How to measure centre of mass of an image?

Hi everyone!!
I already have loaded the image and what i want is to measure the center of mass.
How can i do this?
I’m programmimg in java.
If anyone could help me i’ll appreciate it very much.


Just Analyze > Set Measurements… and activate Center of mass:

then Analyze > Measure.

Running the recorder (Plugins > Macros > Record…) in Java mode while doing this will give you the necessary Java code:"Set Measurements...", "center display redirect=None decimal=4");, "Measure", "");

Alternatively, you can use the low-level Java API (see the javadoc). Here’s an example in Groovy (which is very similar to Java, and can be run as is from the script editor):

// @ImagePlus imp

import ij.measure.ResultsTable;
import ij.plugin.filter.Analyzer;

rt = new ResultsTable();
an = new Analyzer(imp, Analyzer.CENTER_OF_MASS, rt);


Thanks for the last part, i was really trying to do it with the API, but i wasn´t specific, thank you very much!!!

Hi again!!
I implemented the code you gave me, but when the ResultsTable came out, it was empty??

And after i measure the center of mass, i need that values in arrays for “x” and for “y”(i.e XM, YM).

Can you help me???