Select one polygon in a multipolygonal roi

How do I select a single polygon in a multipolygonal Roi created by threshold?
I mean I have an image and have applied threshold obtaining several polygons surrounding each object, but only one Roi. I tried in a java plugin

    roi.getPolygon();

but in a multipolygonal roi it returns null, and

for(Polygon p: roi) {
     ....  
}

but it returns an error because a roi doesnt contain any polygons as iterative objects, please help

Regards

What you call “multipolygonal Roi” is in fact a composite ROI, an instance of ij.gui.ShapeRoi, as you can find out by this little Groovy script:

// @ImagePlus imp

roi = imp.getRoi()

println(roi)
println(roi.getClass())

You should be able to get its single ROIs using getRois(), see the javadoc. (Note that getPolygon() will return the bouding box of the composite selection.)

1 Like