Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting line segments from a hough transform

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.

like image 879
mdm Avatar asked Jul 17 '11 13:07

mdm


4 Answers

I think this image, showing the Hough Transform for lines and segments will help you to catch what is happening:

enter image description here

like image 136
Dr. belisarius Avatar answered Oct 11 '22 14:10

Dr. belisarius


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

like image 35
Sean Avatar answered Oct 11 '22 15:10

Sean


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.

like image 36
jilles de wit Avatar answered Oct 11 '22 14:10

jilles de wit


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.

like image 37
ton4eg Avatar answered Oct 11 '22 14:10

ton4eg