Assume we have some data points in an image which are perhaps the result of an edge detection process, or boundary points of a binary blob. We wish to recognise the points that form a straight line.

Consider a point (

*y* = *ax* + *b*.

*y*_{i} = *ax*_{i} + *b*

We can rewrite this equation as

*b* = -*x*_{i}*a* + *y*_{i},

If we divide parameter space into a number of discrete accumulator cells we can collect `votes' in

However, we have a problem with using

An alternative representation of a line is given by

where

As before, peaks in the accumulator array mark the equations of significant lines.

In theory any kind of curve can be detected if you can express it as a function of the form

For example a circle can be represented as

(*x* - *a*)^{2} + (*y* - *b*)^{2} - *r ^{2}*
= 0.

One powerful global method for detecting edges is called the

Let us suppose that we are looking for straight lines in an image.

If we take a point (

for varying values of

However, this equation can also be written as

where we now consider

This is a straight line on a graph of

Each different

Now consider two pixels

- For each pixel, all of the possible lines through it are represented by a single
line in (
*m*,*c*) space. - Thus the single line in (
*x*,*y*) space which goes through both pixels lies on the intersection of the two lines representing*p*and*q*in (*m*,*c*) space, as illustrated by Fig. 32.

Taking this one step further,

**All**pixels which lie on the same line in (*x*,*y*) space are represented by lines which all pass through a single point in (*m*,*c*) space.- The single point through which they all pass gives the values of
*m*and*c*in the equation of the line*y*=*mx*+*c*.

To detect straight lines in an image, we do:

- Quantise (
*m*,*c*) space into a two-dimensional array*A*for appropriate steps of*m*and*c*. - Initialise all elements of
*A*(*m*,*c*) to zero. - For each pixel (
*x*',*y*') which lies on some edge in the image, we add 1 to all elements of*A*(*m*,*c*) whose indices*m*and*c*satisfy*y*'=*mx*'+*c*. - Search for elements of
*A*(*m*,*c*) which have large values -- Each one found corresponds to a line in the original image.

One useful property of the Hough transform is that the pixels which lie on the line need not all be contiguous.

For example, all of the pixels lying on the two dotted lines in Fig. 33 will be recognised as lying on the same straight line. This can be very useful when trying to detect lines with short breaks in them due to noise, or when objects are partially occluded as shown.

On the other hand, it can also give misleading results when objects happen to be aligned by chance, as shown by the two dotted lines in Fig. 34.

Indeed, this clearly shows that one disadvantage of the Hough transform method is that it gives an

One practical detail is that the

To avoid this problem, it is better to use the alternative formulation given earlier,

as a means of describing straight lines.

Note, however, that a point in (

Otherwise, the method is unchanged.

The Hough transform can be used to detect other shapes in an image as well as straight lines.

For example, if we wish to find circles, with equation

Now:

- Every point in (
*x*,*y*) space corresponds to a surface in (*a*,*b*,*r*) space (as we can vary any two of*a*,*b*and*r*, but the third is determined by Eqn. 53). - The basic method is, thus, modified to use a three-dimensional array
*A*(*a*,*b*,*r*), - All points in it which satisfy the equation for a circle are incremented.

In practice, the technique takes rapidly increasing amounts of time for more complicated curves as the number of variables (and hence the number of dimensions of

So the method is really only of use for simple curves.