2
votes

I am trying to implement circular hough transform by equation, r = sqrt((x-h)^2-(y-k)^2) for detecting circle from image.

I applied list of step like Gaussian Blur, canny. After that i am not getting how to implement above equation if radius and boundary points are available. After implementation i will get accumulator space which contain radius and center of detected circle. I want to implement with out HoughCircle function of opencv. Is there any idea which can help me?It's taking so much time.

import numpy as np
import cv2
import math

image = cv2.imread(imagepath)

h, w = image.shape[:2]
print h, w

grayimg = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)

bimg = cv2.bilateralFilter(grayimg, 5, 175, 175)

cann = cv2.Canny(bimg,100,200)

pixel = np.argwhere(cann == 255)


accum = []
ct = 0
for r in range(10,21):
    for h in range(0,20):
        for k in range(0,20):
            for p in pixel:
                print r,h,k,p
                xpart = (h - p[0])**2
                ypart = (k - p[1])**2
                rhs = xpart + ypart
                lhs = r * r
                if(lhs == rhs):
                    accum.append((r,(h,k),p))

print len(accum)
cv2.waitKey(0)
1
Your question is a bit unclear, Can you please explain more on this ? - ZdaR
look at Hough transforms - Rosa Gronchi
@ Rosa Gronchi I want to implement with out hough transform. - Zara
@ZdaR Consider one image which contains circle matrix. I want to implement given equation for circle detection. For above equation, x and y are boundary points of edge detected image and h,k can be every point on image. if above equation is satisfied it will result center value and radius of circle. For this scenario, radius is 10 to 20. - Zara
@Zara you're already using the Hough transform (from pixel space to equation parameters space) ... ;) - Miki

1 Answers

0
votes

Still some ugradation require in this code to make process fast for accumulator space.

accum = [[[0 for r in range(10,21)]for h in range(0,30)]for k in range(0,30)]
print accum
ct = 0
for r in range(10,21):
    for h in range(0,30):
        for k in range(0,30):
            for p in pixel:
                #print r,h,k,p
                xpart = (h - p[0])**2
                ypart = (k - p[1])**2
                rhs = xpart + ypart
                lhs = r * r
                if(lhs == rhs):
                    accum[k][h][r-10] += 1