Here is an image which I am trying to get the circles from.
I used difference of gray image and erosion to get the boundaries.
img_path= 'input_data/coins.jpg'
img = cv2.imread(img_path)
rgb,gray=getColorSpaces(img)
a,b=0,255
plt.figure(figsize=(12, 12))
erosion_se=cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
erosion = cv2.erode(gray,erosion_se,iterations = 1)
boundary=gray-erosion
image, contours, hierarchy = cv2.findContours(boundary,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
plt.imshow(boundary,'gray')
I could get the circles for most of the circles whose boundaries are relatively distinct. I want to do two things
Get the count of circles that are overlapping.
Find the circles that are touching image boundary. I can determine, by comparing the radius of the circle with with image boundary. The issue is 2 specific blobs are not detected as circles.
circles = cv2.HoughCircles(boundary, cv2.HOUGH_GRADIENT, 1, 20,
param1=30,
param2=15,
minRadius=5,
maxRadius=20)
if circles is not None:
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
cv2.circle(img,(i[0],i[2]),i[3],(0,255,0),2)
cv2.circle(img,(i[0],i[2]),2,(0,0,255),3)
cv2.imshow('circles', img)
k = cv2.waitKey(0)
if k == 27:
cv2.destroyAllWindows()
Below is the output after HoughCircles from the circles boundary image.The big green circle which stands out is undesired.I am not sure why for some of the overlapping regions ,the circles are not detected.