1 | initial version |
Well, if these are representative images, you are probably better off doing something besides HoughCircles.
I suggest doing an adaptive threshold to segment the image into white and black, inverting the image, then performing connected components. If you use connectedComponentWithStats, it will return the centroid of every component (which would be the circles)
If you're worried about the edges, you'll have to remove any component that touches the edge of the image, but that shouldn't be hard.
t2 = cv2.imread('Test2.png')
thresh = cv2.cvtColor(t2, cv2.COLOR_BGR2GRAY)
thresh = cv2.adaptiveThreshold(thresh, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 101, 0)
count, labels, stats, centroids = cv2.connectedComponentsWithStats(thresh)
for i in range(1,count):
t2 = cv2.circle(t2, (int(centroids[i,0]), int(centroids[i,1])), 5, (0, 255, 0, 0), 5)
cv2.imshow('circles', thresh)
cv2.imshow('centers', t2)
cv2.waitKey()
2 | No.2 Revision |
Well, if these are representative images, you are probably better off doing something besides HoughCircles.
I suggest doing an adaptive threshold to segment the image into white and black, inverting the image, then performing connected components. If you use connectedComponentWithStats, it will return the centroid of every component (which would be the circles)
If you're worried about the edges, you'll have to remove any component that touches the edge of the image, but that shouldn't be hard.
t2 = cv2.imread('Test2.png')
thresh = cv2.cvtColor(t2, cv2.COLOR_BGR2GRAY)
thresh = cv2.adaptiveThreshold(thresh, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 101, 0)
count, labels, stats, centroids = cv2.connectedComponentsWithStats(thresh)
for i in range(1,count):
t2 = cv2.circle(t2, (int(centroids[i,0]), int(centroids[i,1])), 5, (0, 255, 0, 0), 5)
cv2.imshow('circles', thresh)
cv2.imshow('centers', t2)
cv2.waitKey()