1 year ago
#379946

Protes
Hough circle implementation using python without "opencv"
I'm trying to implement the Hough circle by using python without cv2 - ("OpenCV")
I have checked the python implementation of hough circles in "detectCircles" function in
https://github.com/PavanGJ/Circle-Hough-Transform/blob/master/main.py
and my code below is based on implementation in above
I have some problems adjusting my function with simple parameters
My original function parameters is : image_input, minimum_radius, max_radius,
I must return a list with contains the center(x,y) and the radius of the circle
the list return is like the from (x,y,r) the (x,y) for center and r for radius
def AlgoHoughCircle(input: np.ndarray, minimum_radius: float, maximum_radius: float) -> list:
img_h, img_w = input.shape
input = cv2.GaussianBlur(input, (5, 5), 0)
input = input.astype('uint8')
input = cv2.Canny(input, 50, 100)
x_y_edges = np.argwhere(input > 0)
A = np.zeros((maximum_radius, img_h + 2 * maximum_radius, img_w + 2 * maximum_radius))
theta = np.arange(0, 360) * np.pi / 180
for r in range(round(minimum_radius), round(maximum_radius)):
bprint = np.zeros((2 * (r + 1), 2 * (r + 1)))
(x_0, y_0) = (r + 1, r + 1)
for angle in theta:
x = int(np.round(r * np.cos(angle)))
y = int(np.round(r * np.sin(angle)))
bprint[x_0 + x, y_0 + y] = 1
constant = np.argwhere(bprint).shape[0]
for x, y in x_y_edges:
A[r, x - x_0 + maximum_radius:x + x_0 + maximum_radius, y - y_0 + maximum_radius:y + y_0 + maximum_radius] += bprint
threshold = 7
A[r][A[r] < threshold * constant / r] = 0
B = np.zeros((maximum_radius, img_h + 2 * maximum_radius, img_w + 2 * maximum_radius))
region = 15
for r, x, y in np.argwhere(A):
environment = A[r - region:r + region, x - region:x + region, y - region:y + region]
p, a, b = np.unravel_index(np.argmax(environment), environment.shape)
B[r + (p - region), x + (a - region), y + (b - region)] = 1
circleCoordinates = np.argwhere(B[:, maximum_radius:-maximum_radius, maximum_radius:-maximum_radius])
return circleCoordinates
python
image-processing
hough-transform
0 Answers
Your Answer