Falks
Does anyone know how to obtain all pixel (x, y) coordinates from selected ROI from either macro or plugin? Thanks Charlie Mao |
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.** |
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? 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 |
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 |
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
|
Hi Daniel,
you can use selectionContains(x, y) to determine whether a point is inside a ROI. To speed up the macro, don't do it for all points but only for these inside the bounding rectangle of the selection, like in this macro: //needs an image with an area selection getSelectionBounds(x0, y0, width, height); for (y=y0; y<y0+height; y++) for (x=x0; x<x0+width; x++) { if (selectionContains(x, y)) print(x," ",y); } Michael ________________________________________________________________ On May 6, 2014, at 09:47, Daniel Pensold wrote: > 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 > > > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/List-all-pixel-coordinates-in-ROI-tp3705127p5007586.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 |
Free forum by Nabble | Edit this page |