Posted by
William O'Connell-3 on
Aug 04, 2008; 6:10pm
URL: http://imagej.273.s1.nabble.com/ROI-type-and-ROI-Manager-tp3695459p3695461.html
Thanks wayne,
I was using the following code rather than RoiManager.getInstance(), but
they give the same results. Only one instance of RoiManager can be open,
yes?
public class RoiManager_Test implements PlugIn {
public void run(String arg) {
RoiManager manager = (RoiManager)findOpenNonImageFrame("ROI");
// RoiManager manager = RoiManager.getInstance();
if(manager==null) {
IJ.error("can't find ROI Manager!");
return;
}
Roi[] rois = manager.getRoisAsArray();
for(int r=0; r<rois.length; r++) {
PolygonRoi roi = (PolygonRoi)rois[r];
IJ.log("Roi " + r + " type is " + roi.getType());
IJ.log(roi.toString());
}
}
Frame findOpenNonImageFrame(String sub) {
Frame fr;
Frame[] nonIm = WindowManager.getNonImageWindows();
if(nonIm == null) return null;
for(int id=0; id<nonIm.length; id++) {
fr = nonIm[id];
String s = fr.getTitle();
IJ.log(s);
int k = s.indexOf(sub);
if(k >= 0) return fr;
}
return null;
}
}
On Sun, Aug 3, 2008 at 9:01 AM, Rasband Wayne <
[hidden email]> wrote:
> 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
>