HoughLine - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


ImageTools

  

HoughLine

  

detect lines using Hough Transform

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

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 ρ=xcosθ+ysinθ 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 upperboundimg,1upperboundimg,2 to upperboundimg,1+upperboundimg,2.

• 

The option thetarange specifies the range of θ, so only the lines with θ values in this range is returned. The default is 0 to π.

Examples

withImageTools:

imgReadcatkerneloptsdatadir,/images/Maplesoft.png

edgeThresholdEdgeDetectimg,1.5

Embededge

lineHoughLineedge,1,π180,250

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:

DrawLineimg,line

Embedimg

Compatibility

• 

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

• 

For more information on Maple 2020 changes, see Updates in Maple 2020.

See Also

ImageTools[Draw][Line]

ImageTools[ProbabilisticHoughLine]