Shape Detection
Shape Detection
(ME-4201)
Shape Detection
Shape Detection
Line detection
Shape Detection |2
Shape Detection
Line fitting
Given: Many ( xi , yi )pairs y
y = mx + c
Find: Parameters (m, c) ( xi , yi )
y= i
i
x= i
i
( x − x) i
2
N N i
Shape Detection |3
Shape Detection
Line fitting
y
1
E=
N
(
i
− xi cos + yi sin ) 2
y = f ( x) = ax3 + bx 2 + cx + d
that best fits the given points ( xi , yi )
Minimize:
x
1
i − + + +
3 2 2
[ y ( axi bxi cxi d )]
N i
Using: E E E E
=0 , =0 , =0 , =0
a b c d
Shape Detection |5
Shape Detection
Circle fitting
Find Circle:
Using:
𝜕𝐸 𝜕𝐸 𝜕𝐸
= 0, = 0, =0
𝜕𝑎 𝜕𝑏 𝜕𝑟
Shape Detection |6
Shape Detection
Detection?
Shape Detection |7
Hough Transform
Parameter space and voting
y = mx + c y
Equation of Line: y = mx + c
Find: (m, c)
Consider point: ( xi , yi ) ( xi , yi )
x
Image Space
yi = mxi + c or c = − xi m + yi
m
Parameter space also called Hough Space
(m, c)
c
Shape Detection |8
Hough Transform
Parameter space and voting
• A point can belong to many lines.
• If there is a line crosses many points, that is the line we are looking for.
c
Shape Detection |9
Hough Transform
Hough Line fitting y
Algorithm:
Here 0 2
0 max
Given points ( xi , yi ) find ( , ) ?
Horizontal axis is θ,
vertical is rho.
Shape Detection |12
Hough Transform
Hough Line fitting
Image votes
space
Image votes
space
( xi − a) 2 + ( yi − b) 2 = r 2
Equation of Circle:
( xi − a) 2 + ( yi − b) 2 = r 2
Edge Location ( xi , yi )
Edge Direction i
a = x − r cos
b = y − r sin
xc = xi + rki cos ki
yc = yi + rki sin ki
Increment Accumulator: A( xc , yc ) = A( xc , yc ) + 1
Find Local Maxima in A( xc , yc )
Shape Detection |22
Hough Transform
General Hough Transform