how does ImageJ measure circular ROI?

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

how does ImageJ measure circular ROI?

Charitra
I am trying to measure photon counts from single molecules (7*7 pixels) by
defining a ROI around the single molecule. I localize the center of the
emitter (this could be subpixel) from ThunderSTORM and draw the ROI around
it which makes everything sub-pixel. If the ROI is circular, some of the
pixels are excluded from measurement. Can someone tell me how exactly the
pixels for measurement are selected? Is it based on the amount of area
selected by the ROI boundaries or is it something else?
<http://imagej.1557.x6.nabble.com/file/t382433/IMG_20191001_172953.jpg>
<http://imagej.1557.x6.nabble.com/file/t382433/IMG_20191001_173241.jpg>

In the above images, I specified a sub-pixel center and drew a circular ROI
and filled it from the ROI Manager, but the fill seems to fall completely at
a different location than the ROI specified. I am not able to understand how
this works! Please help.



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how does ImageJ measure circular ROI?

Herbie
Good day,

this is a cross-post from the IJ-Forum:
<https://forum.image.sc/t/how-does-imagej-measure-pixels-in-circular-roi/30041>

Please make sure that you understand what spatially discrete, i.e.
sampled images mean. The fill command acts on the samples not the ROI
circle that is a vector graphic. The number of pixels that are filled
most likely depends on the next neighbor distances.

Furthermore please not that pixels have no spatial extension, i.e. what
you see as squares of equal gray is the common attempt (most simple
interpolation scheme) to visualize the sample value. Per convention
ImageJ assumes the sample coordinate at the upper left corner of the square.

Did you consider to oversample your image using an adequate
interpolation scheme?

Regards

Herbie

::::::::::::::::::::::::::::::::::::::
Am 02.10.19 um 15:18 schrieb Charitra:

> I am trying to measure photon counts from single molecules (7*7 pixels) by
> defining a ROI around the single molecule. I localize the center of the
> emitter (this could be subpixel) from ThunderSTORM and draw the ROI around
> it which makes everything sub-pixel. If the ROI is circular, some of the
> pixels are excluded from measurement. Can someone tell me how exactly the
> pixels for measurement are selected? Is it based on the amount of area
> selected by the ROI boundaries or is it something else?
> <http://imagej.1557.x6.nabble.com/file/t382433/IMG_20191001_172953.jpg>
> <http://imagej.1557.x6.nabble.com/file/t382433/IMG_20191001_173241.jpg>
>
> In the above images, I specified a sub-pixel center and drew a circular ROI
> and filled it from the ROI Manager, but the fill seems to fall completely at
> a different location than the ROI specified. I am not able to understand how
> this works! Please help.
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how does ImageJ measure circular ROI?

Michael Schmid
In reply to this post by Charitra
Hi Charitra,

in addition to Herbie's response:

Currently, the ImageJ OvalRoi class does not care about subpixel
resolution, i.e., the corner coordinates of the enclosing rectangle are
rounded down to the nearest integer when filling the Roi or in the
'Roi.contains" method.
I think the reason is simply that drawing oval rois manually always
results in integer coordinates, and there are almost no GUI operations
that can create an oval with non-integer coordinates of the bounding
rectangle, so no one has cared about it so far (The early versions of
ImageJ had no subpixel Rois, Roi coordinates were always integer).

If you are programming Java or a script language, for better accuracy
you could use the ShapeRoi class instead of the OvalRoi class, e.g. like
in this JavaScript example:

   //specify the roi coordinates (coordinates of the bounding rectangle)
   x=55.3;
   y=51.7;
   width=2.0;
   height=2.0;
   //create a roi for the current image
   imp=IJ.getImage();
   shape = new Ellipse2D.Double(-0.001, -0.001, width+0.002, height+0.002);
   sr=new ShapeRoi(shape);
   sr.setLocation(x,y);
   imp.setRoi(sr);

The numbers -0.001, +0.002 are meant to make the Ellipse2D.Double class
include usually the same pixels when placed at integer coordinates and
with integer size as the OvalRoi, in spite of rounding errors.
I had tried taking this as way to convert OvalRois to ShapRois when
working on the ROI class about half a year ago, but I had the impression
that the Java Ellise2D.double was quite inaccurate in some cases. If you
have also the same problem, you might convert the ShapeRoi to a
FloatPolygon before translating it, create a PolygonRoi with it, and
then translate it to the desired coordinates.

