Image Processing Workshop Session 2 – Hough Transformation Ashay Tejwani
Image Processing Workshop
Session 2 – Hough TransformationAshay Tejwani
Video ProcessingIn the last session we saw that an image can
be represented by an array of RGB values.
In video processing we:Break down the video into separate framesExtract each image as an arraySimply apply the relevant image processing
techniques.
Hough Transform
Why do we need it?Consider assessing this image:
So what does it do?Useful for detecting Parametric curves (such
as lines, circles, conics).Relatively unaffected by:
GapsNoise
How does it Work?The theory behind Hough Transform
An ExampleUsing Edge Detection Algorithm
1 2
4
5
3
An ExampleLet us consider a coordinate system
1 2
4
5
3
X
Y
Represent all lines in terms of R and Theta
Convention
4
5
X
Y1 2
3
ProcedureSelect one point at
a time, and consider all the combinations of R and Theta for which the line would pass through the given point.
4
5
X
Y1 2
3
LimitsBefore we start off, we
need to set a limit to the max and min values of R and Theta.
Min R=0,Max R= image diagonal
Min Theta=-90Max Theta=+904
5
X
Y1 2
3
(142,142)
(0,100)
An ExampleR=Xcos(Θ) + Y
sin(Θ)
For point 1, all lines will have R=0
4
5
X
Y1 2
3
(142,142)
(0,100)
An ExampleFor Point 2,
R=100, Theta=0R=70.7, Theta=45
For Point 3,R=100, Theta=90R=70.7, Theta=45
Plotting these in the 2-D array:
4
5
X
Y1 2
3
(142,142)
(0,100)
Plotting acceptable R- Θ pairs
R
The t a
Rmax
ThetamaxThetamin
Rmin
ResultThe points of intersection of these plots give
us a value of R and Θ. These R and Θ represent the lines passing
through the two points.
How to Code this?Open CV style
The logic- Voting!We create a 2-D matrix of all possible R and
Θ values.For each edge point you detect, consider all
the valid values of R and Θ.Increment the element of the array by 1 each
time it is valid for a point – Each point ‘votes’ for a valid line.
Which is equivalent to converting this into a matrix
R
The t a
Rmax
ThetamaxThetamin
Rmin
This matrix represents Hough SpaceTheta
R
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
2 1 1 1 2 1 1 1 1 2
0 1 0 1 0 0 0 0 1 0
0 0 2 0 0 0 0 1 0 0
1 1 0 1 0 0 1 0 0 0
0 0 0 0 1 1 0 0 0 0
ResultFrom this array, we find all local Maxima.These correspond to the pair of R- Θ of lines
which pass through the given group of points.
AlgorithmFor all X{
For all Y{ if(edge point at (x,y)){ for all theta{
R= x*cos(theta) + y*sin(theta);increment one to the cell in the matrix
corresponding to R, theta.End all loops
Practical usage
Thank you