# How to obtain the X y coordinates of profile at a specified pixel interval

Hello,

i need to extract the x and y coordinates along a profile at a much higher interval than 1pixel. Can anyone please provide insights as to how to go about it?

i believe the default from >Analyze>Tools>save coordinates is at 1pixel interval. I want to change it to 10pixels per interval.

Thank you

Hi
@Danboat

What do you call a “profile”?
You want the coordinates of the points of a line (straight or curved)…
Be more precise and the help of two images (one annotated and one unannotated) would be very useful for our understanding.

``````run("Blobs (25K)");
//setTool("line");
makeLine(21, 18, 224, 221);
// interval=20;
getSelectionCoordinates(x, y);
print (x.length);
print("----------------");
for (i=0; i<x.length-1; i++)
{
print("x="+x[i]+"         ||          "+"y="+y[i]);
``````

Have a good day.

x image.tif (112.8 KB)

Hello Matthew,

When i refer to a profile i mean something similar to the image attached.

I am running some analysis using Discrete fourier transform and i require a specific number of points along the line in the image shown earlier.

I dont know if your code will work for it

@Danboat
Indeed my proposal will not work with your image (it is an image resulting from a binarization?).
In addition there is not a continuous profile but 17 non-contiguous parts. How did you generate this image? Maybe the image before this one would get that solid line.

the images are generated by cutting slices through a 3d object. Because my analysis involve texture analysis, i have to trim of the sides and bottom and leave just the top. Sometimes i get continuous lines, other times i dont.

i have attached a typical sample of the slice through the 3d object.

I will be glad if you could really help out…

thanks

Best wishes

Hi
@Danboat
Take a quick tour here:

and here

Then come back and tell us if that helps.
Mathew

@Danboat
Using the methods described above we can find this:

``````Table.create("coordinate");
makeRectangle(13, 0, 973, 182);
run("Duplicate...", "title=1 ");
close("\\Others");
run("Duplicate...", "title=2 ");
selectImage("2");
//setTool("wand");
doWand(0, 91);
for(k=0;k<98;k++)
{
//setTool("line");
makeLine(k*10, 0, k*10, 66);
roiManager("select", k);
roiManager("Rename", k);
profile = getProfile();
for (i=0; i<profile.length; i++)
setResult("Values", i, profile[i]);
updateResults;
n=0;
for (i=0; i<nResults; i++)
{
if(getResult("Values", i)==0 )
n++;
}
print(n);
Table.set("X",k,k*10,"coordinate");
Table.set("Y",k,n-1,"coordinate");
Table.update;
}
close("results");
//----------------------------------------------
myArrayX=Table.getColumn ("X");
myArrayY=Table.getColumn ("Y");
Array.show (myArrayX);
Array.show (myArrayY);
//----------------
selectWindow("1");
makeSelection("point",myArrayX, myArrayY);
``````
1 Like

Hello Matthew,

The first image with the points is exactly what i want.
with regards to the code, what exactly do i need to edit. i am assuming i have to change the figures in the makeRectangle() to match the picture pixel dimensions…or??

Not too good with coding so pardon my questions.

thanks

This is what i want to be able to do… And clearly the code is working which is very encouraging.

however it looks like the X and y coordinates have been inverted according to the graphs unless i made a mistake.

Can this be corrected somehow.

thanksk

Best wishes

1 Like

@Danboat
The origin of the benchmark for ImageJ is on the top left.
You wanted the (topographic) profile of the coordinates of the upper line of the white surface / at the reference whose origin is at the top and to the left.

1 Like

@Mathew

Yes i have played with the figures and realized what it does. thanks once again. What of the inversion as i highlighted. Can it be corrected ?

@Danboat You will need to change the code.

What inversion are you talking about?

Alright.

I will try and figure out what to change. Looking for a needle in a hay stack so i hope i find it.

Thank you. With this code, i can apply to several images which i need to analyze.

Best wishes

1 Like

its like the y values have been multiplied by -1 so they are on the opposite side of the graph. they are pointing upwards instead of downwards. A careful review of the excel graph and image shows.

Exactly. That is what is happening. Ideally they should be on the same side of the axis?? or ??

@Mathew

I think i have solved the problem. To get the y coordinates on the opposite side, all i had to do was to subtract the values from the overall y pixel dimension. i.e if the pixel dimension is 1920 x 800, i need to subtract all the y values from 800 and voila it works.

thanks once again for all your help