detect lines using Hough Transform
HoughLine(img, d_rho, d_theta, threshold)
algebraic , radial increment
algebraic , angular increment in radian
posint , minimum number of points required to detect a line
rhorange : list , contains minimum rho and maximum rho
thetarange : list , contains minimum theta and maximum theta
The HoughLine command detects the lines in img, and returns the detected lines in an m by 2 Array, lines. A line given by the equation ρ=x⁢cos⁡θ+y⁢sin⁡θ 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 0 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 −upperbound⁡img,1−upperbound⁡img,2 to upperbound⁡img,1+upperbound⁡img,2.
The option thetarange specifies the range of θ, so only the lines with θ values in this range is returned. The default is 0 to π.
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]):
The ImageTools[HoughLine] command was introduced in Maple 2020.
For more information on Maple 2020 changes, see Updates in Maple 2020.
Download Help Document
What kind of issue would you like to report? (Optional)