Hough Transform

The purpose of Hough Transform is to find imperfect instances of objects within a certain class of shapes by a voting procedure. This voting procedure is carried out in a parameter spacearrow-up-right, from which object candidates are obtained as local maxima in a so-called accumulator space that is explicitly constructed by the algorithm for computing the Hough transform. -- Wikipedia

Linear Hough Transform

In short, hough transform detects edge line inside the image. How to do that?

Basic idea: We have a list of points after edge filter. For each point, we draw out all lines that pass through it and repeat this procedure for all points. Thus, the line all points have in commin determines an edge.

We make use of Hough/parameter space to find these lines. Consider a edge point (xi,yi)(x_i, y_i), we denote a line equation yi=mxi+cy_i=mx_i+c in image space. We can also write it in a different way: c=xim+yic=-x_im+y_i in Hough space. Thus, a line in image space is transformed into a point in Hough space.

Image adapted from Medium.com

Thus, we realize that for the line that pass (x1,y1),(x2,y2)(x_1,y_1), (x_2,y_2), we have c=x0m+y0,c=x1m+y1c=-x_0m+y_0, c=-x_1m+y_1, that is a point (m,c)(m,c) inside the hough space. So, how to find the most likely parameters (m,c)(m,c) for the line in image space?

  • Let each edge point in image space vote for a set of possible parameters in Hough space

  • Accumulate votes in discrete set of bins; parameters with the most votes indicate line in image space.

circle-info

However, usual parameter space (m,c) can take on infinite values, undefined for vertical edge lines, and it is difficult to implement. Thus, for computational efficiency, we use the Hesse normal formarrow-up-right: r=xcos(θ)+ysin(θ)r= xcos(\theta)+ysin(\theta)

pseudocode

  1. Use a edge filter on top of the image to find all edge points

  2. Create accumulator array A(θ,r)=0,θ,rA(\theta,r)=0, \forall \theta,r

  3. Check each pixel to see if it is a edge points or not

  4. If edge point, construct the set of lines pass this point (θ\theta=-90:90, compute correspond rr)

    1. A(θ,r)=A(θ,r)+1A(\theta,r)=A(\theta,r)+1

  5. Repeat for the rest of points

  6. Find local maxima in A(θ,r)A(\theta,r)

Left: original image; Right: Image after edge detector
Linear Hough Transform Result

Circle Hough Transform

Instead of constructing lines through each edge pixel, we construct circles centered at these points. If a correct radius rr is chosen, the constructed circles will overlap at the center of the circle we want to identify. Thus, this time the accumulator matrix has 3 dimensions: r,x,yr,x,y.

  1. Use a edge filter on top of the image to find all edge points

  2. Create accumulator matrix A=zeros([size(img),#radius])

  3. For each edge (x,y)

    1. For each radius r=r1,r2,...r=r_1, r_2,...

      1. For each θ=0,...,360\theta=0,...,360

        1. Calculate the candidate center point (x,y)=(x+rcos(θ),y+rsin(θ))(x',y')=(x+rcos(\theta), y+rsin(\theta))

        2. A(x,y,r)=A(x,y,r)+1A(x',y',r)=A(x',y',r)+1

Find the radius with largest length and that's the winning radius.

Last updated