An alternative would be creating a FloatPolygon approximating your
circles by dedicated code and then creating a PolygonRoi from it.

Of course, also for a ShapeRoi or PolygonRoi created like this, a given
pixel can be only inside or outside the Roi. In ImageJ, there is nothing
like a 40%-selected pixel. One could write code for measuring e.g.
average intensity with pixel weights, but some operations like the
median of intensities would be quite difficult when pixels have a weight.

Michael
________________________________________________________________
On 02.10.19 15:18, Charitra wrote:

> I am trying to measure photon counts from single molecules (7*7 pixels) by
> defining a ROI around the single molecule. I localize the center of the
> emitter (this could be subpixel) from ThunderSTORM and draw the ROI around
> it which makes everything sub-pixel. If the ROI is circular, some of the
> pixels are excluded from measurement. Can someone tell me how exactly the
> pixels for measurement are selected? Is it based on the amount of area
> selected by the ROI boundaries or is it something else?
> <http://imagej.1557.x6.nabble.com/file/t382433/IMG_20191001_172953.jpg>
> <http://imagej.1557.x6.nabble.com/file/t382433/IMG_20191001_173241.jpg>
>
> In the above images, I specified a sub-pixel center and drew a circular ROI
> and filled it from the ROI Manager, but the fill seems to fall completely at
> a different location than the ROI specified. I am not able to understand how
> this works! Please help.

________________________________________________________________
On 02.10.19 15:45, Herbie wrote:> Good day,
 >
 > this is a cross-post from the IJ-Forum:
 >
<https://forum.image.sc/t/how-does-imagej-measure-pixels-in-circular-roi/30041>

 >
 >
 > Please make sure that you understand what spatially discrete, i.e.
 > sampled images mean. The fill command acts on the samples not the ROI
 > circle that is a vector graphic. The number of pixels that are filled
 > most likely depends on the next neighbor distances.
 >
 > Furthermore please not that pixels have no spatial extension, i.e. what
 > you see as squares of equal gray is the common attempt (most simple
 > interpolation scheme) to visualize the sample value. Per convention
 > ImageJ assumes the sample coordinate at the upper left corner of the
 > square.
 >
 > Did you consider to oversample your image using an adequate
 > interpolation scheme?
 >
 > Regards
 >
 > Herbie

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how does ImageJ measure circular ROI?

Herbie
In reply to this post by Herbie
Good day Charitra,

you've brought up your question on the ImageJ-Forum again but you didn't
reply to Michael's and my posts here on the ImageJ-list.

Would you please tell us what remains unclear after our replies?


To make things more obvious, you may run the following ImageJ-macro:

///////
newImage("Untitled", "8-bit noise", 8, 8, 1);
run("Set... ", "zoom=3200 x=4 y=4");
run("Specify...", "width=1 height=1 x=3.3 y=3.3 oval");
run("RGB Color");
setForegroundColor(255, 0, 255);
run("Fill", "slice");
exit()
///////
Paste the this macro code to an empty macro window
(Plugins >> New >> Macro) and run it.

Please tell us in detail what you don't understand when inspecting the
result.

Regards

Herbie

::::::::::::::::::::::::::::::::::::
Am 02.10.19 um 15:45 schrieb Herbie:

