Perform the Hough transform for lines or circles.
The method argument chooses between the Hough transform for lines and circles. It can be either "line" (default) or "circle".
Line Detection
If method is "line", the function will compute the Hough transform for lines. A line is parametrised in r and theta as
r = x*cos(theta) + y*sin(theta),
where r is distance between the line and the origin, while theta
is the angle of the vector from the origin to this closest point. The result
H is an N by M matrix containing the Hough transform. Here,
N is the number different values of r that has been attempted.
This is computed as 2*diag_length - 1
, where diag_length
is
the length of the diagonal of the input image. M is the number of
different values of theta. These can be set through the third input
argument arg. This must be a vector of real numbers, and is by default
pi*(-90:90)/180
.
Circle Detection
If method is "circle" the function will compute the Hough transform for circles. The circles are parametrised in r which denotes the radius of the circle. The third input argument arg must be a real vector containing the possible values of r. If the input image is N by M, then the result H will be an N by M by K array, where K denotes the number of different values of r.
As an example, the following shows how to compute the Hough transform for circles with radius 3 or 7 in the image im
bw = edge(im); H = houghtf(bw, "circle", [3, 7]);
Here H will be an NxMx2 array, where H(:,:,1) will contain the
Hough transform for circles with radius 3, and H(:,:,2) for radius 7.
To find good circles you now need to find local maximas in H. If you
find a local maxima in H(row, col, 1) it means that a good circle exists
with center (row,col) and radius 3. One way to locate maximas is to use the
immaximas
function.
See also: hough_line, hough_circle, immaximas.
Package: image