Main Content

Hough transform

`[`

computes the Standard
Hough Transform (SHT) of the binary image `H`

,`theta`

,`rho`

]
= hough(`BW`

)`BW`

.
The `hough`

function is designed to detect lines.
The function uses the parametric representation of a line: ```
rho
= x*cos(theta) + y*sin(theta)
```

. The function returns `rho`

,
the distance from the origin to the line along a vector perpendicular
to the line, and `theta`

, the angle in degrees
between the *x*-axis and this vector. The function
also returns the Standard Hough Transform, `H`

,
which is a parameter space matrix whose rows and columns correspond
to *rho* and *theta* values respectively.
For more information, see Algorithms.

The Standard Hough Transform (SHT) uses the parametric representation of a line:

rho = x*cos(theta) + y*sin(theta)

The variable *rho* is the distance from the
origin to the line along a vector perpendicular to the line. *theta* is
the angle of the perpendicular projection from the origin to the line
measured in degrees clockwise from the positive *x*-axis.
The range of *theta* is $$-90\xb0\le \theta <90\xb0$$. The angle of the line itself
is $$\theta +90\xb0$$, also measured clockwise with
respect to the positive *x*-axis.

The SHT is a parameter space matrix whose rows and columns correspond
to *rho* and *theta* values
respectively. The elements in the SHT represent accumulator cells.
Initially, the value in each cell is zero. Then, for every non-background
point in the image, *rho* is calculated for every *theta*. *rho* is
rounded off to the nearest allowed row in SHT. That accumulator cell
is incremented. At the end of this procedure, a value of *Q* in *SHT(r,c)* means
that *Q* points in the *xy*-plane
lie on the line specified by *theta(c)* and *rho(r)*.
Peak values in the SHT represent potential lines in the input image.

The Hough transform matrix, `H`

, is *nrho*-by-*ntheta* where:

`nrho = 2*(ceil(D/RhoResolution)) + 1`

, and

`D = sqrt((numRowsInBW - 1)^2 + (numColsInBW - 1)^2)`

.

`rho`

values range from `-diagonal`

to `diagonal`

,
where

`diagonal = RhoResolution*ceil(D/RhoResolution)`

.

`ntheta = length(theta)`