Macros to read and write Complex Fourier Transform

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Macros to read and write Complex Fourier Transform

Marco LO
Dear Listers,

What is the data format of Complex Fourier Transform in FFT?  Is there any
macro to read and write the Real and Imaginary transformation from and to a
file so that I could manipulate the data directly.

Thanks!
marco
Reply | Threaded
Open this post in threaded view
|

Re: Macros to read and write Complex Fourier Transform

dscho
Hi,

On Fri, 23 Jan 2009, Marco LO wrote:

> What is the data format of Complex Fourier Transform in FFT?  Is there
> any macro to read and write the Real and Imaginary transformation from
> and to a file so that I could manipulate the data directly.

<shameless plug>
If you use Fiji (http://pacific.mpi-cbg.de/), you will have a choice of
scripting languages with which to access the image data, and you will also
have a pretty fast pure Java FFT bundled:
http://boole.mines.edu/doc/api/edu/mines/jtk/dsp/FftComplex.html
</shameless>

There is no complex fast Fourier transform in ImageJ, as far as I can
tell.

Ciao,
Dscho
Reply | Threaded
Open this post in threaded view
|

trouble specifying a ROI in ROI Manager

Hugo A. M. Torres
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
Reply | Threaded
Open this post in threaded view
|

Re: trouble specifying a ROI in ROI Manager

Joris FA Meys
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
>
Reply | Threaded
Open this post in threaded view
|

Re: Macros to read and write Complex Fourier Transform

Michael Schmid
In reply to this post by dscho
Hi,

you can use Process>FFT>FFT Options in standard ImageJ (no Fiji  
required) to access the real and imaginary parts of the FFT.
I have not checked whether they are mathematically correct, but at  
least they are consistent with the power spectrum that you get from  
FFT Options, i.e.

real^2 + imaaginary^2 = power spectrum

Michael
________________________________________________________________

On 13 Feb 2009, at 03:24, Johannes Schindelin wrote:

> Hi,
>
> On Fri, 23 Jan 2009, Marco LO wrote:
>
>> What is the data format of Complex Fourier Transform in FFT?  Is  
>> there
>> any macro to read and write the Real and Imaginary transformation  
>> from
>> and to a file so that I could manipulate the data directly.
>
> <shameless plug>
> If you use Fiji (http://pacific.mpi-cbg.de/), you will have a  
> choice of
> scripting languages with which to access the image data, and you  
> will also
> have a pretty fast pure Java FFT bundled:
> http://boole.mines.edu/doc/api/edu/mines/jtk/dsp/FftComplex.html
> </shameless>
>
> There is no complex fast Fourier transform in ImageJ, as far as I can
> tell.
>
> Ciao,
> Dscho
Reply | Threaded
Open this post in threaded view
|

Re: trouble specifying a ROI in ROI Manager

Hugo A. M. Torres
In reply to this post by Joris FA Meys
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
Reply | Threaded
Open this post in threaded view
|

Re: trouble specifying a ROI in ROI Manager

Joris FA Meys
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
>
Reply | Threaded
Open this post in threaded view
|

Re: Macros to read and write Complex Fourier Transform

dscho
In reply to this post by Michael Schmid
Hi,

On Fri, 13 Feb 2009, Michael Schmid wrote:

> you can use Process>FFT>FFT Options in standard ImageJ (no Fiji
> required) to access the real and imaginary parts of the FFT.

From the source:

        This class implements the FFT, Inverse FFT and Redisplay Power
        Spectrum commands in the Process/FFT submenu. It is based on Arlo
        Reeves' Pascal implementation of the Fast Hartley Transform from NIH
        Image (http://rsb.info.nih.gov/ij/docs/ImageFFT/).

That was exactly the reason why I did not suggest accessing the ImageJ
plugin in my reply: the OP asked for an FFT, not an FHT.

Ciao,
Dscho
Reply | Threaded
Open this post in threaded view
|

Re: trouble specifying a ROI in ROI Manager

Hugo A. M. Torres
In reply to this post by Joris FA Meys
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
> > > >
> > --
>
>
Reply | Threaded
Open this post in threaded view
|

Re: trouble specifying a ROI in ROI Manager

Wayne Rasband
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
>>>>>
>>> --
>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: trouble specifying a ROI in ROI Manager

Hugo A. M. Torres
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?

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
Reply | Threaded
Open this post in threaded view
|

Re: trouble specifying a ROI in ROI Manager

Wayne Rasband
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
Reply | Threaded
Open this post in threaded view
|

Re: trouble specifying a ROI in ROI Manager

Hugo A. M. Torres
On Sat, 2009-02-14 at 23:42 -0500, Rasband Wayne wrote:

> 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


Hello again Wayne,

I run the macro that compares pixel count in both ROIs and it seems the
"ROI-converter" ( The one you sent me, I am calling it this way)  misses
around 600pixels. I tryed  to fix the macro by calculating the perimeter
and adding a little extra lengh to the size of the square ROI. Namely,
the extra length should correspond to the to the the area taken by the
perimeter of the triangle, please see if you can understand what I tried
to do:


getSelectionBounds(x, y, width, height);
   getRawStatistics(area, perimeter);
   size = (2*area + perimeter)/(2*sqrt(area));
   x2 = x + width/2 - size/2;
   y2 = y + height/2 - size/2;
   makeRectangle(x2, y2, size, size)


Triangle ROI
pixel count: 94843
area: 94842
differencet: 0.0011%
Measured area in square micrometers: 41412.942

Wayne's square ROI:
pixel count: 94249(misses 594 pixels)
area: 94249
differencet: 0%
Measured area in square micrometers: 41153.574

Hugo's square ROI
pixel count: 94864 (still misses 21 pixels)
area: 94864
differencet: 0%
Measured area in square micrometers: 41422.112

Is it possible to improve this further, or should I consider this normal
computational error?