I have an images of particles and I want to get the center point coordinates for each particle. I can get the coordinates with other imaging tools, but since my calculations are in mathematica i want to do everything in the same notebook. here are two images, one is with more resolution than the other one, preferably I want the image with Low Resolution

High Resolution HighRes Low ResolutionLow Res
Expecting Expecting

Thank you very much,


1 Answer 1


I followed the example in the article How to Count Cells, Annihilate Sailboats, and Warp the Mona Lisa on the Wolfram Blog, and got a pretty good result on the high resolution image:

img = Import["https://i.sstatic.net/Y3Sed.png"];
binary = Binarize[ImageAdjust[img], 0.4];
dist = ImageAdjust@DistanceTransform[binary, 0.5];
markers = MaxDetect[dist, 0.1];
 {Red, Values@ComponentMeasurements[markers, "Centroid"]}

Output of code

I hope it might help. Perhaps someone else can refine it.

  • $\begingroup$ Thanks for your answer, I get an error , I think my mathematica 9, doesn't recognize Values, what is the alternative? here is the error code: HighlightImage::mkinv: Expecting either an image or graphics with dimensions {162,449} or a list of positions to specify markers instead of {RGBColor[1,0,0],Values[{1->{64.,448.167},2->{99.,448.},3->{80.6111,440.722},4->{111.,437.},5->{60.5,431.583},<<41>>,47->{94.5,309.167},48->{73.9615,305.5},49->{122.75,299.5},50->{59.8,296.7},<<86>>}]}. >> $\endgroup$ Apr 4, 2020 at 4:04
  • $\begingroup$ @RacaioCmoto it is always better to include the version of your Mathematica/WL, especially when it is not the most updated one. As to fix your problem, one can make an intuitive jump that since Values pulls out the values of each Rule or Association and lists them, and each key is the indexed position in the list of values (more or less), one might consider the following: Range@Length@#/.#&@ComponentMeasures[markers, “Centroid”]. Maybe there’s a simpler way, though. $\endgroup$ Apr 4, 2020 at 6:51
  • $\begingroup$ I would use cm[[All, 2]] where cm is ComponentMeasurements[...]. $\endgroup$
    – C. E.
    Apr 4, 2020 at 7:22

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.