Login  Register

Re: List all pixel coordinates in ROI

Posted by Michael Cammer on Aug 01, 2005; 4:10pm
URL: http://imagej.273.s1.nabble.com/List-all-pixel-coordinates-in-ROI-tp3705127p3705128.html

One problem is that the getCoordinates command does not return all
coordinates.  When there is a horizontal or vertical, it only returns
vertices.  And for polygon tool it always returns only vertices.  Thus the
following:



//  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){
         x[i] = x_[i];
         y[i] = y_[i];
         }
       x[x_.length] = x_[0];
       y[y_.length] = y_[0];

      //print("*************************************************************");
      //for (i=0; i<x.length; i)
          //print(x[i]" "[i]);
      //print("------------");

      newx = newArray(65535);
      newy = newArray(65535);
      newindex = 0;
      for (i=0; i<x.length; i){
          if (i < (x.length-1)){
            if (x[i] == x[i]){
              y0 = y[i];
              y1 = y[i];
              dy = y1 - y0;
              if (dy > 0) step = 1; else step = -1;
              for (k=y0; k!=y1; k=k×) {
                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];
              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.




At 03:21 AM 07/28/05 -0400, you wrote:
>Falks
>
>Does anyone know how to obtain all pixel (x, y) coordinates from selected
>ROI from either macro or plugin?
>
>Thanks
>
>Charlie Mao

____________________________________________________________________________
Michael Cammer   Analytical Imaging Facility   Albert Einstein Coll. of Med.
Jack & Pearl Resnick Campus      1300 Morris Park Ave.     Bronx, NY  10461
(718) 430-2890       Fax:  430-8996      URL:  http://www.aecom.yu.edu/aif/
   **This electronic transmission contains information that is privileged.**



____________________________________________________________________________
Michael Cammer   Analytical Imaging Facility   Albert Einstein Coll. of Med.
Jack & Pearl Resnick Campus      1300 Morris Park Ave.     Bronx, NY  10461
(718) 430-2890       Fax:  430-8996      URL:  http://www.aecom.yu.edu/aif/
   **This electronic transmission contains information that is privileged.**