vision.HoughLines System object

Package: vision

Find Cartesian coordinates of lines that are described by rho and theta pairs


The HoughLines object finds Cartesian coordinates of lines that are described by rho and theta pairs. The object inputs are the theta and rho values of lines and a reference image. The object outputs the one-based row and column positions of the intersections between the lines and two of the reference image boundary lines. The boundary lines are the left and right vertical boundaries and the top and bottom horizontal boundaries of the reference image.


H = vision.HoughLines returns a Hough lines System object, H, that finds Cartesian coordinates of lines that are described by rho and theta pairs.

H = vision.HoughLines(Name,Value) returns a Hough lines object, H, with each specified property set to the specified value. You can specify additional name-value pair arguments in any order as (Name1, Value1,...,NameN,ValueN).

Code Generation Support
Supports MATLAB® Function block: Yes
System Objects in MATLAB Code Generation.
Code Generation Support, Usage Notes, and Limitations.



Method to calculate sine values used to find intersections of lines

Specify how to calculate sine values which are used to find intersection of lines as Trigonometric function, or Table lookup. If this property is set to Trigonometric function, the object computes sine and cosine values it needs to calculate the intersections of the lines. If it is set to Table lookup, the object computes and stores the trigonometric values it needs to calculate the intersections of the lines in a table and uses the table for each step call. In this case, the object requires extra memory. For floating-point inputs, this property must be set to Trigonometric function. For fixed-point inputs, the property must be set to Table lookup. The default is Table lookup.


Spacing of the theta-axis

Specify the spacing of the theta-axis. This property applies when you set the SineComputation property to Table lookup.

 Fixed-Point Properties


cloneCreate hough lines object with same property values
getNumInputsNumber of expected inputs to step method
getNumOutputsNumber of outputs from step method
isLockedLocked status for input attributes and nontunable properties
release Allow property value and input characteristics changes
stepOutput intersection coordinates of a line described by a theta and rho pair and reference image boundary lines


expand all

Detect Longest Line In An Image

Read the intensity image.

    I = imread('circuit.tif');

Create an edge detector, Hough transform, local maxima finder, and Hough lines objects.

    hedge = vision.EdgeDetector;
    hhoughtrans = vision.HoughTransform(pi/360,'ThetaRhoOutputPort', true);
    hfindmax = vision.LocalMaximaFinder(1,	'HoughMatrixInput', true);
    hhoughlines = vision.HoughLines('SineComputation','Trigonometric function');

Find the edges in the intensity image

 	BW = step(hedge, I);

Run the edge output through the transform

	[ht, theta, rho] = step(hhoughtrans, BW);

Find the location of the max value in the Hough matrix.

 	idx = step(hfindmax, ht);

Find the longest line.

 	linepts = step(hhoughlines, theta(idx(1)-1), rho(idx(2)-1), I);

View the image superimposed with the longest line.

   imshow(I); hold on;
   line(linepts([1 3])-1, linepts([2 4])-1,'color',[1 1 0]);


This object implements the algorithm, inputs, and outputs described on the Hough Lines block reference page. The object properties correspond to the block parameters.

Was this topic helpful?