HoughLine - Maple Help

ImageTools

 HoughLine
 detect lines using Hough Transform

 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 $m$ by $2$ Array, lines. A line given by the equation $\mathrm{\rho }=x\mathrm{cos}\left(\mathrm{\theta }\right)+y\mathrm{sin}\left(\mathrm{\theta }\right)$ is represented by the pair of values $\left(\mathrm{\rho },\mathrm{\theta }\right)$. 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 $\mathrm{\rho }$ (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 $\mathrm{\theta }$ (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 $\mathrm{\theta }$ are in the range $0$ to $\mathrm{\pi }$.
 • The implementation attempts to find such lines by varying $\mathrm{\rho }$ and $\mathrm{\theta }$ over a grid of values. The required arguments d_rho and d_theta specify the step size for $\mathrm{\rho }$ and $\mathrm{\theta }$, 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 $\mathrm{\rho }$, so only the lines with $\mathrm{\rho }$ values in this range is returned. The default is from $-\mathrm{upperbound}\left(\mathrm{img},1\right)-\mathrm{upperbound}\left(\mathrm{img},2\right)$ to $\mathrm{upperbound}\left(\mathrm{img},1\right)+\mathrm{upperbound}\left(\mathrm{img},2\right)$.
 • The option thetarange specifies the range of $\mathrm{\theta }$, so only the lines with $\mathrm{\theta }$ values in this range is returned. The default is $0$ to $\mathrm{\pi }$.

Examples

 > $\mathrm{with}\left(\mathrm{ImageTools}\right):$
 > $\mathrm{img}≔\mathrm{Read}\left(\mathrm{cat}\left(\mathrm{kernelopts}\left(\mathrm{datadir}\right),"/images/Maplesoft.png"\right)\right)$
 ${{\mathrm{_rtable}}}_{{36893628729988960492}}$ (5.1)
 > $\mathrm{edge}≔\mathrm{Threshold}\left(\mathrm{EdgeDetect}\left(\mathrm{img}\right),1.5\right)$
 ${{\mathrm{_rtable}}}_{{36893628729851154292}}$ (5.2)
 > $\mathrm{Embed}\left(\mathrm{edge}\right)$

 > $\mathrm{line}≔\mathrm{HoughLine}\left(\mathrm{edge},1,\frac{\mathrm{\pi }}{180},250\right)$
 ${{\mathrm{_rtable}}}_{{36893628729851135388}}$ (5.3)
 > 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:
 > $\mathrm{DrawLine}\left(\mathrm{img},\mathrm{line}\right)$
 > $\mathrm{Embed}\left(\mathrm{img}\right)$

Compatibility

 • The ImageTools[HoughLine] command was introduced in Maple 2020.