3
votes

I am trying to detect all the circles in the array. To achieve this I am using Hough Circle Transform. I am able to detect 100% circles in the array but there are a lot many false positives and when I get rid of the false positives I am not able to detect 100% circles. When I change the dp parameter to 1 in the code given below then all the false positives are gone and when I keep it as 3 then there are many false positives with 100% detection. I would like to get 100% detection with 0 or very few false positives. What would be the best approach to do this.

import cv2
import cv2.cv as cv
import numpy as np

img = cv2.imread('test1.tiff',0)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)

circles = cv2.HoughCircles(img, cv.CV_HOUGH_GRADIENT,3,15,
                        param1=70 ,param2=17,minRadius=1,maxRadius=10)

circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
    cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)

cv2.imshow('detected circles',cimg)
cv2.imwrite("output15.jpg", cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()

Here there is a sample image:

Original Image

No False PositivesFalse Positives

1
which one is "dp" in your code and what does it tune...?Ben
In any case, it's just playing with the parameters. It's very likely you won't get it as well as you'd like. Hough is pretty limited. you should write a script to automate running the transform over a range and pick out the one you like. That always saved a lot of time. Hough is also sensitive to noise, so you might try to denoise your image a little to see if that helps.Ben
The value 3 after cv.CV_HOUGH_GRADIENT is the dp parameter. I am playing with the parameters but I don't think so I would get the results I desire. I would try denoising the image like you suggested. Is there any other method you can suggest me which I can try for detecting the circles?user3756616
Why are you loading the image like this: img = cv2.imread('test1.tiff',0) cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR) isn't it already a color image??Яois
You still didn't tell me what "dp" does and now I had to look it up myself. It likely won't be the only parameter you have to tune. As you know Hough transform first does edge detection, and there are many faded circles, so if you want to really detect those, you'd have to set your threshhold way low. Post a picture of your false positives.Ben

1 Answers

5
votes

Since they are circles, and all dark, why not filter them out with a morphological disk and subtract the original image from the filtered one to get good responses? Morphology isn't particularly fast, but faster than Hough. What you'd do is dilate the background (with a disk shaped) until the black is gone, then subtract the original image from that. Then threshold. You can then do size filtering to eliminate any tiny scraps that could get through.

Given this application, I don't think Hough is the strongest choice, unless this is a school project.