Get access to the values generated by " Save XY Coordinates "

Hi, I am analyzing an image using theAnalyze>Tools>Save XY Coordinates. Running it from the GUI is fine.
I am interested in writing a macro - when I record the macro, it records it as
run(“Save XY Coordinates…”, “background=0 save=[C:\Users\Desktop\Coordinates.txt]”);

Is there any way to return these values (x,y,pixel) into variables so that they can be processed from within the macro?


Good day Fares,

either you open the saved file in ImageJ again and use the new macro calls for accessing results table columns as arrays, or you loop through all selected pixels and gather the data yourself.



Thank you Herbie,
I wrote this macro and it works well :

rows=split(Data, "\n");
for(i=0; i<rows.length; i++){
1 Like

Yes, parsing text data is fine!

This is the new approach if you have the data in a Results table:

x = Table.getColumn("X");
y = Table.getColumn("Y");

Where x and y are the respective arrays already.



Hey Herbie,

That results table looks neat and like I’m trying to build. I have a macro that identifies a bunch of ROIs in an image and then saves the xy coordinates of the pixels of each region with run("Save XY Coordinates..."), but I don’t know how to put those results anywhere. Saving a csv and re-loading it for each region in each image seems cumbersome. How do I use nResults or setResult or etc when I have no variable handle by which to access the data?

Thanks for your time, apologies for the trouble