Generating xy coordinates for both a line and points along the line (same scale)

I am having trouble producing a .txt file (or excel file) of xy coordinates of selected points along a line. I am successfully able to produce a .txt file (or excel file) for the xy coordinates of a drawn line (which I have already manually traced using the brush tool, and selected using the wand tool), using Analyze > Tools > Save as XY Coordinates. The values in the file seem to range from the 100’s to 3000’s. I have already set the scale at 117 pixels/cm (and I have seen that the default xy origin point is the upper left corner of the image).

However, if I select points along that same line using the multi-point tool, select them using the wand tool, and then use Analyze > Tools > Save as XY Coordinates, it gives me the xy values for the points, but they appear to be on a completely different scale (values are ranging from 8 to 10, not 100’s to 1000’s).

How might I be able to save the xy coordinates of these points specifically, using the same scale as what was used for the line?

Attached is an image of the line (the points I want to define are the maximum points wherever the line peaks). 164_D50_112020_practice2.tif (3.6 MB)

Hi
@kbrande

I don’t understand the situation.
But I had this in my data.
This macro does not answer your problem but can help you build one.

newImage("Untitled", "8-bit white", 512, 512, 1);
//setTool("freeline");
type = selectionType();
if (type!=7)
waitForUser("Select freehand line");
waitForUser("Make a vaguely sinusoidal line;");
run("Interpolate", "interval=20 adjust");
roiManager("Add");
x = newArray();
y = newArray();
getSelectionCoordinates(x, y);
     for (i=0; i<x.length; i++)
{
 print(i+" "+x[i]+" "+y[i]);
}
Array.show("Results", x, y) ;
  print("\\Clear");
print("maximum");
close("x");
close("y");
for(j=1;j<nResults-1;j++)
{
if(getResult("y",j-1) < getResult("y",j)&&getResult("y",j)>getResult("y",j+1))
{
print(getResult("x",j),getResult("y",j));
makePoint(getResult("x",j),getResult("y",j));
roiManager("Add");
}
}
selectWindow("Log");
roiManager("Show All without labels");

Hi
@kbrande

Here is the result I get with your image

Uploading: Results-00.jpg…

using this macro.

run("Select None");

run("Duplicate...", "title=0");
run("Set Scale...", "distance=0 known=0 unit=pixel");
//setTool("rectangle");
makeRectangle(498, 1110, 1554, 570);
run("Crop");
run("Duplicate...", "title=1");
run("Duplicate...", "title=2");
//setTool("wand");
doWand(636, 534);
setBackgroundColor(0, 0,0);
run("Clear", "slice");
run("Interpolate", "interval=10");
run("Fit Spline");
getSelectionCoordinates(x, y);
     for (i=0; i<x.length; i++)
{
 print(i+" "+x[i]+" "+y[i]);
}
rw=getWidth();
rh=getHeight();
Array.show("Results", x, y) ;
//----------------------------------------
  print("\\Clear");
for(j=0;j<nResults-1;j++)
{
//If you want the hollows
//if (getResult("x",j)>4 && getResult("x",j)<rw-4 && getResult("y",j)<rh-4 && getResult("y",j-1)< getResult("y",j) && getResult("y",j)>getResult("y",j+1))
//If you want the tops
if (getResult("x",j)>4 && getResult("x",j)<rw-4 && getResult("y",j)<rh-4 && getResult("y",j-1)> getResult("y",j) && getResult("y",j)<getResult("y",j+1))

{
print(getResult("x",j),getResult("y",j));
makePoint(getResult("x",j),getResult("y",j));
roiManager("Add");
}}
run("Point Tool...", "type=Hybrid color=Red size=XXL label show counter=0");
close("0");
close("2");
selectWindow("1");
roiManager("Select", newArray(0,1,2,3,4));
RoiManager.setGroup(0);
RoiManager.setPosition(0);
roiManager("Show All without labels");

Note that the vertices are not found exactly.
To refine the result you will have to play with the parameters of:

run("Interpolate", "interval=10");
run("Fit Spline");

There is probably a better treatment than what I am suggesting.

Hi @Mathew ,

Thank you for your response! Unfortunately I am quite the beginner to ImageJ and am not familiar with how to use macros. But it appears your macro generates the xy values for the points (“vertices”) that are considered the maxima along my line. Why wouldn’t they be found exactly? (Perhaps its a matter of adjusting the “interval=” part of the interpolation?)

I’m still just confused why I couldn’t use the same steps in the menu as what I used to generate the xy values for the whole line. I figure there has to be a way using the existing menu options?

I would also need the option to manually select the points along the line (here we are obviously choosing the points based on being the maxima). Because in the future, the points I want may not necessarily be the maxima.

Hi
@kbrande
To answer your problem :

test this macro:

  1. Open your image posted on the forum
  2. Paste the macro in “Plugins” → “New”
text=getTitle();
run("Show Info...");
msg="Is the image resolution value 125 pixels per cm?";
if(getBoolean(msg) == 1) 
{

print("The scaling-Resolution- is indeed 125 pixels per cm.");
scaling=125;
close("Info for "+ text);
//----------------------------------------------------------------------
//Step 1
//---------------------------
//setTool("rectangle");
makeRectangle(114, 987, 1977, 713);
run("Crop");
rename("Reference image");
setAutoThreshold("Default");
//run("Threshold...");
//setThreshold(0, 128);
setOption("BlackBackground", false);
run("Convert to Mask");
run("Analyze Line Graph");

// Step 2
//--------------------
Plot.showValues();
//----------------------------
// Complete one table for the values ​​of x and another for the values ​​of y
//------------------------
x = newArray();
// loop the table rows
for ( i=0; i<nResults; i++ ) 
x=Array.concat(x,getResult("X",i));
//Array.show (x);
//---------------------------
y = newArray();
// loop the table rows
for ( i=0; i<nResults; i++ ) 
y=Array.concat(y,getResult("Y",i));
//Array.show (y);
close("Line Graph");
IJ.renameResults("Results","All points results");

//------------------------------------------
// Step 3 Select your point 
selectWindow("Reference image");
run("Set Scale...", "distance=125 known=1 unit=cm global");
//setTool("point");
waitForUser("Choose the point of interest.");
run("Point Tool...", "type=Hybrid color=Red size=Large label show");
roiManager("Add");
roiManager("Measure");
yr=getHeight();
y=(yr/scaling)- getResult("Y",0);
x=getResult("X",0);
print("The origin of the mathematical reference is at the bottom left.");
print("Coordinates of a point are :", x +" cm"+" ;  " +y+" cm");
close("Results");
selectWindow("Log");
}
else
exit( "Check your scaling.The scaling value in the macro must be suitable for your scaling. ");

Please let me know if this is suitable.