Hough transform for line detection

Hough transform for line detection helps to find lines in an image even if the points are not connected and the lines are not perfectly straight. It works with a voting procedure where each point in the image votes for all the possible lines that pass through it. The line with more votes corresponds to the most likely one.

In the following applet you can draw anything on the left and see the transformed image on the right. Each point in the original image contributes to many points (a curve) in the transformed image, and each point in the transformed image represents a straight line in the original image (you can move the mouse there to see it). The brightest points in the transformed image are likely to be caused by a straight line in the original image.

This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

Usage:

  • Press keys 'i' and 'u' to change the image
  • Press keys 'r' to reset to a black image
  • Press 'Esc' to stop the applet (reload the page to start again)

If you don't have the Java plug-in you can watch a video of it

If you draw a line, it corresponds to the brightest point of the Hough transform:

Hough transform of a line

In fact, for each line two points are detected, this is because we are plotting degrees from 0 to 360, but plotting from 0 to 180 would be enough. In other words, you can ignore half of the transformed image.

In this transform the horizontal axis corresponds to the angle of the line and the vertical axis corresponds to its distance from the center of the image.

Several parallel lines are transformed to points in the same horizontal coordinate:

Hough transform of parallel lines

Even with just a few points, a line can be detected:

Hough transform of some aligned points

Short lines can be detected as well:

Hough transform of short lines

and sometimes other lines emerge:

Hough transform of short lines

The Hough transform for line detection applied to circles, detects tangent lines:

Hough transform of two circles

If you want to apply it to real images, you have to detect the edges first. In the case of the cameraman test image, it detects the tripod:

Hough transform of a cameraman

In noisy images, like this baboon, the noise may hide the real lines of the image:

Hough transform of a baboon

Hough transform of a baboon

In a random noise image, the diagonals will be detected, because the diagonals are the longest lines inside the square:

Hough transform of random noise

There are many variations of the Hough transform, that are used for circle detection or generic shape detection, but they are more complex and the transformed image (the “parameter space”) has more than two dimensions and it would be difficult to visualize it here.

In OpenCV, the function cvHoughLines2() with the CV_HOUGH_STANDARD mode implements the same line detection that we have been talking about, except that it returns the detected lines and not the transformed image. It can find line segments as well using the CV_HOUGH_PROBABILISTIC mode. The function cvHoughCircles() finds circles of any radius in an image.

Comments

medo, 2012/11/03 23:02

thanks for your post

can you help me for Hough transform for circle detection

any post or link can help me

i use opencv for cvhougthcircle but i cant know how it work exactly

thanks

Octavi Estapé, 2012/11/05 11:08

You can read the book “Learning OpenCV”. It explains Hough Transform for lines and circles. In the book you can find a small example very similar to that one:

http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.html

the book uses the C style (cvHoughCircles), and the documentation in the website uses the C++ style (HoughCircles), but the meaning of the parameters is the same.

Enter your comment
If you can't read the letters on the image, download this .wav file to get them read to you.
 
 
Back to top
hough_transform.txt · Last modified: 2021/08/05 14:14 (external edit)
 
 
CC Attribution-Noncommercial-Share Alike 3.0 Unported
chimeric.de = chi`s home Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0