Roi coordinates

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Roi coordinates

Susanna Trollvad
I want to get the x,y coordinates from my current Roi. All I have found are
ways to do it with macros, but I'm writing a plugin and to be able to access
the coordinates from inside the plugin. Any idea how I can do this?

//Susanna
Reply | Threaded
Open this post in threaded view
|

Re: Roi coordinates

dscho
Hi,

On Fri, 20 May 2011, Susanna Trollvad wrote:

> I want to get the x,y coordinates from my current Roi. All I have found
> are ways to do it with macros, but I'm writing a plugin and to be able
> to access the coordinates from inside the plugin. Any idea how I can do
> this?

If you're looking for the handle coordinates of a polygon ROI (or its
variants point ROI, segmented line, freehand, etc): there are
getNCoordinates(), getXCoordinates() and getYCoordinates() methods in
PolygonRoi. But beware: the coordinates are relative to the bounding box.

So here is a Beanshell snippet:

        Roi roi = image.getRoi();
        if (roi instanceof PolygonRoi) {
                PolygonRoi polygon = (PolygonRoi)roi;
                Rectangle bounds = roi.getBounds();
                int n = polygon.getNCoordinates();
                int[] x = polygon.getXCoordinates();
                int[] y = polygon.getYCoordinates();

                for (int i = 0; i < n; i++)
                        IJ.log("Coordinate " + i + ": "
                                + (bounds.x + x[i]) + ", "
                                + (bounds.y + y[i]));
        }

Ciao,
Johannes
Reply | Threaded
Open this post in threaded view
|

Re: Roi coordinates

dscho
Hi,

On Fri, 20 May 2011, Susanna Trollvad wrote:

> My ROIs are generated by running particle analyzer. How do I know what
> kind of ROI I have?

Since that question is really of interest to a larger audience, I Cc: the
ImageJ list again. The answer is: use Roi's getType() method:

http://pacific.mpi-cbg.de/javadoc/ij/gui/Roi.html#getType%28%29

Ciao,
Johannes