| Image Processing Toolbox™ | ![]() |
[H, theta, rho] = hough(BW)
[H, theta, rho] = hough(BW, param1,
val1, param2, val2)
[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.
Parameter | Description |
|---|---|
'ThetaResolution' | Real scalar value between 0 and 90, exclusive, that specifies the spacing (in degrees) of the Hough transform bins along the theta axis. Default: 1. |
'RhoResolution' | Real scalar value between 0 and norm(size(BW)), exclusive, that specifies the spacing of the Hough transform bins along the rho axis. Default: 1 |
The hough function implements the Standard Hough Transform (SHT). The SHT uses the parametric representation of a line:
rho = x*cos(theta) + y*sin(theta)
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 SHT is a parameter space matrix whose rows and columns correspond to rho and theta values respectively. The elements in the SHT represent accumulator cells. Initially, each cell is set to zero. Then, for every nonbackground point in the image, rho is calculated for every theta. Rho is rounded off to the nearest allowed row in SHT. That accumulator cell is incremented. At the end of this procedure, a value of Q in SHT(r,c) means that Q points in the XY plane lie on the line specified by the theta(c) and rho(r). Peak values in the SHT represent potential lines in the input image.
The Hough transform matrix, H, is NRHO-by-NTHETA.
| NRHO = 2*ceil(norm(size(BW))/RhoResolution)-1 where D = sqrt((numRowsColsInBW - 1)^2 + (numColsInBW - 1)^2). RHO values range from -DIAGONAL to DIAGONAL where DIAGONAL = RhoResolution*ceil(D)/RhoResolution). |
| NTHETA = 2*ceil(90/ThetaResolution) where Theta angle values are in the range [-90, 90) degrees. If 90/ThetaResolution is not an integer, the actual angle spacing will be 90/ceil(90/ThetaResolution) |
BW can be logical or numeric and it must be real, 2-D, and nonsparse.
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);![]() | histeq | houghlines | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |