Image Processing Toolbox User's Guide |
Syntax
Description
[H, theta, rho] = hough(BW)
computes the Standard Hough Transform (SHT) of the binary image BW. You can use the hough
function to detect lines in an image. The function returns H, the Hough transform matrix. theta
(in degrees) and rho
are the arrays of rho
and theta
values over which the Hough transform matrix was generated.
[H, theta, rho] = hough(BW,param1,val1,param2,val2)
specifies parameter/value pairs, listed in the following table. Parameter names can be abbreviated, and case does not matter.
Notes
The hough
function implements the Standard Hough Transform (SHT). The SHT uses 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 rho
and theta
values respectively. Peak values in this space represent potential lines in the input image.
The Hough transform matrix, H
, is NRHO-by-NTHETA where NRHO = 2*ceil(norm(size(BW))/RhoResolution)-1
, and NTHETA = 2*ceil(90/ThetaResolution)
. Theta angle values are in the range [-90, 90) degrees and rho values range from -DIAGONAL to DIAGONAL where DIAGONAL = RhoResolution*ceil(norm(size(BW))/RhoResolution). Note that if 90/DTHETA is not an integer, the actual angle spacing will be 90/ceil(90/DTHETA).
Class Support
BW
can be logical or numeric and it must be real, 2-D, and nonsparse.
Example
Compute and display the Hough transform of an image
RGB = imread('gantrycrane.png'); I = rgb2gray(RGB); % convert to intensity BW = edge(I,'canny'); % extract edges [H,T,R] = hough(BW,'RhoResolution',0.5,'ThetaResolution',0.5); % display the original image subplot(2,1,1); imshow(RGB); title('gantrycrane.png'); % display the hough matrix subplot(2,1,2); imshow(imadjust(mat2gray(H)),'XData',T,'YData',R,... 'InitialMagnification','fit'); title('Hough transform of gantrycrane.png'); xlabel('\theta'), ylabel('\rho'); axis on, axis normal, hold on; colormap(hot);
See also
histeq | houghlines |
© 1994-2005 The MathWorks, Inc.