How to get the centoid coordinates of any shaped roi

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get the centoid coordinates of any shaped roi

Maximilian Maske
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.

Can you help me here?


Thank you,

Maximilian


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

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

C Heeney
> 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
Reply | Threaded
Open this post in threaded view
|

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

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Maximilian Maske
> 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