2
$\begingroup$

I need to determine the size of the 16 circles. Therefore I tried to binarize the picture to get the 16 circles, but i failed. I used a combination of Binarize, EdgeDetect and FillingTransform. But that wasn't successful.

The best results were obtained by:

res = Table[EdgeDetect[image, i] // FillingTransform, {i, 0.5, 5, 0.1}]

I thought I can overlay some single binarized images from res to get what I want. But that's very cumbersome.

Pattern

$\endgroup$
6
$\begingroup$

Well, I am sure that someone with more experience can do it better. Anyway, this is my approach.

I can see that the image can enhanced its contrast to make it darker, which delimitates the circles. Then, we can do some cleaning and can remove small elements. This gives:

newimg = MinDetect[ImageAdjust[img, 1.2], .02] // 
MorphologicalTransform[#, "Clean"] & // 
DeleteSmallComponents[#, 70] &

enter image description here

Now, we can retrieve properties of the resulting components in the image with restrictions, such as the area and the elongation of the best ellipse corresponding to the regions found:

circles = ComponentMeasurements[
newimg, {"Centroid", "EquivalentDiskRadius"}, #AdjacentBorderCount == 0 && 
150 < #Area < 3000 && -.8 < #Elongation < .8 &]

Then, we can see that the more approximate radius is about 18 pixels. We extract the data of the centroids, which will serve as the centres of the circles detected. Next, we create the circles having about 18 pixels for the radius, and, then, overlay the detected circles over the original image. The result is quite approximate to that requested:

markers = # -> 1 & /@ Floor@circles[[All, 2, 1]];
markersimg = ImageRotate@Image@SparseArray[markers, Reverse@Dimensions[ImageData@img]];
img2 = Dilation[markersimg, DiskMatrix[18]];
HighlightImage[img, img2]

enter image description here

Improvements would include detecting all the circles and a better location of the centres.

Using Generalized Hough Transform (GHT) to detect circles

Hough Transform, based on the Radon Transform, was devised to detect lines in an image containing edges of objects. The alogrithm has been successively improved (the GHT algorithm) to detect different geometrical (regular and non regular) smooth shapes.

Here, a custom GHT was provided to detect circles in a image. As far I know, MMA has not implemented GHT to detect circles yet. I have modified it minimally to show the final detected circles in the original image. Starting from the image newimg obtained above:

circlesimg = Show[ImageApply[Plus, HoughCircleDetection[#, 18, 21, 10, .3]], 
ImageSize -> ImageDimensions[#]] &[newimg];

I use this image and the data to obtain the circles to be detected:

Dilation[ImageRotate@
Image@SparseArray[# -> 1 & /@ 
 Floor@ComponentMeasurements[circlesimg, {"Centroid", "EquivalentDiskRadius"},
#AdjacentBorderCount == 0 && 
150 < #Area < 3000 && -.8 < #Elongation < .8 &][[All, 2, 1]],
Reverse@Dimensions[ImageData@img]], DiskMatrix[19]]

And, finally, it seems from the data that 19 pixels is the most appropriate value for the radius of all the circles detected in the original image:

HighlightImage[img, 
Dilation[ImageRotate@Image@SparseArray[# -> 1 & /@ 
  Floor@ComponentMeasurements[circlesimg, {"Centroid","EquivalentDiskRadius"}, 
#AdjacentBorderCount == 0 && 150 < #Area < 3000 && -.8 < #Elongation < .8 &][[All, 2, 1]], 
Reverse@Dimensions[ImageData@img]], DiskMatrix[19]]]

enter image description here

$\endgroup$
  • $\begingroup$ There’re a few questions about circular Hough transforms on here. I believe one of those may be able to help you out. $\endgroup$ – b3m2a1 Feb 3 '18 at 3:25
  • $\begingroup$ I read them. However, as far I know MMA have not implemented it yet. So a custom function must be utilised. Further, to use Hough Transform, one needs a clear edges image (no need to be closed) to find useful results, as you know. I will see how to add this... $\endgroup$ – José Antonio Díaz Navas Feb 3 '18 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.