Image Processing Toolbox User's Guide Previous page   Next Page

Detecting Lines Using the Hough Transform

The Image Processing Toolbox includes functions that support the Hough transform.

The hough function implements the Standard Hough Transform (SHT). The Hough transform is designed to detect lines, using the parametric representation of a line:

The variable rho is the distance from the origin to the line along a vector perpendicular to the line. theta is the angle between the x-axis and this vector. The hough function generates a parameter space matrix whose rows and columns correspond to these rho and theta values, respectively.

The houghpeaks function finds peak values in this space, which represent potential lines in the input image.

The houghlines function finds the endpoints of the line segments corresponding to peaks in the Hough transform and it automatically fills in small gaps.

The following example shows how to use these functions to detect lines in an image.

  1. Read an image into the MATLAB workspace.
  2. For this example, rotate and crop the image.
  3. Find the edges in the image.
  4. Compute the Hough transform of the image using the hough function.
  5. Display the transform.
  6. Find the peaks in the Hough transform matrix, H, using the houghpeaks function.
  7. Plot the peaks.
  8. Find lines in the image.
  9. Create a plot that superimposes the lines on the original image.

Previous page  Tracing Boundaries Using Quadtree Decomposition Next page

© 1994-2005 The MathWorks, Inc.