Get x and y coordinates of a point in javascript

javascript
selection
Tags: #<Tag:0x00007fd540930ec8> #<Tag:0x00007fd540930d88>

#1

Hi, I;m trying to develop a script for my research and I need to get the X and Y coordinate of a selection point. For an ImageJ script getSelectionCoordinates(xpoints, ypoints) is working properly, however, I haven’t the same results within a javascript function. How can I get the X and Y coordinate of a selection point from Java?


#2

Dear @gabrieltorresl,

This should print the x and y coordinate of a point selection on the active image:

//@ ImagePlus impIn

importClass(Packages.ij.gui.Roi);
importClass(Packages.ij.IJ);

roi = impIn.getRoi();
IJ.log(roi.getType());
if (roi.getType() == Roi.POINT) {
	points = roi.getContainedPoints();
	IJ.log("("+points[0].x+","+points[0].y+")");
}

Best,
Stefan