0

I'm trying to draw exactly one line on all the edges of an image. I was able to draw the lines but some of the lines are repeated and I'm stuck on it for days, any help would be appreciated. I tried using the KMeans algorithm from sklearn but still don't even know if it's the correct choice for solving the issue. the sample code that produced the lines on the edge map is

hspace, angles, distances = hough_line(img) and  accum, angles2, distances2 = hough_line_peaks(hspace, angles, distances, threshold = 3, num_peaks = 13) 

def line(x, rho, theta):
   return (rho - x \* np.cos(theta)) / np.sin(theta)  

plt.imshow(img, "gra")
x = np.linspace(0, 1045000, 50000)
for i in range(13):
plt.plot(x, line(x, distances2\[i\], angles2\[i\]), label = 'line :' + str(i))
plt.xlim((0,img_sliced.shape\[1\]))
plt.ylim((img_sliced.shape\[0\], 0)) 

I Computed the edge map of the image using a canny edge detection the edge map looks like this edge mapthen I applied the Hough_line transform on the edge map to detect the lines and then applied the Hough_line_peaks. the resulting image looks like lines detected .as you can see from the image there are duplicated lines the question here is can I merge them or even remove one leaving the other if that is an option. any ideas will be appreciated.

Rastaw
  • 1
  • 1
  • Is very simple merging not enough? e.g. if evaluate distance between 2 lines and merge them if near enough, what happened? – fana Apr 25 '23 at 01:21
  • Or, consider reducing resolution of voting space of Hough. Of cause, result line parameters will be more coarsely, and so you will want to employ some refinement step. But you can start with "merged" result. – fana Apr 25 '23 at 01:26
  • @fana, simple merging would be enough. can you explain how to achieve that? and I don't really understand what you mean by reducing the resolution of voting space. – Rastaw Apr 25 '23 at 10:25
  • Hough transform is a vote-based method. Each edge point votes for all lines that pass through it, and then, lines obtained many votes will be extracted as the result. So, think about how voting result will change when resolution of the voting space changed. When with low resolution voting space, small differences in lines become indistinguishable, because the votes are cast in the same place. – fana Apr 25 '23 at 10:51
  • About simple merge : You know angle and distance for each line. So you can evaluate how similar 2 lines are, and merge them(just averaging line parameters may be most easy/crude way). – fana Apr 25 '23 at 10:58

0 Answers0