Ozum Safa
Ozum Safa

Reputation: 1518

Opencv hough circles perform better if I resize image to double the size

I have an image like below :

enter image description here

I am trying to detect the circles via HoughCircles function. Prior to detection, I threshold the image, and blur it via gaussian technique. The result is like follows :

enter image description here

The inverted image is larger, because I happened to find out that, if I dont resize image with same aspect ratio, hough circles algorithm goes nuts and finds either very few circles, or very wrong set of circles. I do understand the hough transformation algorithm to an extent. I use this snippet to detect the circles :

circles = cv2.HoughCircles(invertedBlurredImg, cv2.HOUGH_GRADIENT, 1, 30, param1=100, param2=23, minRadius=7, maxRadius=20)

I tried a lot of different dp values ranging from 1 to 2. I do think that if I get it close to 2, the sensitivity drops and, it becomes somewhat more possible to find the circles in a bad quality image. However, even if I dont enlargen the inverted image, I think the circles are quite clear, and I dont understand why it cannot find all the circles, unless I enlargen the image.

Here are the detected circle in case of the original sized image, and enlarged image, respectively.

enter image description here

enter image description here

What is the positive effect I receive from enlarging the image? Does it kinda work like dilation because of the interpolation that goes on during the resizing to a larger image ?

Thanks

Upvotes: 1

Views: 1339

Answers (1)

Humam Helfawi
Humam Helfawi

Reputation: 20324

You had a problem and you have solved it in another way. Your problem is the parameters of the HoughCircle. They are too high for your small circles. Instead of changing them, you changed the image size. Thus gave you a good results since your new image is suitable for the old paramters.

The solution is to change your HoughCircle parameters until you got a good results on your original image. I am pretty sure it is the minRaduis which need to be decreased a bit.

Upvotes: 0

Related Questions