How to “de-dupe” similar lines (detected using the Hough Transform as rho/theta pairs)

algorithmsimage processing

I'm trying to identify an object (a cube) in a set of photos. Using Canny/Sobel/Hough I've managed to get the photo down to a set of lines that are pretty accurate; however if I plot these lines on my image there are a lot of duplicates where the angle/distance varies only a tiny amount. Here's a cut down sample:

Lines from Hough Transform plotted

I thought I could reduce these by simply looking for lines that have a rho/theta values within a certain tolerance. However, the problem I discovered is that the more vertical a line is (the further the intersection at x=0) the greater the difference in the rho value for the same angle:

I hope this makes sense :)

This doesn't seem like a problem maths can't fix; but it seems like there should be tried-and-tested method for doing this yet I'm failing to find any good info online about the best way to do this (either maths to allow for this, or a generally better way of merging similar lines within the image space for the output of Hough Transform).

I did wonder if converting them to x/y pairs for the edges of my image (eg. the points to use to render a line) and then comparing them might be a better idea. I'm going to give this a go; but if it's not the "normal" way to do it, I'd like to know!

Best Answer

Well, I went ahead and tried converting to x/y pairs and then de-duping where both sets were within 5% of their respective axis. I don't know if this is a good way to do it, but it's definitely gotten me closer!

enter image description here

There's something wonky with a bunch of lines starting at 0, 0 (I reckon they should be perpendicular, and suspect the noise at top might be overwhelming the real edge from the cube centre corner, but I don't care for those lines ultimately anyway), and I have a problem for "perfectly vertical" lines (theta is 0, causes errors in some of my maths) but this page seems to have a solution to that.

Posting this as an answer in case it helps others, but still hoping for a better answer (or confirmation this way make sense).

Related Topic