Find Cartesian coordinates of lines that are described by rho and theta pairs
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( 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 (
|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
Spacing of the theta-axis
Specify the spacing of the theta-axis. This property applies
when you set the
|clone||Create hough lines object with same property values|
|getNumInputs||Number of expected inputs to step method|
|getNumOutputs||Number of outputs from step method|
|isLocked||Locked status for input attributes and nontunable properties|
|release||Allow property value and input characteristics changes|
|step||Output intersection coordinates of a line described by a theta and rho pair and reference image boundary lines|
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');
Warning: The vision.EdgeDetector will be removed in a future release. Use the edge function with equivalent functionality instead. Warning: The vision.HoughTransform will be removed in a future release. Use the hough function with equivalent functionality instead.
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.