Login  Register

Re: trouble specifying a ROI in ROI Manager

Posted by Wayne Rasband on Feb 15, 2009; 4:42am
URL: http://imagej.273.s1.nabble.com/Macros-to-read-and-write-Complex-Fourier-Transform-tp3693680p3693689.html

On Feb 14, 2009, at 11:07 AM, Hugo A. M. Torres wrote:

> Hi Wayne,
>
> Thanks for helping me with that. I can understand from that code  
> you are
> doing exactly what I said, namely compute a square of sides whose  
> length
>  is the square root of the triangle's area.
>
> Yet, If I measure the area of the resulting triangle, it is actually
> somewhat smaller than the triangle's.
>
> So maybe Joris was right about  the area being measured only inside  
> the
> selection's boundaries discounting the pixels of the border?

ImageJ measures the area of a selection by doing a polygon fill and  
counting pixels. You can see what the polygon fill does by using the  
Edit>Fill command. Zoom in and you will see that some of the pixels  
extend beyond the selection boundary.

Here is a macro that compares the polygon fill pixel count to the  
area calculated from the polygon vertices.

    getRawStatistics(count);
    getSelectionCoordinates(x, y);
    area = 0;
    n = x.length;
    for (i=0; i<n; i++) {
       iminus1 = i-1;
       if (iminus1<0) iminus1=n-1;
       area += (x[i]+x[iminus1])*(y[i]-y[iminus1]);
    }
    area = abs(area/2);
    print("");
    print("pixel count: "+count);
    print("area: "+area);
    print("differencet: "+(count-area)*100/count+"%");

-wayne

>
> Hugo
>
> On Fri, 2009-02-13 at 15:56 -0500, Wayne Rasband wrote:
>> Here is a macro that creates a square selection that has the same  
>> area
>> as an existing selection.
>>
>>    getSelectionBounds(x, y, width, height);
>>    getRawStatistics(area);
>>    size = sqrt(area);
>>    x2 = x + width/2 - size/2;
>>    y2 = y + height/2 - size/2;
>>    makeRectangle(x2, y2, size, size);
>>
>> -wayne
>>
>> On Feb 13, 2009, at 3:27 PM, Hugo A. M. Torres wrote:
>>
>>> I tried that, didn't work. Maybe I am still having rounding issues
>>> because of the area being reported in micrometers.
>>>
>>> I am not experienced in writing macros, but would it be possible at
>>> least in principle to write a macro that specifies a square ROI
>>> according to an area value input?
>>>
>>> Hugo
>>>
>>> On Fri, 2009-02-13 at 13:41 +0100, joris meys wrote:
>>>> Ah, I see. Sorry for the misunderstanding.
>>>>
>>>> As far as I understand, the ROI measures inside its boundaries,
>>>> boundary not
>>>> included. So in fact you should extend the length and width of the
>>>> ROI with
>>>> 2 pixels if you want to have a square that covers the same area.  
>>>> I'm
>>>> not
>>>> 100% sure about this, but it might be worth a try.
>>>>
>>>> Kind regards
>>>> Joris
>>>>
>>>> On Fri, Feb 13, 2009 at 1:13 PM, Hugo A. M. Torres
>>>> <[hidden email]>wrote:
>>>>
>>>>> No Joris, I understand what you are saying, but the problem is the
>>>>> first
>>>>> ROI (used to measure the nucleus I am interested in) has a  
>>>>> triangular
>>>>> shape, which will not fit in the background area unless I make it
>>>>> into a
>>>>> square of the same area as the triangle. Now, this should be very
>>>>> straightforward: just draw a square with sides whose lenght is the
>>>>> square root of the triangle area. It doesn't work if I use a
>>>>> calculator,
>>>>> possibly because of rounding issues, I don't know.
>>>>>
>>>>> I always get a smaller area in um^2 if I do this by hand. So I was
>>>>> wandering if it is possible to specify a square ROI by area value.
>>>>>
>>>>> Any ideas?
>>>>>
>>>>> Tganks
>>>>>
>>>>> On Fri, 2009-02-13 at 11:08 +0100, joris meys wrote:
>>>>>> The measurements should be fairly simple with the ROI manager.  
>>>>>> Just
>>>>>> click
>>>>> on
>>>>>> the roi you specified earlier, and drag it to where you want to
>>>>>> measure.
>>>>>> First click "Add", because otherwise the ROI manager will measure
>>>>>> at the
>>>>>> previous position. That should give you the results you want.
>>>>>>
>>>>>> Kind regards
>>>>>> Joris
>>>>>>
>>>>>>
>>>>>> On Fri, Feb 13, 2009 at 4:36 AM, Hugo A. M. Torres
>>>>>> <[hidden email]
>>>>>> wrote:
>>>>>>
>>>>>>> Hello listmates,
>>>>>>>
>>>>>>> I am trying to perform densitometry measurements according to  
>>>>>>> this
>>>>>>> method:
>>>>>>>
>>>>>>> "The nucleus was encircled by free-hand drawing of a border  
>>>>>>> around
>>>>>>> the
>>>>>>> outermost mRNA-expressing cells in the nucleus. The mean density
>>>>>>> and
>>>>> the
>>>>>>> area of the selection were measured. The mean density of the
>>>>>>> background
>>>>>>> was measured from a rectangular area of corresponding size in  
>>>>>>> the
>>>>>>> immediate vicinity of the nucleus. The mean density of the
>>>>>>> background
>>>>>>> was subtracted from the mean density of the nucleus and..."
>>>>>>>
>>>>>>> Now, the problem is I can't specify a ROI of the same area of  
>>>>>>> the
>>>>>>> place
>>>>>>> I measured previously. I tried taking the square root of the  
>>>>>>> area
>>>>> (given
>>>>>>> in um^2) and specifying a square ROI with sides of this  
>>>>>>> length but
>>>>>>> the
>>>>>>> resulting area measured is always smaller!
>>>>>>>
>>>>>>> Is it possible to specify a square ROI by inputing  an area  
>>>>>>> value
>>>>>>> in
>>>>>>> square micrometers?
>>>>>>>
>>>>>>> Thanks
>>>>>>> --
>>>>>>> Hugo Arruda de Moura Torres
>>>>>>> ==================================
>>>>>>> Departamento de Biofísica
>>>>>>> Universidade Federal de São Paulo
>>>>>>> Rua Botucatu 862 7o. andar
>>>>>>>
>>>>> --
>>>>
>>>>
>>>
> --
> Hugo Arruda de Moura Torres
> ==================================
> Departamento de Biofísica
> Universidade Federal de São Paulo
> Rua Botucatu 862 7o. andar
> CEP 04023-062 Vila Clementino
> São Paulo - SP - Brasil
> Tel:+55 (11) 5576 4530 r.220
> Fax: 55 11 5571 5780