How to add multipoint (x,y pair) lists to log file?

Greetings Forum,

I have an image and want to program following:
-first user selects points from set 1 using multi-point tool to get x and y coordinates (pixels),
-then these points are saved in a log file under xN and yN,
-then user selects another set of points (set 2) using multi-point tool
-and the second set of points are saved in the same log file under xNprime and yNprime.
So my log file should have , xN, yN, xNprime, yNprime lists; every time the user clicks on image pairs are appended to log file. My code so far doesn’t append any coordinates to logs, and it only asks for user to select for xN and yN

,

This is how I started,

\\ Open Image 
Imagename = File.openDialog("Open an Image");
if (Imagename=="")
	exit();
write("Image name = "+Imagename);
open(Imagename);

collect = true;
while (collect)
{

//-- Collect points
setTool("multipoint");
waitForUser("Select points for xN yN hit OK");

getSelectionCoordinates(x, y);
run("Add Selection...");
run("Select None");
run("Measure");


shortimagename = File.nameWithoutExtension;
logfile = File.directory+File.separator+"points_log.txt";
if (!File.exists(logfile))
	File.append("image name \txN \tyN \txNprime \tyNprime",logfile);
File.append(shortimagename+" \t"+x[0]+" \t"+y[0]+" \t"+x[1]+" \t"+y[1]+",logfile);

Dialog.create("Instructions");
	Dialog.addCheckbox("Keep going?", true);	
	Dialog.show();
	collect = Dialog.getCheckbox;
	waitForUser;
	
}	
print("stop")

Thanks for your help

If I understand correctly it would be easier to just store everything in arrays and write them once at the end of the collection of the 2nd set of points. So you avoid reading and writing , appending, creating a table, etc.

2 Likes