Login  Register

Re: How to get the centoid coordinates of any shaped roi

Posted by Rasband, Wayne (NIH/NIMH) [E] on Oct 13, 2016; 4:06am
URL: http://imagej.273.s1.nabble.com/How-to-get-the-centoid-coordinates-of-any-shaped-roi-tp5017351p5017361.html

> On Oct 11, 2016, at 11:20 PM, Maximilian Maske <[hidden email]> wrote:
>
> Dear ImageJ list,
>
> I am trying to get the coordinates of the centroid of my ROI, which is in my case a polygon roi I think. I can see the centroid coordinates by using the Analyzer but I need to call this from my plugin.
>
> 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 ImagePlus.getStatistics() method calculates area, mean, min/max, standard deviation, mode and median. To get the centroid, use ImagePlus.getStatistics(Measurements.CENTROID), as in this JavaScript example:

   stats = image.getStatistics(Measurements.CENTROID);
   IJ.log(stats.xCentroid+" : "+stats.yCentroid);

-wayne

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html