Documentation

This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

vision.HoughTransform System object

Package: vision

Find lines in images via Hough transform

Description

 Note:   The `vision.HoughTransform` System object will be removed in a future release. Use the `hough` function with equivalent functionality instead.

The `HoughTransform` object finds lines in images via Hough transform. The Hough transform maps points in the Cartesian image space to curves in the Hough parameter space using the following equation:

`$rho=x*\mathrm{cos}\left(theta\right)+y*\mathrm{sin}\left(theta\right)$`

Here, $rho$ denotes the distance from the origin to the line along a vector perpendicular to the line, and $theta$ denotes the angle between the x-axis and this vector. This object computes the parameter space matrix, whose rows and columns correspond to the rho and theta values respectively. Peak values in this matrix represent potential straight lines in the input image.

 Note:   Starting in R2016b, instead of using the `step` method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, ```y = step(obj,x)``` and `y = obj(x)` perform equivalent operations.

Construction

`H = vision.HoughTransform` returns a Hough transform System object, `H`, that implements the Hough transform to detect lines in images.

`H = vision.HoughTransform(Name,Value)` returns a Hough transform 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`).

```H = vision.HoughTransform(THETARES, RHORES,'Name',Value,...)``` returns a Hough transform object, `H`, with the `ThetaResolution` property set to `THETARES`, the `RhoResolution` property set to `RHORES`, and other specified properties set to the specified values.

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

Properties

 `ThetaResolution` Theta resolution in radians Specify the spacing of the Hough transform bins along the theta-axis in radians, as a scalar numeric value between `0` and `pi/2`. The default is `pi/180`. `RhoResolution` Rho resolution Specify the spacing of the Hough transform bins along the rho-axis as a scalar numeric value greater than `0`. The default is `1`. `ThetaRhoOutputPort` Enable theta and rho outputs Set this property to `true` for the object to output theta and rho values. The default is `false`. `OutputDataType` Data type of output Specify the data type of the output signal as `double`, `single`, or `Fixed point`. The default is `double`.

Methods

 clone Create Hough transform 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 parameter space matrix for binary input image matrix

Examples

expand all

``` 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]); ```

Algorithms

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