✨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 space, 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), we denote a line equation yi=mxi+c in image space. We can also write it in a different way: c=−xim+yi in Hough space. Thus, a line in image space is transformed into a point in Hough space.

Thus, we realize that for the line that pass (x1,y1),(x2,y2), we have c=−x0m+y0,c=−x1m+y1, that is a point (m,c) inside the hough space. So, how to find the most likely parameters (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.
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 form: r=xcos(θ)+ysin(θ)
pseudocode
Use a edge filter on top of the image to find all edge points
Create accumulator array A(θ,r)=0,∀θ,r
Check each pixel to see if it is a edge points or not
If edge point, construct the set of lines pass this point (θ=-90:90, compute correspond r)
A(θ,r)=A(θ,r)+1
Repeat for the rest of points
Find local maxima in A(θ,r)


Circle Hough Transform
Instead of constructing lines through each edge pixel, we construct circles centered at these points. If a correct radius r 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,y.
Use a edge filter on top of the image to find all edge points
Create accumulator matrix A=zeros([size(img),#radius])
For each edge (x,y)
For each radius r=r1,r2,...
For each θ=0,...,360
Calculate the candidate center point (x′,y′)=(x+rcos(θ),y+rsin(θ))
A(x′,y′,r)=A(x′,y′,r)+1
Find the radius with largest length and that's the winning radius.
Last updated