Hi,
I'm writing a script that does the following : I have a smoothened lined obtained with the "Fit Spline" command on a line selection. I get the intensity profile along this line, and based on that profile the script detects a part of the ROI as the object of interest. Let's say that on the profile view, the ROI is 500 pixels long (p=0 to p=500) and that the detected object is 200 pixels long (from p=100 to p=300). Now I would like to trace this detected object on the original image. But i need to get the coordinates of the detected object as XY image coordinates from its coordinates along the profile. How could I do that ? - First, I'm sure this has been discussed before, but I can't find the method that gives all XY coordinates of a line ROI as two X,Y arrays, 1 pixel appart (in my exemple it should give me two arrays whose length is 500, one containing the X coordinates and the other one the Y coordinates). - Once I get that, It will be easy to use the profile coordinate as an index to find the corresponding X,Y coordinates. Thanks for your help, Christophe |
Hi Christophe,
if you have a smooth line (spline), you can use the macro call getSelectionCoordinates In a plugin you can use FloatPolygon fp = roi.getFloatPolygon(); The FloatPolygon class has public variables npoints, xpoints and ypoints that you can use http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi? p=imagej.git;a=blob;f=ij/process/FloatPolygon.java (The way how to find this out: if you know some function in the ImageJ macro language, have a look at ij/macro/functions.html to find the equivalent in java) Michael ________________________________________________________________ On 31 Oct 2011, at 15:48, Christophe Leterrier wrote: > Hi, > > I'm writing a script that does the following : I have a smoothened > lined > obtained with the "Fit Spline" command on a line selection. > I get the intensity profile along this line, and based on that > profile the > script detects a part of the ROI as the object of interest. Let's > say that > on the profile view, the ROI is 500 pixels long (p=0 to p=500) and > that the > detected object is 200 pixels long (from p=100 to p=300). > > Now I would like to trace this detected object on the original > image. But i > need to get the coordinates of the detected object as XY image > coordinates > from its coordinates along the profile. How could I do that ? > > - First, I'm sure this has been discussed before, but I can't find the > method that gives all XY coordinates of a line ROI as two X,Y > arrays, 1 > pixel appart (in my exemple it should give me two arrays whose > length is > 500, one containing the X coordinates and the other one the Y > coordinates). > - Once I get that, It will be easy to use the profile coordinate as an > index to find the corresponding X,Y coordinates. > > Thanks for your help, > > Christophe |
Hi Michael,
Thank you for your help! I have a problem though: the getFloatPolygon method gives me a number of coordinates that is around half of that obtained when doing a profile along the ROI (for a ROI with a profile that has 889 points, the method gives 410 coordinates for exemple), even after fitting a spline to the ROI. So I can't trivially map the coordinates between the profile and the 2D ROI. Can someone explain me why I don't get 889 coordinates using getFloatPolygon ? Christophe On Mon, Oct 31, 2011 at 16:24, Michael Schmid <[hidden email]>wrote: > Hi Christophe, > > if you have a smooth line (spline), you can use the macro call > getSelectionCoordinates > > In a plugin you can use > FloatPolygon fp = roi.getFloatPolygon(); > > The FloatPolygon class has public variables npoints, xpoints and ypoints > that you can use > http://pacific.mpi-cbg.de/cgi-**bin/gitweb.cgi?p=imagej.git;a=** > blob;f=ij/process/**FloatPolygon.java<http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=imagej.git;a=blob;f=ij/process/FloatPolygon.java> > > (The way how to find this out: if you know some function in the ImageJ > macro language, have a look at ij/macro/functions.html to find the > equivalent in java) > > Michael > ______________________________**______________________________**____ > > > On 31 Oct 2011, at 15:48, Christophe Leterrier wrote: > > Hi, >> >> I'm writing a script that does the following : I have a smoothened lined >> obtained with the "Fit Spline" command on a line selection. >> I get the intensity profile along this line, and based on that profile the >> script detects a part of the ROI as the object of interest. Let's say that >> on the profile view, the ROI is 500 pixels long (p=0 to p=500) and that >> the >> detected object is 200 pixels long (from p=100 to p=300). >> >> Now I would like to trace this detected object on the original image. But >> i >> need to get the coordinates of the detected object as XY image coordinates >> from its coordinates along the profile. How could I do that ? >> >> - First, I'm sure this has been discussed before, but I can't find the >> method that gives all XY coordinates of a line ROI as two X,Y arrays, 1 >> pixel appart (in my exemple it should give me two arrays whose length is >> 500, one containing the X coordinates and the other one the Y >> coordinates). >> - Once I get that, It will be easy to use the profile coordinate as an >> index to find the corresponding X,Y coordinates. >> >> Thanks for your help, >> >> Christophe >> > |
In reply to this post by lechristophe
On Oct 31, 2011, at 10:48 AM, Christophe Leterrier wrote:
> Hi, > > I'm writing a script that does the following : I have a smoothened lined > obtained with the "Fit Spline" command on a line selection. > I get the intensity profile along this line, and based on that profile the > script detects a part of the ROI as the object of interest. Let's say that > on the profile view, the ROI is 500 pixels long (p=0 to p=500) and that the > detected object is 200 pixels long (from p=100 to p=300). > > Now I would like to trace this detected object on the original image. But i > need to get the coordinates of the detected object as XY image coordinates > from its coordinates along the profile. How could I do that ? > > - First, I'm sure this has been discussed before, but I can't find the > method that gives all XY coordinates of a line ROI as two X,Y arrays, 1 > pixel appart (in my exemple it should give me two arrays whose length is > 500, one containing the X coordinates and the other one the Y coordinates). > - Once I get that, It will be easy to use the profile coordinate as an > index to find the corresponding X,Y coordinates. Use the "straighten" option of "Fit Spline" to get one pixel spacing and the getSelectionCoordinates() macro function or getFloatPolygon() method to get the coordinates as two arrays. Here is a macro example: run("Fit Spline", "straighten"); getSelectionCoordinates(x, y); x2=0; y2=0; distance=0; for (i=0; i<x.length; i++) { if (i>0) { dx = x[i] - x[i-1]; dy = y[i] - y[i-1]; distance = sqrt(dx*dx+dy*dy); } print(i, x[i], y[i], distance); } And here is a JavaScript version: imp = IJ.getImage(); IJ.run("Fit Spline", "straighten"); roi = imp.getRoi(); p = roi.getFloatPolygon(); x2=0; y2=0; distance=0; for (i=0; i<p.npoints; i++) { if (i>0) { dx = p.xpoints[i] - p.xpoints[i-1]; dy = p.ypoints[i] - p.ypoints[i-1]; distance = Math.sqrt(dx*dx+dy*dy); } x = IJ.d2s(p.xpoints[i],2); y = IJ.d2s(p.ypoints[i],2); d = IJ.d2s(distance,2); print(i+" "+x+" "+y+" "+d); } -wayne |
Free forum by Nabble | Edit this page |