ROis that fall within a bigger roi: identifying which ones

I have a big circle as an roi and small tiny puncta within that circle AND outside of that circles as well. how do i get to know which rois are within the bigger circle when there is hundreds of them, I mean i need to know the count and maybe the specific rois, displayed in the roi manager, that fall within one bigger roi. how is this done. and is there any macro for it.


Hello Noor -

I am not aware of any built-in tool that will do this for you, but
you can do things like this with a script (or plugin).

The Roi class has a contains() method that is helpful.

Here is a jython (python) script that illustrates this:

from ij.gui import OvalRoi, Roi

bigRoi = OvalRoi (100, 100, 300, 300)
outsideRoi = Roi (100, 100, 3, 3)
insideRoi = Roi (250, 250, 3, 3)

# test whether little Rois are in the big Roi
isOutsideInside = bigRoi.contains (int (outsideRoi.getXBase()), int (outsideRoi.getYBase()))
isInsideInside = bigRoi.contains (int (insideRoi.getXBase()), int (insideRoi.getYBase()))
print 'isOutsideInside =', isOutsideInside
print 'isInsideInside =', isInsideInside

print 'upper left =', outsideRoi.getXBase(), outsideRoi.getYBase()  # upper left corner
print 'center =', outsideRoi.getContourCentroid()   # "center" (centroid)

# display the Rois just so we can see what we're doing
from ij import IJ
from ij.gui import Overlay

imp = IJ.createImage ("some ROIs", "8-bit ramp", 512, 512, 1)
rois = Overlay()
rois.add (bigRoi)
rois.add (outsideRoi)
rois.add (insideRoi)
imp.setOverlay (rois)

The idea is that bigRoi represents your big circle, while
outsideRoi and insideRoi are two of your tiny puncta.
The script shows how to use Roi.contains() to determine
which puncta are in your big circle.

(The above code tests for whether the upper-left corner of
(the bounding box containing) your Roi is in the circle. For
small Rois it doesn’t really matter. If you want to get fancy,
you could test the Roi's centroid, but for small Rois, the
centroid it almost the same as the corner, as shown by the

Thanks, mm