Login  Register

Re: List all pixel coordinates in ROI

Posted by Daniel Pensold on May 06, 2014; 7:47am
URL: http://imagej.273.s1.nabble.com/List-all-pixel-coordinates-in-ROI-tp3705127p5007586.html

Thx for your reply. Unfortunately this return only the border of the selection, but I need all x,y coordinates of the whole selection/ROI (also the inside coordinates).

best regards
daniel

Rasband, Wayne (NIH/NIMH) [E] wrote
On May 5, 2014, at 1:06 PM, Daniel Pensold wrote:

> Hello,
> Iam new at this forum/mailing list and found this interesting macro here,
> but unfortunately I didn’t get it work :(
> maybe there is already another function or macro, which gets all
> x,y-coordinates of a free-hand ROI?

You can do this with two lines of macro code:

  run("Interpolate", "interval=1"); // Edit>Selection>Interpolate
  getSelectionCoordinates(xpoints, ypoints);

-wayne

> I have not much experience with macro editing and Iam working either with
> ImageJ or Fiji
> As I went  step by step through this macro I found some troubles which I
> couldn’t solve or explain
> *******
> //  Macro by Michael Cammer [hidden email]
> // This routine gets all the pixels along a ROI, not just vertices.
> //  It only works with the magic wand tool or a complete freehand ROI tool.
> //  It does not work with the polygon tool!
>      getSelectionCoordinates(x_, y_);
>      x = newArray(x_.length);
>      y = newArray(x_.length);
>      for (i=0; i<x_.length; i){    --> should it be here ; i++ so the index
> increase per round?
>         x[i] = x_[i];
>         y[i] = y_[i];
>         }
>       x[x_.length] = x_[0];  *--> I don’t get, what this should do... I get
> an “out of range” error, as the new array x is always x_.length-1 as it
> starts from zero. So should this function add a new value at the end
> (corresponding to the first value of the old x_) or should it overwrite the
> last value of the new array? If it should add a new value it would be easy
> to create the x-array in the beginning with x_.length+1*
>       y[y_.length] = y_[0];  *--> same as comment before*
>
>
> //print("*************************************************************");
>      //for (i=0; i<x.length; i)       --> should it be here ; i++ so the
> index increase per round?
>          //print(x[i]" "[i]);
>      //print("------------");
>
> *--> From here the script results in an endless calculation or is doing
> nothing *
>
>      newx = newArray(65535);
>      newy = newArray(65535);
>      newindex = 0;
>      for (i=0; i<x.length; i){    --> should it be here ; i++ so the index
> increase per round?
>          if (i < (x.length-1)){
>            if (x[i] == x[i]){
>              y0 = y[i];
>              y1 = y[i];  *--> should this be really the same as the line
> before? In my opinion the next if function is therefore always wrong, as dy
> = 0? Maybe y1 = y[i+1]?*
>              dy = y1 - y0;
>              if (dy > 0) step = 1; else step = -1;
>              for (k=y0; k!=y1; k=k×) {   *--> what means k×, I only find
> this term by google as kmeans and don’t understand its function here*
>                newx[newindex] = x[i];
>                newy[newindex] = k;
>                newindex;
>              } // for k
>           } //  if (x[i] == x[i])
>
>            if (y[i] == y[i]){
>              x0 = x[i];
>              x1 = x[i];  *--> same as 2 comments above*
>              dx = x1 - x0;
>              if (dx > 0) step = 1; else step = -1;
>              for (k=x0; k!=x1; k=k×) {
>                newx[newindex] = k;
>                newy[newindex] = y[i];
>                newindex;
>              } // for k
>           } //  if (y[i] == y[i])
>
>          if ( (x[i] != x[i]) && (y[i]!=y[i]) ){
>            newx[newindex] = x[i];
>            newy[newindex] = y[i];
>            newindex;      }
>
>      } // if  (i < (x.length-1))
>      } // for i
>
> // This is the end of the routine that gets the coordinates along the edge.
> // The coordinates are stored in the arrays x and y.
> ******
> When I change the script as stated in the comments, then it runs without
> error, but the newindex stays 0 after running, so I think there happened
> nothing?
>
> Thanks
> Daniel
>
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/List-all-pixel-coordinates-in-ROI-tp3705127p5007571.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html