Login  Register

Re: ROI XY coordinates

Posted by Eric BADEL-2 on Mar 18, 2009; 12:38pm
URL: http://imagej.273.s1.nabble.com/ROI-XY-coordinates-tp3693267p3693268.html

    This does not work. Some of the cell are in the ROI and some of them
    are outside.
    I tried with the following test and I got values=0 or 255. This mean
    the fit curve goes throught the boundary. looks bizarre...

    labels = newArray(3);
    labels[0] = "X";
    labels[1] = "Y";
    labels[2] = "values";
    run("Fit Spline", "straighten");
       getSelectionCoordinates(x, y);
       for (i=1; i<x.length; i++) {
           value =getPixel(x[i-1],y[i-1]);
           setResult(labels[0], i, x[i-1]);
           setResult(labels[1], i, y[i-1]);
           setResult(labels[2], i, value);
       }
    updateResults();

    ****************************************
    I need the list of ALL the coordinates and all the corresponding
    grey values
    of an ROI. (This ROI is a boundary).
    - Save As \ Coordinate XY does not work for this because it gives
    only the
    extremities of boundaries segments (when they are vertical or
    horizontal).
    So, few data are missing.

    - getSelectionCoordinates(x, y); does not work too for the same reason.

    Is there a way to get ALL the coordinates of an ROI (boundaries or
    area ROI) ?
    Thank you
    Eric

------------------------------------------------------------------------
You can often find answers to these questions by searching the ImageJ
archives.  :-)


------------------------------------------------------------------------
On Sep 24, 2008, at 6:29 AM, Adam Cliffe wrote:

>  Does anyone have a macro which will list all of the coordinates for an
>  ROI?
>  (not just the ends of the vertices)

One way to do this is to run the Edit>Selection>Fit Spline command with
the "straighten" option, which is what the Edit>Selection>Straighten
command does to get coordinates along a line spaced one pixel apart.
Here is an example:

   requires("1.41i");
   run("Fit Spline", "straighten");
   getSelectionCoordinates(x, y);
   for (i=1; i<x.length; i++) {
       distance =
sqrt((x[i]-x[i-1])*(x[i]-x[i-1])+(y[i]-y[i-1])*(y[i]-y[i-1]));
       print(i, x[i], y[i], distance);
   }

-wayne