1 of 24

Hough Transform

CS 663, Ajit Rajwade

2 of 24

What is the Hough Transform?

  • A method to detect the presence of different types of shapes in an image – eg. Lines, circles, ellipses, polygons etc.
  • Used for detection of important features in images- eg: roads or buildings in satellite imagery or photos, biological cells in microscope images.

3 of 24

4 of 24

Beyond edge detection

  • The output of edge detectors can be noisy and yield outputs with missing points, and it is often difficult to group edges to isolate specific shapes such as lines, circles or ellipses.

5 of 24

Hough transform for line detection: big picture

  • Perform edge detection on the image using (say) Canny’s algorithm.

  • Every significant edge point casts one vote for every line on which it could potentially lie.

  • The lines which get maximum votes are the winners and can be marked out prominently.

  • The crux is: how do you represent a line?

6 of 24

7 of 24

Hough transform for line detection

  • Consider a point (xi,yi) in (x,y) space.
  • A line passing through this point can be represented as yi = axi + b (slope-intercept form). The line is parameterized by (a,b).
  • There are infinitely many lines passing through the point (xi,yi), and each of them will satisfy yi = axi + b for some value of (a,b). Thus a line becomes a point in the (a,b) space.
  • The (a,b) space is called the parameter space.

8 of 24

Hough transform for line detection

  • The set of all lines passing through (xi,yi) will constitute a single line in parameter space.
  • The set of all lines passing through some other point (xj,yj) will constitute another line in parameter space.
  • If the point (xj,yj) also satisfies yj = axj + b, then the respective lines for these points in parameter space will intersect at the point (a,b) in parameter space.

9 of 24

10 of 24

Hough transform for line detection

  • There is a problem with the slope intercept representation for a line – the slope is infinity for vertical lines, and hence a can take values that range from –∞ to +∞.
  • It is more convenient to use the normal representation, i.e. the form x cos Ѳ + y sin Ѳ = ρ.
  • The value of Ѳ is the angle made by a line perpendicular to the original w.r.t. the X axis, and ranges from -90 to +90 degrees.
  • The value of ρ is the perpendicular distance from the origin onto the line, and it ranges from 0 to the length of the largest diagonal in the image (why?).

11 of 24

Hough transform for line detection

  • The parameter space for the line has changed from (m,c) to (ρ,Ѳ). A single point in the XY space corresponds to a sinusoid in this parameter space.
  • The line joining two points in XY space is represented by a point obtained from the intersection of their corresponding two sinusoids in the parameter space.

12 of 24

13 of 24

14 of 24

Hough transform for line detection: algorithm

  • We will divide the entire (ρ,Ѳ) space into bins - also called accumulator cells, which form a 2D array A.

  • Perform edge detection on the image using (say) Canny’s algorithm.

  • For every edge point (xk,yk) in the XY space, and for every value of Ѳ ranging from -90 to +90, compute the corresponding value of ρ, using the fact that ρ = xkcos Ѳ+yksin Ѳ, and approximate it to the closest allowed cell value in (ρ,Ѳ) space.

  • If some angle Ѳa yields a solution ρa then increment the frequency count A(Ѳaa) by 1 (this is called as “voting”).

  • At the end, the value in A(Ѳaa) indicates the number of edge points that (approximately) satisfied the equation x cos Ѳa + y sin Ѳa = ρa.

15 of 24

Hough transform for line detection: algorithm

  • Pick those lines (i.e. cells in the parameter space) which have maximum number of votes.
  • Mark out those lines in the original image.
  • Note: Any single point votes for many lines, but lines corresponding to actual structures in the image will receive votes from many points. Votes for the other lines (i.e. not corresponding to prominent structures) will get scattered.

16 of 24

17 of 24

18 of 24

19 of 24

Speed-up heuristic

  • For every edge point, we know the edge direction Ѳ’ (perpendicular to the gradient at that point).
  • We can therefore constrain that an edge point is allowed to vote for only those accumulator cells corresponding to (say) Ѳ’-K≤ Ѳ ≤ Ѳ’+K where K is around 20 degrees.

20 of 24

Hough transform for circles

  • A circle is represented by the equation

(x-a)2 + (y-b)2 = r2.

  • For circle detection, there are 3 parameters (a,b,r), so the parameter space is 3-dimensional.
  • For every edge point in an image, for every reasonable value of r and a, compute the possible values of b. Increment the appropriate accumulator cell (a,b,r) just as before.

21 of 24

22 of 24

Hough transform for ellipses

  • An axis parallel ellipse is given by
  • The parameter space is 4-D.
  • In addition, if the major axis is oriented at some angle Ѳ w.r.t. X axis, the parameter space becomes 5D.

23 of 24

Hough transform: pros

  • It can handled cases where pixels lying on the same line have gaps in between them due to noise or occlusions.

24 of 24

Hough transform: cons

  • It considers a line to be of infinite extent – you will have to be careful while marking out the final line segments in the image.

  • If the resolution of the parameter grid is too coarse, potentially different curves could fall into the same bin. If the resolution is too fine, the votes of different points lying close to the same curve will get bifurcated and you may miss some significant structures. In the latter case, the problem is worsened by noise.

  • Computational complexity is exponential in the number of parameters (why?).