Login  Register

Re: ROI type and ROI Manager

Posted by Wayne Rasband on Aug 03, 2008; 4:01pm
URL: http://imagej.273.s1.nabble.com/ROI-type-and-ROI-Manager-tp3695459p3695460.html

> Dear listers,
>
> I have a plugin which fits edges to objects in a stack of images.  
> The edge
> points  are saved as PolygonRois(type 2) in an RoiManager.  I  
> retrieve the
> ROIs in another Plugin with the getRoisAsArray() command. But the  
> ROIs are
> now type 4, TRACE_ROIs.  I want to retrieve the coordinate points,  
> but the
> getXCoordinates() and getYCoordinates() are not supported.
> I welcome any suggestions.
> Bill O'Connell


ROIs returned by getRoisAsArray() have the original types. When I add  
rectangular, oval, polygon and traced ROIs to the ROI Manager and run  
(using the editor's Macros>Evaluate JavaScript command) this  
JavaScript code

     importClass(Packages.ij.plugin.frame.RoiManager);
     manager = RoiManager.getInstance();
     rois = manager.getRoisAsArray();
     for (i=0; i<rois.length; i++)
         print(rois[i].getName()+": "+rois[i].getType());

I get

    0067-0104: 0
    0077-0223: 1
    0251-0159: 2
    0383-0359: 4

In any case, getXCoordinates() and getYCoordinates() work with type 4  
(traced) ROIs.

     importClass(Packages.ij.plugin.frame.RoiManager);
     manager = RoiManager.getInstance();
     rois = manager.getRoisAsArray();
     roi = rois[3];
     print("type: "+roi.getType());
     n= roi.getNCoordinates();
     x = roi.getXCoordinates();
     y = roi.getYCoordinates();
     bounds = roi.getBounds();
     for (i=0; i<n; i++)
         print((bounds.x+x[i])+", "+(bounds.y+y[i]));

It is easier, however, to use the getPolygon() method

     importClass(Packages.ij.plugin.frame.RoiManager);
     manager = RoiManager.getInstance();
     rois = manager.getRoisAsArray();
     roi = rois[3];
     print("type: "+roi.getType());
     p = roi.getPolygon();
     for (i=0; i<p.npoints; i++)
         print(p.xpoints[i]+", "+p.ypoints[i]);

This is what the code looks like in Java

     RoiManager manager = RoiManager.getInstance();
     Roi[] rois = manager.getRoisAsArray();
     Roi roi = rois[3];
     IJ.log("type: "+roi.getType());
     Polygon p = roi.getPolygon();
     for (int i=0; i<p.npoints; i++)
         IJ.log(p.xpoints[i]+", "+p.ypoints[i]);

-wayne