Function File: [H, theta, rho] = hough (BW)
Function File: [H, theta, rho] = hough (BW, property, value, …)

Compute the Hough transform to find lines in a binary image.

The resulting Hough transform matrix H (accumulator array) is 2D. Its rows correspond to the distance values rho and its columns to the angle values theta. Points of high value in H correspond to present lines in the given image.

The distance rho is measured with respect to the image origin. The angle theta is measured clockwise to the vertical axis.

The following property values are possible:

"Theta"

A vector of angle values. The Hough transform will be calculated at those Theta angle values. The angles are given in degrees. Defaults to [-90:89].

"ThetaResolution"

A scalar value to specify the Theta angles for the Hough transform in a different way. This will result in Theta = [-90:ThetaResolution:90], with the +90° angle excluded.

See also: hough_line, hough_circle, immaximas.

Demonstration 1

The following code

 BW = zeros (100, 150);
 BW(30,:) = 1;
 BW(:, 65) = 1;
 BW(35:45, 35:50) = 1;
 for i = 1:90
   BW(i,i) = 1;
 endfor
 BW = imnoise (BW, "salt & pepper");
 figure ();
 imshow (BW);
 title ("BW");
 [H, theta, rho] = hough (BW);
 H /= max (H(:));
 figure ();
 imshow (H, "XData", theta, "YData", rho);
 title ("hough transform of BW");
 axis on;
 xlabel ("angle \\theta [degrees]");
 ylabel ("distance \\rho to origin [pixels]");

Produces the following figures

Figure 1 Figure 2

Package: image