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

enter image description here

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:


{71.0501, 56.9741}

Can the conversion to the coordinate be obtained different?

  • 3
    $\begingroup$ 1 /. result will give the same answer $\endgroup$
    – bill s
    Commented Oct 10, 2016 at 16:36

1 Answer 1


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


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 = 
  newImage, {"Area", "IntensityCentroid"}, #1 >= 2 &, 

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


{71.0501, 56.9741}

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

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.