Image Processing Toolbox User's Guide  hough

Hough transform

Syntax

• [H, theta, rho] = hough(bw)


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.

 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

Notes

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

houghpeaks, houghlines