Posted by
Michael Schmid on
Oct 02, 2019; 3:38pm
URL: http://imagej.273.s1.nabble.com/how-does-ImageJ-measure-circular-ROI-tp5022481p5022483.html
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