2
$\begingroup$

If I have an image img, and I ask ComponentMeasurements to return "IntensityValues" for the image:

m=MorphologicalComponents[Binarize[img]];
ivalues=ComponentMeasurements[{m,img},"IntensityData"];

How can I replicate the output of ComponentMeasurements[{m,img},"IntensityCentroid"]?

The challenge I'm having is understanding how to interpret a calculated intensity centroid from "IntensityValues" in the context of larger image with the overlayed morphological component? Is it flipped or rotated? It would be fantastic to see an example going from the raw "IntensityValues" data to the output of ComponentMeasurements[{m,img},"IntensityCentroid"] for the same morphological component.

$\endgroup$
2
  • $\begingroup$ Check out ImageMeasurements. I imagine it uses the same method as that under the hood to compute the intensity centroid or intensity values for each component. To replicate the result by applying ImageMeasurements on each component, this might be of help: mathematica.stackexchange.com/questions/28826/… $\endgroup$
    – C. E.
    Aug 14, 2013 at 7:29
  • $\begingroup$ @Anon I was hoping for someone to show me how to manually compute the measurement, since I was having some trouble getting it right. $\endgroup$
    – Ynv
    Aug 14, 2013 at 7:48

1 Answer 1

3
$\begingroup$

Something like this:

img     = ExampleData[{"TestImage", "Lena"}];
m       = MorphologicalComponents[Binarize[img]];
ivalues = ComponentMeasurements[{m, img}, "IntensityData"];

cents = ({#[[2]] - .5, ImageDimensions[img][[2]] - #[[1]] + .5} & /@ 
        (Total[Position[m, #] (# /. ivalues)]/Total[(# /. ivalues)] & /@  Range[Max[m]]));

Testing:

Chop[cents - ComponentMeasurements[{m, img}, "IntensityCentroid"][[All, 2]]]

{{0,0}, {0,0}, ... {0,0}}

$\endgroup$
2
  • $\begingroup$ +1, but it should be ImageDimensions[img][[2]] $\endgroup$ Aug 14, 2013 at 13:26
  • $\begingroup$ @SimonWoods You're right of course. The image coordinates are always a source of bugs. I shouldn't test with square images! Thanks. $\endgroup$ Aug 14, 2013 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.