How can I detect line segments instead of lines in an image after performing a Hough Transform? Does it make sense to save the minimum and maximum coordinates for each accumulator bin or is there a better way?
I'm not using OpenCV, btw.
I think this image, showing the Hough Transform for lines and segments will help you to catch what is happening:
Basically, you'll have to keep track of exactly which points contributed a vote to each Hough bin. You can do this either after you fill the bins (as in the Matlab version) or as you're filling the bins (more efficient, but also more memory intensive which might not be good for an embedded platform). From there, you can follow the pixels along the line to extract the actual segments, creating a new segment when the gap between neighboring pixels is too large.
See this partial description of the Matlab algorithm for more information on how to extract which pixels contributed to a specific Hough bin, including the actual implementation (linked to as hough_bin_pixels.m).
Even if you don't use OpencV You could look at the code for the HoughLinesP function that one returns line segments.
And yes, saving the extreme coordinates of the accumulator bins makes sense.
[edit 2011-07-19] If you have multiple line segments that lie on the same line as in belisarius' example above then you would have to do some more work, just remembering the extreme coordinates won't be enough. So it depends on you exact application.
Matlab has houghlines function that does exactly what you want. It extracts line segments based on hough transform.
http://www.mathworks.com/help/toolbox/images/ref/houghlines.html
Saving extreme coordinates for hough bins will not work if two separate line segments lies on the same line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With