http://imagej.273.s1.nabble.com/Center-of-mass-for-a-channel-tp3683783p3683784.html
example).
It's not a must.
> Hello,
>
> I'm developing a plugin and I need to calculate the center of mass for an image's red channel (I allow to select the channel from a combobox for convenience, but it's intended to work mainly with the red one)
>
> My images contain cells and some of them are pretty close to others, so I need to work with a ROI.
>
> The thing is to extract the channel, set the ROI (which comes from the main image) and get the center of mass point with getStatistics().
>
> My method to get the Center of Mass for a concrete channel is the following, but it doesn't seem to work, as the point appears outside of the ROI.
>
> Any tip? Or does anybody know if there is a better way to do this?
>
>
> private Point getCenterOfMass(ImagePlus imp, int channel) {
> RGBStackSplitter splitter = new RGBStackSplitter();
> splitter.split(imp.getStack(), true);
>
> ImageStack stack = null;
> switch (channel) {
> case 0:
> stack = splitter.red;
> break;
> case 1:
> stack = splitter.green;
> break;
> case 2:
> stack = splitter.blue;
> }
>
> ImagePlus aux = new ImagePlus("CM", stack.getProcessor(1));
> aux.copyScale(imp);
> aux.setCalibration(imp.getCalibration());
> aux.setRoi(imp.getRoi());
>
> ImageStatistics is = aux.getStatistics(ImageStatistics.CENTER_OF_MASS);
>
> Point CM = new Point();
> CM.setLocation(is.xCenterOfMass, is.yCenterOfMass);
>
> return CM;
> }
>
>
> Sincerely,
>
>
> ------------------------------------------------------------
> Juanjo Vega (
[hidden email])
>
> Unidad de Biocomputación. Laboratorio B-13.
> Centro Nacional de Biotecnología. CNB-CSIC.
> C\ Darwin, 3. Campus de Cantoblanco.
> Universidad Autónoma de Madrid.
> 28049, Madrid, Spain.
>
>
http://www.cnb.csic.es>
http://www.biocomp.cnb.csic.es>
> +34 91 585 4510
>
> "Las mejores almas son capaces de los mayores vicios como de las mayores
> virtudes, y aquellos que caminan despacio por el camino recto pueden
> llegar más lejos que los que corren pero se apartan de él." - Discurso
> del Método, René Descartes.
>