Re: Point Selections

Posted by Wayne Rasband on
URL: http://imagej.273.s1.nabble.com/Point-Selections-tp3701394p3701395.html

> It seems that the "Point Selections" (cross-hair) tool has no
> return value. I want to put something like this inside my code...
>
> Toolbar Tb = Toolbar.getInstance();
> Tb.setTool(7);    // override the current tool with the Point
> Selections tool
>
> int[] xy_coordinates = new int[2];
> xy_coordinates = <where ever the Point Selections object is placed>
>
> Is there a standard way of doing this?

In a macro, you can get the coordinates of a selection, including a
point selection, using:

     getSelectionCoordinates(x, y);
     for (i=0; i<x.length; i++)
         print(i, x[i], y[i]);

In a plugin, use:

     ImagePlus img = IJ.getImage();
     Roi roi = img.getRoi();
     Polygon p = roi.getPolygon();
     for (int i=0; i<p.npoints; i++)
         IJ.log(i+" "+p.xpoints[i]+" "+p.ypoints[i]);

-wayne