Re: How to get the centoid coordinates of any shaped roi
Posted by
C Heeney on
Oct 12, 2016; 4:32pm
URL: http://imagej.273.s1.nabble.com/How-to-get-the-centoid-coordinates-of-any-shaped-roi-tp5017351p5017356.html
> I tried like this:
> Roi roi = image.getRoi();
> ImageStatistics stats = roi.getImage().getStatistics();
> System.out.println("(" + stats.xCentroid + " : " + stats.yCentroid + ")");
> But at the moment I will get an output (0.0 : 0.0) which I don't understand.
The getCentroid() function in the statistics Class should probably relate to the statistics themselves.
If you're looking for the Centroid of the ROI, then you need the getContourCentroid() function from the Roi class.
(
https://imagej.nih.gov/ij/developer/api/ij/gui/Roi.html#getContourCentroid-- )
some code (tested on a polygon Roi in a sample image):
Roi roi = this.image.getRoi();
double result[] = roi.getContourCentroid();
IJ.log("X: " + result[0]);
IJ.log("Y: " + result[1]);
Hope this helps
Conor
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html