Intensity along a line with a "pixel-relative" coordiantes


I am looking for a way to find the intensity along a line (yellow line circled in blue), but instead of the (X,Y) coordinates that correspond to the distance from the line beginning (blue arrows), I wish to obtain the coordinates that correspond to the pixels of the entire image with a given origin. For example, if my image is a 4X4 ( raws X columns ) matrix, and I draw a line from (3,1) to (3,3), I wish to get the following Table:

X; Y: intensity
1; 3; somthing
2; 3; somthing
3; 3; somthing

I noticed that there is a similar post:

However, if I use the given script, I need to insert the coordinates manually every single time (sorry if I did not understand the code correctly, I am not familiar with the syntax)

You can trace the line, then to the measurements (ctrl+m) and then in the Results window, you go to the menu Results>Set Measurements and check the boxes “mean gray value” (from what I understand, this is the value of the intensity you are interested in), and as well as “Bounding rectangle” (this will give you BX, BY, Width and Height) from which you basically have the coordinates of the line you plotted.

Hope this helps.

To complete Adrien’s [ @LeChat ] info, I did a little macro-test.
It gives you the results in two tables. Personally I will go through a spreadsheet, copying / pasting. It’s easier to deal with.
Can you tell me about your results, if you don’t mind.

// Step 1
newImage("test", "8-bit ramp", 512, 512, 1);
makeLine(34, 200, 434, 200);
run("Interpolate", "interval=1");
//run("Interpolate", "interval=1 adjust");
print("Number of points=", X.length);
//print( lengthOf(xCoordinates) );"Selection Coordinates",X,Y);
print("Table title=",Table.title);

// Step2
p = getProfile();
Plot.create("gray values", "xInterval", "grayvalue", p);;
Plot.getValues( xInterval, grayvalue );"Value",xInterval,grayvalue);
print("Table title=",Table.title);
print("Table size=",Table.size);
1 Like

Just add this code, to the @Mathew’s code so everything is in 1 table.


and maybe make the second line a bit more exciting:
makeLine(34, 300, 434, 200);

1 Like

First of all thank you, because although I knew that I had to go through setResult I did not see how.
A small step forward for me, thanks to you.