Mass Displacement Calculation




I just checked the source code of the ‘Mass Displacement’ calculation in the Module ‘MeasureObjectIntensity’.

I am not sure, but I think the formulas may not be correct (at least I do not understand their meaning :wink: ):

        %%% Calculate the Mass displacment (taking the pixelsize into account), which is the distance between
        %%% the center of gravity in the gray level image and the binary
        %%% image.
        PixelSize = str2double(handles.Settings.PixelSize);
        BWx = sum((1:size(BWim,2)).*sum(BWim,1))/sum(1:size(BWim,2));
        BWy = sum((1:size(BWim,1))'.*sum(BWim,2))/sum(1:size(BWim,1));
        Greyx = sum((1:size(Greyim,2)).*sum(Greyim,1))/sum(1:size(Greyim,2));
        Greyy = sum((1:size(Greyim,1))'.*sum(Greyim,2))/sum(1:size(Greyim,1));
        Basic{Object,11} = sqrt((BWx-Greyx)^2+(BWy-Greyy)^2)*PixelSize;

I think it should read:

        BWx = sum((1:size(BWim,2)).*sum(BWim,1)) / sum(sum(BWim));
        BWy = sum((1:size(BWim,1))'.*sum(BWim,2)) / sum(sum(BWim));
        Greyx = sum((1:size(Greyim,2)).*sum(Greyim,1)) / sum(sum(Greyim));
        Greyy = sum((1:size(Greyim,1))'.*sum(Greyim,2)) / sum(sum(Greyim));

which would correspond to the following definition:

rCG = Sum[r*m®] / Sum[m®]

where the Sum goes over all vectors r, so basically, one computes a weighted average of all vectors, where the weight is the mass (=intensity).

does this make sense?!

another thing that I do not understand in this module is the following:

Greyim is obtained as follows:

Greyim = OrigImage(rmin:rmax,cmin:cmax);

I don’t see how you restrict the Center of Gravity computation to the pixels that belong to the corresponding object.
Shouldn’t it rather read:

Greyim = OrigImage(rmin:rmax,cmin:cmax) .* (LabelMatrixImage(rmin:rmax,cmin:cmax)==Object);

such that only the pixels contribute that belong to the current object?! (if objects are close to each other it will not be sufficient just cut out a square…)

(in the lines above, which deal with Perimeter related computations, this is not necessary, because you only access pixels belonging to the object perimeter…
for the center of gravity computation, however, I feel one needs it…)

what do you think?



Hi Christian,

You are correct on both counts. We have made the appropriate corrections in the code which will be in the next release. Thank you for pointing this out to us!