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 |
William O'Connell 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 You might be able to use the following piece of javascript I adapted from ListPixelsinROI.js found under the Macros examples at the ImageJ website. Selwyn // List Perimeter Pixels In ROI // // Displays the coordinates and values of // the pixels within a non-rectangular ROI. // var img = IJ.getImage(); var roi = img.getRoi(); var mask = roi!=null?roi.getMask():null; if (mask==null) IJ.error("Non-rectangular ROI required"); var ip = img.getProcessor(); var r = roi.getBounds(); var z = img.getCurrentSlice()-1; var toggle = 0; for (var y=0; y<r.height; y++) { for (var x=0; x<r.width; x++) { if (mask.getPixel(x,y)!=toggle) { toggle = (toggle == 0) ? 255 : 0; IJ.log(x+" \t"+y+" \t"+z+" \t"+ip.getPixel(r.x+x,r.y+y)); } } } |
selwyn wrote:
> William O'Connell 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 > > You might be able to use the following piece of javascript I adapted > from ListPixelsinROI.js found under the Macros examples at the ImageJ > website. > > Selwyn > > // List Perimeter Pixels In ROI > // > // Displays the coordinates and values of > // the pixels within a non-rectangular ROI. > // > var img = IJ.getImage(); > var roi = img.getRoi(); > var mask = roi!=null?roi.getMask():null; > if (mask==null) > IJ.error("Non-rectangular ROI required"); > var ip = img.getProcessor(); > var r = roi.getBounds(); > var z = img.getCurrentSlice()-1; > var toggle = 0; > for (var y=0; y<r.height; y++) { > for (var x=0; x<r.width; x++) { > if (mask.getPixel(x,y)!=toggle) { > toggle = (toggle == 0) ? 255 : 0; > IJ.log(x+" \t"+y+" \t"+z+" \t"+ip.getPixel(r.x+x,r.y+y)); > } > } > } Oops last line should be changed to the following for absolute coordinates: IJ.log((r.x+x)+" \t"+(r.y+y)+" \t"+z+" \t"+ip.getPixel(r.x+x,r.y+y)); selwyn |
In reply to this post by William O'Connell-3
> 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 |
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 > |
Free forum by Nabble | Edit this page |