|
Calling Sequence
|
|
HoughLine(img, d_rho, d_theta, threshold)
|
|
Parameters
|
|
img
|
-
|
Image
|
d_rho
|
-
|
algebraic , radial increment
|
d_theta
|
-
|
algebraic , angular increment in radian
|
threshold
|
-
|
posint , minimum number of points required to detect a line
|
|
|
|
|
Options
|
|
•
|
rhorange : list , contains minimum rho and maximum rho
|
•
|
thetarange : list , contains minimum theta and maximum theta
|
|
|
Description
|
|
•
|
The HoughLine command detects the lines in img, and returns the detected lines in an by Array, lines. A line given by the equation is represented by the pair of values . This pair then forms a row of lines. The equation takes the origin of the coordinate system to be at the top left corner of the image, contrary to e.g. the ImageTools[Draw] subpackage which takes the origin a the lower left corner. The value (in the first column) can be understood as the signed distance from the origin to the closest point on the line - the sign being negative if the line passes above the origin and positive otherwise. The value (in the second column) can be understood as the counterclockwise angle in radians of a normal to the line, starting from horizontal. By default, the values of are in the range to .
|
•
|
The implementation attempts to find such lines by varying and over a grid of values. The required arguments d_rho and d_theta specify the step size for and , respectively, in this grid. For each line, the implementation counts the number of nonblack pixels. If this is greater than threshold, the line is included in the result.
|
•
|
img should be a binary image, so calling EdgeDetect and Threshold are usually necessary before calling HoughLine.
|
•
|
The option rhorange specifies the range of , so only the lines with values in this range is returned. The default is from to .
|
•
|
The option thetarange specifies the range of , so only the lines with values in this range is returned. The default is to .
|
|
|
Examples
|
|
>
|
|
>
|
|
>
|
|
>
|
DrawLine := proc(img, line)
local i, nRows, nCols, rho, theta, pixel, ctheta, stheta,
xMid, yMid, x1, y1, x2, y2;
nRows := upperbound(img, 1);
nCols := upperbound(img, 2);
pixel := evalf('sqrt'(nRows^2 + nCols^2));
for i to upperbound(line, 1) do
rho := line[i, 1];
theta := line[i, 2];
ctheta := cos(theta);
stheta := sin(theta);
xMid := rho * ctheta;
yMid := rho * stheta;
x1 := xMid + pixel * (-stheta);
y1 := yMid + pixel * ctheta;
x2 := xMid - pixel * (-stheta);
y2 := yMid - pixel * ctheta;
Draw:-Line(img, x1, nRows - y1, x2, nRows - y2, [255, 0, 0]):
end do;
end proc:
|
>
|
|
|
|
Compatibility
|
|
•
|
The ImageTools[HoughLine] command was introduced in Maple 2020.
|
|
|
|