# Using Hough Transform to detect lines in an image

I am using hough transform on the following image after canny 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):

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=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.