> Good day,
>
> this is a cross-post from the IJ-Forum:
> <https://forum.image.sc/t/how-does-imagej-measure-pixels-in-circular-roi/30041>
>
>
> Please make sure that you understand what spatially discrete, i.e.
> sampled images mean. The fill command acts on the samples not the ROI
> circle that is a vector graphic. The number of pixels that are filled
> most likely depends on the next neighbor distances.
>
> Furthermore please not that pixels have no spatial extension, i.e. what
> you see as squares of equal gray is the common attempt (most simple
> interpolation scheme) to visualize the sample value. Per convention
> ImageJ assumes the sample coordinate at the upper left corner of the
> square.
>
> Did you consider to oversample your image using an adequate
> interpolation scheme?
>
> Regards
>
> Herbie
>
> ::::::::::::::::::::::::::::::::::::::
> Am 02.10.19 um 15:18 schrieb Charitra:
>> I am trying to measure photon counts from single molecules (7*7
>> pixels) by
>> defining a ROI around the single molecule. I localize the center of the
>> emitter (this could be subpixel) from ThunderSTORM and draw the ROI
>> around
>> it which makes everything sub-pixel. If the ROI is circular, some of the
>> pixels are excluded from measurement. Can someone tell me how exactly the
>> pixels for measurement are selected? Is it based on the amount of area
>> selected by the ROI boundaries or is it something else?
>> <http://imagej.1557.x6.nabble.com/file/t382433/IMG_20191001_172953.jpg>
>> <http://imagej.1557.x6.nabble.com/file/t382433/IMG_20191001_173241.jpg>
>>
>> In the above images, I specified a sub-pixel center and drew a
>> circular ROI
>> and filled it from the ROI Manager, but the fill seems to fall
>> completely at
>> a different location than the ROI specified. I am not able to
>> understand how
>> this works! Please help.
>>
>>
>>
>> --
>> Sent from: http://imagej.1557.x6.nabble.com/
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how does ImageJ measure circular ROI?

Charitra
Hello Herbie and Michael

Thank you for your replies.

Herbie, I had posted my question on both the mailing list and the forum on
the same day. Not sure what you mean by reposting. I'm not very familiar
with how the forum and mailing list work, sorry.

But coming back, this was what I suspected - that ImageJ does not care about
sub-pixels. I am not interested in filling sub-pixel oval ROIs; I want to
measure them. So I just used 'fill' in a way to visualize which pixels were
going into the measurement. But coming back to Michael's answer, yes, the
values in the ROI managers are always integers, but if I 'specify' a ROI and
add it to the ROI manager, although the values are an integer, the sub-pixel
nature of the ROI is maintained. Or was this a wrong observation of mine?

Also, if there is no way to measure just 40% or 50% of the pixel, then I am
afraid I cannot use the oval ROIs. I have switched to using square ROIs
instead, as I cannot afford to do guesswork on these intensity measurements.
Moreover, in oval ROIs, the number of pixels taken into consideration is not
clear and I need to know exactly which and how many pixels are taken into
account. So I think I am going to continue with rectangular ROIs. Sorry for
the delay in replying, and have a nice day!

Charitra.



--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how does ImageJ measure circular ROI?

Herbie
Good day Charitra,

here are (again) some ideas:

1. It is always a good idea to mention, if a topic is cross-posted, so
that those interested in it are able to follow comments and solutions.
(I've mentioned the cross-post in my first reply to you, here on the
list. Marcel aka Bio7 did the same today on the Forum.)

2. Meanwhile and as Michael has mentioned, you've realized that ImageJ
uses the "floor"-rule when dealing with circular ROIs, i.e. the next
lowest integer.

3. As mentioned in my first reply, I recommend to scale the images using
an adequate interpolation scheme. When doing so, the problem of
"percentage pixels" can be reduced to integer pixels. Please note that
interpolated scaling doesn't create information but can circumvent the
problem of "percentage pixels".

Regards

Herbie

::::::::::::::::::::::::::::::::::::::
Am 17.10.19 um 11:03 schrieb Charitra:

> Hello Herbie and Michael
>
> Thank you for your replies.
>
> Herbie, I had posted my question on both the mailing list and the forum on
> the same day. Not sure what you mean by reposting. I'm not very familiar
> with how the forum and mailing list work, sorry.
>
> But coming back, this was what I suspected - that ImageJ does not care about
> sub-pixels. I am not interested in filling sub-pixel oval ROIs; I want to
> measure them. So I just used 'fill' in a way to visualize which pixels were
> going into the measurement. But coming back to Michael's answer, yes, the
> values in the ROI managers are always integers, but if I 'specify' a ROI and
> add it to the ROI manager, although the values are an integer, the sub-pixel
> nature of the ROI is maintained. Or was this a wrong observation of mine?
>
> Also, if there is no way to measure just 40% or 50% of the pixel, then I am
> afraid I cannot use the oval ROIs. I have switched to using square ROIs
> instead, as I cannot afford to do guesswork on these intensity measurements.
> Moreover, in oval ROIs, the number of pixels taken into consideration is not
> clear and I need to know exactly which and how many pixels are taken into
> account. So I think I am going to continue with rectangular ROIs. Sorry for
> the delay in replying, and have a nice day!
>
> Charitra.
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html