0
$\begingroup$

I am using hough transform on the following image after canny edge detectionImage after edge detection

 hough_img=Image.fromarray(tem.T)
 # Hough
 d=(hough_img.height**2+hough_img.width**2)**(1/2)
 rho=0
 acc=np.zeros((180,int(d)),dtype=np.int32)
 for x in range(hough_img.width):
    for y in range(hough_img.height):

    if(hough_img.getpixel((x,y))==255):
        for theta in range(0,180):
            temp=x*np.cos(np.deg2rad(theta))+y*np.sin(np.deg2rad(theta))

            print("ss",temp,theta)
            if(temp>0):
                acc[theta,abs(int(temp))]+=1

 import heapq

 para=[] ## theta and rho parameters above a certain threshold
 maxx=heapq.nlargest(30,acc.ravel())[0]

 for x in range(acc.shape[0]):
    for y in range(acc.shape[1]):
       if(acc[x][y]>(0.5*maxx)):
          para.append((x,y))
 k=deepcopy(new)
 theta_peaks=[x for (x,y) in para]
 associated={} ## to find associated pixels with max values in accumulator




## again traversing through each pixel which voted for max value points in 
accumulator
for i in range(hough_img.width):
    for j in range(hough_img.height):
      if(hough_img.getpixel((i,j))==255): ## pixel value at i,j
        for the in theta_peaks:
            temp=i*np.cos(np.deg2rad(the))+j*np.sin(np.deg2rad(the))
            temp=abs(int(temp))
            print(the,temp)
            if((the,temp) in para):
                print("yes")




       associated[((the,abs(int(temp))))]=
       associated.get(((the,abs(int(temp)))),[])+ 
         [(i,j)]



   for coords in associated.values():

       d=ImageDraw.Draw(k)
       d.line(coords, fill=None, width=0)

But I'm getting wrong lines(below) detected by hough transform, I'm not sure where I'm wrong, either the implementation or the threshold.

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.