Is someone experienced with Application Nr. 3 shown in the ComponentMeasurements documentation: "Select complete and non-overlapping cells"?

That's the code (you can find the picture "i" in the documentation):

b = Binarize[i, {0, .7}]

cells = ComponentMeasurements[
  b, {"Centroid", 
   "EquivalentDiskRadius"}, #AdjacentBorderCount == 0 && 
    50 < #Area < 1200 &]

HighlightImage[i, Circle @@@ cells[[All, 2]]]

I want to use this code to find round objects in a picture, but it has not been working that well in some cases. I am attaching an example:

sample image: yellow filled dots and red hollow circles

Thanks in advance. Random Bubble Chart

  • 3
    $\begingroup$ Please post the image i in your case. $\endgroup$
    – cvgmt
    Jul 3, 2022 at 23:36
  • 1
    $\begingroup$ Your image has several overlapping disks, so I am not completely sure what you want to achieve. However, try this: b = GeodesicClosing[Binarize[i, {0, .8}], 30]; cells = ComponentMeasurements[b, {"Centroid", "EquivalentDiskRadius"}] It correctly identifies the non-overlapping circles (but it also finds the overlapping clusters). $\endgroup$
    – Domen
    Jul 4, 2022 at 11:42
  • $\begingroup$ Hi, in this image are only 2 overlapping disks, not several overlapping disks. I want to find all disks that are not overlapping and I don't understand why on one hand the code finds disks where there is actually nothing and on the other hand it doesn't find separated disks. $\endgroup$
    – Merlin
    Jul 4, 2022 at 11:48
  • $\begingroup$ @Merlin, you probably didn't post the original image without the red circles, am I correct? Otherwise, the red circles cross the yellow ones several times. $\endgroup$
    – Domen
    Jul 4, 2022 at 11:50
  • $\begingroup$ Yes, the original picture is a bubble chart with yellow disks, the red circles are produced by the code. I am not looking for a solution for that certain picture, it's just an example how the code doesn't work. $\endgroup$
    – Merlin
    Jul 5, 2022 at 5:53

1 Answer 1


ComponentMeasurements will find all connected components in the binarized image. That is, every connected "white island". It doesn't care about its shape. The code from the Applications in the documentations does also find the overlapping cells, but they are manually (!) filtered out by the condition 50 < #Area < 1200 &. If you remove this condition, even the overlapping cluster is found.


Therefore, you might consider the description of this application ("Select complete and non-overlapping cells") slightly misleading.

However, if you are indeed looking for round objects only, you can use property "Circularity", which is defined as "$2 \pi r/p$, with polygonal length $p$ and equivalent disk radius $r$". Round objects will have circularity very close to 1.

  b, {"Centroid", 
   "EquivalentDiskRadius"}, #AdjacentBorderCount == 0 && #Circularity > .9 &];

enter image description here

  • $\begingroup$ Thanks a lot Domen, that could be helpful, I'll try the code with my pictures. $\endgroup$
    – Merlin
    Jul 7, 2022 at 14:26

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.