Login  Register

Re: Center of mass for a channel

Posted by Juanjo Vega on Jul 21, 2011; 9:14am
URL: http://imagej.273.s1.nabble.com/Center-of-mass-for-a-channel-tp3683783p3683785.html

Hi,

Yesterday I managed to fix the problem.

The point was calculated properly, but when drawing it into the image, it was in a wrong position.

If I copy scale and calibration after obtaining the center of mass it works fine.

>  aux.copyScale(imp);
>  aux.setCalibration(imp.getCalibration());


I still don't understand why, but now it's working :)

Thank you very much for your help :)

Sincerely,

Juanjo


On Jul 21, 2011, at 10:51 AM, Peter Haub wrote:

> Hi,
>
> I've checked your code and can not see any problem (with an simple image example).
>
> Are you sure that the CM has to be inside the ROI?
> It's not a must.
>
> ph
>
>
> On 19.07.2011 18:06, Juanjo Vega wrote:
>> 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.
>>

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