# Resulting list of ComponentMeasurements

I detect a single bright object in an image with the following code;

binImage = Binarize[image, 35/255];
newImage = ImageMultiply[image, binImage];
result = ComponentMeasurements[
DeleteSmallComponents[newImage, 2], "IntensityCentroid"]

{1 -> {71.0501, 56.9741}}


To get the coordinate I have to write:

result[[1]][[2]]

{71.0501, 56.9741}


Can the conversion to the coordinate be obtained different?

• 1 /. result will give the same answer Commented Oct 10, 2016 at 16:36

There are several ways to get individual measurements, apart from the obvious:

result[[1,2]]


As @bills commented:

1 /. result


You probably want to do something with the centroid, e.g. call some function - you can make that function accept data in ComponentMeasurements format:

foo[index_ -> {x_, y_}] := (* do something useful with x/y *)


and then apply that function to each element in result:

Map[foo, result]


Or, you can use replacement rules to turn result to any format you want, e.g.:

circles = result /. (index_ -> centroid_) :> Circle[centroid, 5];
HighlightImage[image, circles]


In recent versions of Mathematica, ComponentMeasurements can also return different output formats, e.g. "PropertyAssociation" returns an Association of property names to value lists:

resultAssociation =
ComponentMeasurements[
newImage, {"Area", "IntensityCentroid"}, #1 >= 2 &,
"PropertyAssociation"]


<|"Area" -> {45., 2.}, "IntensityCentroid" -> {{71.0501, 56.9741}, {67.0714, 54.5}}|>

(Note that I've replaced DeleteSmallComponents with a criteria function as 3rd parameter.)

resultAssociation["IntensityCentroid"][[1]]


{71.0501, 56.9741}

• Thank you very much for your explanation.
– mrz
Commented Oct 10, 2016 at 18:59