Professional Documents
Culture Documents
Chapter5 Segmentation
Chapter5 Segmentation
Chapter5 Segmentation
Edge
dge detection
de ec o
I
Image segmentation
i
Corner detection
Introduction
Feature extraction
segmentation
Discontinuity
y Similarity
y
partition partition
similarities
discontinuities
R = ∑i =1Wi I i
W1 W2 W3
9
W4 W5 W6
W7 W8 W9
Gray level
Mask coefficient
1.1. Point detection
Measure of the weighted difference
-1 -1 -1 between the center point and its
neighbors
g
-1 8 -1
-1 -1 -1
HP filter
filt + threshold
th h ld
Point mask
2 2 2 -1 2 -1 -1 2 -1 -1 2 -1
-1
1 -1
1 -1
1 2 -1
1 -1
1 -1
1 2 -1
1 -1
1 -1
1 2
H +45° V -45°
Line masks
M
More generall : template
t l t matching
t hi
correlation between signal and filters (masks, forms)
1.3. Edge
g detection
Model :
e
h lenght
e ϑ h width
Roof edges
g
Effects of noise
Consider a single row or column of the
image
Plotting intensity as a function of position
gives a signal
Laplacian of Gaussian
operator
Where is the Z
Zero-crossings
i off
edge?
Example
p
Image
50
20
40
First
derivative
30
40 20
10
60
0
80 -10
-20
Sign
100
-30
position
120 -40
20
Second
15 derivative
200
10
180 5
0
160
-5
140
Position
P iti
-10
zero crossing
-15
120
-20
100
-25
0 20 40 60 80 100 120 140
0 20 40 60 80 100 120 140
Gradient
⎡∂∂ff ⎤
At position (x,y) of f(x,y) r ⎡Gx ⎤ ⎢ ∂x ⎥
∇f = ⎢ ⎥ = ∂f vector
⎣Gyy ⎦ ⎢ ∂y ⎥
⎢⎣ ⎥⎦
2 images
( )
r
magnitude ∇f = mag ∇f = Gx 2 + Gy 2 >0
or ∇f ≈ Gx + Gy for hardware 1 image
direction
α ( x, y ) = tan −1 (Gy Gx ) 1 image
100
100
150
150
200
200 X
250
50 100 150 200 250
250
50 100 150 200 250
50
50
100
100
Y
150
150
200
200
250
50 100 150 200 250 250
50 100 150 200 250
Implementation
p
* approximation
i ti ∂f ≈1 f ( x + 1, y ) −1 f ( x, y ) -1
∂x H1
1
∂f ≈1 f (x, y + 1) − 1 f ( x, y )
∂y -1 1 H2
Other possibilities
* filtering f ⊗ H1 ⎫
⎬→ ( f ⊗ H1 )2 + ( f ⊗ H 2 )2
f ⊗ H2 ⎭
0 -1 -1 0
2x2 filters
H1 H2 Roberts
1 0 0 1
3x3 filters -1
1 -c -1
1
-1 0 1
H1 -cc 0 c 0 0 0
H2
-1 0 1 1 c 1
C=1 Prewitt
C=1
C=2
C=2 Sobel
Mean = 0
Gradient template
p
Simple, general
noise sensitivity
threshold problem
T1
|G(I)| T2
T1 -->
--> only one edge
T2 --
-->> two edges but edge 1 is large
See also zero crossing
Algorithm
g
4° edge linking
sensibility to noise
choice of t
thickness of egdes
2 filters!
Laplacian
p
1 filter !
0 -1
1 0 ΣCoefs=
C f 0 HP
Coefs=0
-1 4 -1
0 -1
1 -0
0
Laplacian
p
Properties
easy to implement
S ( x, y ) = ∇ 2 [G ( x, y ) ⊗ F ( x, y )]
edges : thickness = 1 pixel
robust
Gaussian filter Input image
detect every change of intensity
Improvement
Laplacian of 2D Gaussian function
Laplacian
p of ggaussian
S ( x, y ) = ∇ [G ( x, y ) ∗ f ( x, y )]
Using the properties
2
⎛ x2 + y2 ⎞
G ( x, y ) = exp⎜⎜ − ⎟⎟
⎝ σ 2
⎠ 1
σ=2
r −σ
2 2
⎛ r ⎞
2
∇ G=
2
p⎜⎜ − 2 ⎟⎟
exp
σ ⎝ 2σ ⎠
0.5
2
0
r
S ( x, y ) = ∇ G ∗ f ( x, y )
2
-0.5
-10 -8 -6 -4 -2 0 2 4 6 8 10
Image Segmentation
Image Segmentation
Comparison
p
Cannyy edge
g detector
Principle
Image features:
Edge detection:
1-Good Detection: it must minimize the probability of false positives as well as false
negatives . So it is the ability to locate and mark all real edges.
2-Good Localization: The edges detected must be as close as possible to the true edges.
So we have to obtain minimal distance between the detected edge and real edge.
edge
g Response
3-Single p or clear response:
p The detector must return one p
point onlyy for each
edge point, only one response per edge.
Given an image I:
St 1 Apply
Step A l CANNY_ENHANCER t I, output
CANNY ENHANCER to t t IE
The aim is to filter out any noise in the original image before trying to locate and detect any
edges. And because the Gaussian filter can be computed using a simple mask, it is used
exclusively in the Canny algorithm. It ‘s used to eliminate noise in reason to obtain a smooth
image.
The larger the width of the Gaussian mask, the lower is the detector
detector'ss sensitivity to noise.
The Gaussian mask used is:.
I
Image G
Gx G
Gy
Estimate the edge strength:
Finding the edge direction is trivial once the gradient in the x and y directions are known.
The
h fformula
l for
f finding
fi di the
h edge
d direction
di i is i just
j :
E0 (i,j)=theta = arctan (Gy / Gx)
There are only four possible directions when describing the surrounding pixels 0degrees
(i th
(in the horizontal
h i t l direction),
di ti ) 45 degrees
d ( l
(along the
th positive
iti diagonal),
di l)
90 degrees (in the vertical direction), or 135 degrees (along the negative diagonal). So
now the edge orientation has to be resolved into one of these four directions depending
on which direction it is closest to.
Any edge direction falling within the yellow range (0 to 22.5 & 157.5 to 180
d
degrees) ) iis sett to
t 0 degrees.
d
Any edge direction falling in the green range (22.5 to 67.5 degrees) is set to 45
degrees.
degrees
Any edge direction falling in the blue range (67.5 to 112.5 degrees) is set to 90
degrees.
And finally, any edge direction falling within the red range (112.5 to 157.5 degrees)
is set to 135 degrees.
Direction du gradient
(x,y)
Voisins
V i i lle llong
du gradient
Step 4 Hysteresis Thresholding:
Finally,
Fi ll hysteresis
h i is
i usedd as a means off eliminating
li i i streakingki & to remove
edge pixels caused by noise.
St ki is
Streaking i the
th breaking
b ki up off an edged contour t causedd by
b the
th operator
t
output fluctuating above and below the threshold. Some edge pixels has
l
lower values
l than
th false
f l edge
d pixels
i l so we have
h to
t eliminate
li i t them
th byb using
i
this method of thresholding.
thinning
(non-maximum suppression)
Non-maximum suppression
pp
Ideally
previous technics yield pixel lying on the boundary between regions
In practice
set of pixels seldom characterizes a boundary completely
(because of noise)
breaks in the boundaryy
Local processing
Global processing
Hough
g transform
EL : local processing
p g
Si l approach
Simple h for
f linking
li ki edges
d is
i to
t
analyse characteristics of pixels in a small neighborhood 3x3, 5x5 for
all (x,y) that has undergone edge detection
angle
α ( x , y ) − α ( x ' , y ') ≤ A Angle threshold
Sobel
T>25
T>25,, a=
a=15
15°°
Pixels --
-->> Codes Chains
3 2 1 A
1 7
0
4 1
0 6 6
2
4 0
2 5
5 6 7
3 5
4
y Theta code
7 111
6 110
0 000
t 1 001
ϑ
0 000
6 110
x 5 101
ϑ
5 101
4 100
3 011
2 010
4 100
2 010
1 001
t
a x
Infinités des droites Une droite y=f(x)
qui passent par un point fixe Plusieurs points col
col.
Transformée de Hough
g
a
Hough Transform Technique
• At each point of the (discrete) parameter space,
space
count how many lines pass through it.
– Use an array
arra of co
counters
nters
– Can be thought as a “ parameter image”
• The higher the count, the more edges are collinear
in the image
g space.
p
– Find a peak in the counter array
– This is a “bright”
bright point in the parameter image
– It can be found by thresholding
Transformée de Hough
g
Algorithme case (u,v) => accumulateur
bmin
i
1)Quadrillage de l’espace (a,b)
amin
2) P
Pour chaque
h case A(
A(u,v)=0
) 0
b
3) P
Pour chaque
h point
i t im
image(edge)
g ( dg )
a)
) p
pour a ∈ [a a ]
min max
b) Calculer b = − xa + y
y = ax + b b = − xa + y
y b
a=100
a=11
a=10 a=10
x a=11 a=100
a
x et y fixés
Quadrillage impossible
Transformée de Hough
g
y = ax + b x cos(θ ) + y sin(θ ) = ρ
y ρmin
ρ
θ −π/2
π/2 π/2 θ
x ρmax
θ Is th
the line
li orientation
i t ti
ρ
ρ Is the distance between
Espace des paramètres
the origin and the line
New Parameter Space
• Use the parameter space (ρ, θ)
• Thee new
ew space iss FINITE
N
– 0 < ρ < D , where D is the image diagonal.
–0<θ<π
• The new space can represent all lines
– Y = k is represented with ρ = k, θ=90
– X = k is represented with ρ = k, θ=0
Transformée de Hough
g
A Point in Image Space is now
represented as a SINUSOID
x cos(θ ) + y sin(θ ) = ρ ρ = x cos θ+y sinθ
sinθ
y
ρ
θ
θ
ρ
Espace image E
Espace des
d paramètres
èt
Divvying Up Space
r = x cosθ + y sinθ “normal” form
imsiz
y coord e
dist r
x coord
0 g θ
angle π
Edge Image Parameter space
Issues
i actually
in ll getting
i the
h
curve...
imsiz
y coord e
dist r
x coord
0 g θ
angle 2π
Edge Image Parameter space
Hough Transform Algorithm
Input is an edge image (E(i,j)=1
(E(i,j) 1 for edges)
1 Di
1. i θ and
Discretize d ρ in
i increments
i off dθ and
d dρ.
d Let
L
A(R,T) be an array of integer accumulators, initialized
to 0.
2 For
2. F each
h pixel
i l E(i,j)=1
E(i j) 1 and
d h=1,2,…T
h 1 2 T do
d
1. ρ = i cos(h * dθ ) + j sin(h * dθ )
2. Find closest integer k corresponding to ρ
3
3. Increment counter A(h,k)
A(h k) by one
3. Find local maxima in A(R,T)
Transformée de Hough
g
50
100
150
200
250
300
350
50 100 150 200 250 300
50
100
150
200
250 50
300 100
350 150
50 100 150 200 250 300
200
250
300
350
50 100 150 200 250 300
Segmentation
Basic formulae
let R entire image region
Partition R into n subregions R1,R2,
R1 R2 …, Rn
such that:
⌧∪Ri=R Segmentation is complete
Frequency
Frequency
p ( z ) = P1 p1 ( z ) + P2 p2 ( z )
Global pdf Zone 2 pdf
Zone 1 pdf
P1 z − μ1 2 P2 z − μ2 2
p( z ) = exp(− ) + exp(− )
2π σ 1 2σ 1 2π σ 2 2σ 2
P1 + P2 = 1
T?
Now pb of error : problem of classifying object points as background point
T +∞
E1 (T ) = ∫ p2 ( z )dz and E2 (T ) = ∫ p1 ( z )dz
−∞ T
E (T ) = P2 E1 (T ) + P1 E2 (T )
p ( z ) = P1 p1 ( z ) + P2 p2 ( z ) P1 p1 (T ) = P2 p2 (T )
For gaussian density, taking logarithm,
AT 2 + BT + C = 0
A = σ −σ2
1
2
2
(
B = 2 μ1σ 22 − μ 2σ 12 )
C = μ 2 σ − μ σ + 2σ σ ln(σ 2 P1 / σ 1 P2 )
2 2 2 2 2 2
1 1 2 1 2
if
σ 12 = σ 22 = σ 2
μ1 + μ 2 σ2
T= + ln(( P2 / P1 )
2 μ1 − μ 2 A d if
And P1 = P2
μ1 + μ 2
T=
2
Example
p
2. Region
g splitting
p g and merging
g g
Ex : quadtree
Q
Quadtree
Split into 4 disjoint quadrants any region
Ri where P(Ri)=False
Merge any adjacent regions Rj and Rk for which
P(Rj∪Rk)= TRUE
P(Rj∪Rk)
Stop when no further merging or splitting is
possible
ibl
R L f/b
Leaf/branch
h
R1 R2
R1 R2 R3 R4
R41 R42
R3 R41 R42 R43 R44
R43 R44
quadtree
partition
Example
p
4 steps
result
3- Region
g growing
g g pixel
p agregation
g g
0 1 5 6 5
A A A A A
2 seeds
A A A A A
A A A A A
T=8
A A A A A
R1 associated to s1
R2 associated to s2 A A A A A
P
Property
t |zi-sj|<T
| i j|<T
Difficulties
⌧selection of initial seeds
military images with targets
⌧criteria choice
histogram, a priori info
pp g rule
⌧stopping
Image
g pprocessingg
Corner detection
Corner detection
A corner is easier
Edge
g Detectors Tend to Fail at Corners
Findingg Corners
Intuition:
• Right at corner, gradient is ill defined.
• Near corner, gradient has two different
values.
values
•Ix a
and
d Iyy are
a e the
t e gradients
g ad e ts along
ao gXaand
dY
Formula for Findingg Corners
We look at matrix:
Gradient with respect to x, times
Sum over a small region, the gradient with respect to y
h
hypothetical
th ti l corner
⎡ ∑I 2
∑I I ⎤
C=⎢ x x y
⎥
⎢⎣ ∑ I x I y ∑I 2
y ⎥⎦
⎡ ∑I 2
∑I I ⎤ ⎡λ1 0⎤
C=⎢ x x y
⎥=⎢ ⎥
⎢⎣ ∑ I x I y ∑I λ2 ⎦
2
y ⎥⎦ ⎣ 0
Thi means allll gradients
This di t iin neighborhood
i hb h d are:
((k,0)
, ) or (0,
( , c)) or (0,
( , 0)) (or
( off-diagonals
g cancel).
)
What is region like if:
1. λ1 = 0? edge
2 λ2 = 0? edge
2.
3. λ1 = 0 and λ2 = 0? Homogeneous Region
4. λ1 > 0 and λ2 > 0? Corner
So,, to detect corners
Filter image.
Compute magnitude of the gradient
everywhere.
everywhere
We construct C in a window.
Use Linear Algebra to find λ1 and λ2.
If they are both big, we have a corner.