6

I'm testing to see if I can count/draw circles around dots I drew on a piece of paper, this research is for my thesis as I want to count the amount of pinholes in a composite laminate. I tried several methods that were already given in several forums.

The code I use is:

img = Import["https://i.imgur.com/Wu7pSBY.jpg"];
i = GaussianFilter[FillingTransform[img], 15];
b = Binarize[i];
d = DistanceTransform[b, Padding -> 0];
m = MaxDetect[ImageAdjust[d, 0.2]];
w = WatershedComponents[GradientFilter[b, 3], m, Method -> "Rainfall"];
s = SelectComponents[w, "Count", 20 < # < 10000 &];
ms = ComponentMeasurements[
   s, {"Centroid", "EquivalentDiskRadius", "Label"}];
Show[seimg, 
 Graphics[{Blue, Circle @@ # & /@ (ms[[All, 2, 1 ;; 2]]), 
   MapThread[Text, {ms[[All, 2, 3]], ms[[All, 2, 1]]}]}]]

I have zero to none idea what this all does, but the results are this (click for full size):

Image

The only thing I want it to do is draw circles around the dots and count them. Can anyone help out?

C. E.
  • 70,533
  • 6
  • 140
  • 264

1 Answers1

6

I think I have a solid way now to count them, my code is:

img = Import["https://i.imgur.com/Wu7pSBY.jpg"];
b = DeleteSmallComponents[ColorNegate[Binarize[img]], 50];
c = ComponentMeasurements[
   b, {"Centroid", "EquivalentDiskRadius", "Label"}];
Show[b, Graphics[{Red, Circle @@ # & /@ (c[[All, 2, 1 ;; 2]]), 
   MapThread[Text, {c[[All, 2, 3]], c[[All, 2, 1]]}]}]]
c // Length

This resulted in this:

Image

Thanks for the help everyone!

C. E.
  • 70,533
  • 6
  • 140
  • 264