lecture_3
lecture_3
Edge Detection
CS-477 Computer Vision
1
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
1 Basics
2 Edge detectors
2
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
3
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
1 Basics
2 Edge detectors
4
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Examples
5
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Application of edge
6
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
7
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
What is an edge?
Edge models
Step
Roof
Ramp
Spike
8
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Detecting Discontinuities
Image derivatives
∂f f (x+)−f (x) ∂f f (xn+1 )−f (x)
∂x = lim → ∂x ≈ ∆x
→0
Convolve image with derivative filters
Backward difference: [−1 1]
Forward difference: [1 − 1]
Central difference: [−1 0 1]
9
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Derivatives in two-dimensions
Definition
∂x = lim f (x+,y )−f (x,y )
∂f (x,y ) ∂f (x,y )
∂y = lim f (x,y +)−f (x,y )
→0 →0
Approximation
∂f (x,y ) f (xn+1 ,ym )−f (xn ,ym ) ∂f (x,y ) f (xn ,ym+1 )−f (xn ,ym )
∂x ≈ ∆x ∂y ≈ ∆y
Convolution kernels
1
fx = 1 −1 fy =
−1
10
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Image derivatives
Image I
1
Iy = I ∗
Ix = I ∗ 1 −1 −1
11
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Image derivatives
An edge is a place of rapid change in the image intensity function
12
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Image derivatives
13
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
14
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
15
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
16
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Image smoothing
17
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Image smoothing
Gaussian smoothing
−(x 2 +y 2 )
g(x, y ) = e 2σ 2
Scale of Gaussian
As σ increases, more pixels are involved in average
As σ increases, image is more blurred
As σ increases, noise is more effectively suppressed
18
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Image smoothing
19
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
1 Basics
2 Edge detectors
20
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
21
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Gradient operators
Prewit
Sobel
Laplacian of Gaussian (Marr-Hildreth)
Gradient of Gaussian (Canny)
22
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Compute derivatives
In x and y directions
Find gradient magnitudes
Threshold gradient magnitude
23
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Vertical Edges:
1 0 −1
hx = 1 0 −1
1 0 −1
Horizontal Edges:
−1 −1 −1
hx = 0 0 0
1 1 1
Gradient:
Gx = I ∗ hx
G y = I ∗ hy
24
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
25
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
26
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
27
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Drawback
Edges are not clear
28
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
29
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
S =g∗I (1)
where,
1 −(x 2 +y 2 )
g=√ e 2σ 2 (2)
2πσ
Next step is to find the Laplacian of S. This is represented as,
∂2 ∂2
∆2 S = S + S (3)
∂x 2 ∂y 2
30
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
∆2 S = ∆2 (g ∗ I) = (∆2 g) ∗ I (4)
where ∆2 g is represented as
x2 + y2 2 2
2 1 − x +y2
∆ g = −√ 2− e 2σ (5)
2πσ 3 σ2
This means, rather than convolve the image with the gaussian
and take the second order derivative of the result, you can
actually take the 2nd derivative of the gaussian itself.
31
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Gaussian
−x 2
1-D Gaussian: g(x) = e 2σ2
x -3 -2 -1 0 1 2 3
g(x) .011 .13 .6 1 .6 .13 .011
−(x 2 +y 2 )
2-D Gaussian: g(x, y ) = e 2σ 2 for σ = 2
Here the mask is multiplied with 255 to have integer values from range 0-255. 32
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
LOG Filter
2 +y 2
−x
1 x 2 +y 2
∆2 g = − √ 2− σ2
e 2σ 2
2πσ 3
33
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
34
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
35
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
36
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
∆2 S = ∆2 (g ∗ I) = (∆2 g) ∗ I = I ∗ (∆2 g)
Requires n2 multiplications
Requires 4n multiplications
37
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Separability
38
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Example
39
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Algorithm
Compute LoG
Use 2D filter i.e., ∆2 g(x, y ), OR
Use 4 1D filters i.e., g(x), gxx (x), g(y ), gyy (y )
Find zero-crossings from each row,
Find slope of zero-crossings
Apply threshold to slope and mark edges
40
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
Robust to noise
Localization
Too many or too less responses
41
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
Line detection
42
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
Line detection
43
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
Quality of an Edge
45
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
E = (mxi + c − yi )2
P
∂E
Pi
∂m = (mxi + c − yi )xi = 0
i
∂E
P
∂c = (mxi + c − yi ) = 0
iP
xi2
P P
xi
xi yi
i i m i
P P = P
xi 1 c yi
i i i
46
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
Disadvantages are:
Multiple lines
Not robust to noise
47
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
Another approach
RANSAC (RANdom SAmple Consensus1 )
- It is an iterative method to estimate parameters of a
mathematical model from a set of observed data that contains
outliers, when outliers are to be accorded no influence on the
values of the estimates.
- Roboust against noise
1
https://en.wikipedia.org/wiki/Random_sample_consensus 48
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
49
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
50
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
51
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
Algorithm:
1 Sample (randomly) the number of points required to fit the model (n = 2)
2 Solve for model parameters using samples
3 Score by the fraction of inliers within a preset threshold of the model (NI = 6)
Repeat 1-3 until the best model is found with high confidence
52
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
NI = 14
53
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
Summary of RANSAC
Select minimum number of random points from data needed
to estimate the model
Estimate the model from selected random points
Check how many other points are consistent with the fitted
model (Consistent Set)
If consistent set is large enough, estimate model from all
points in the consistent set
If the consistent set is larger than the previous best model,
make the current model as the best model
Repeat a number of times
54
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Quality of an Edge
Pros
Robust to outliers
Applicable for larger number of objective function
parameters
Optimization parameters are easier to choose than other
approaches
Cons
Computational time grows quickly with fraction of outliers
and number of parameters
Needs to be adapted further to allow multiple fits
Common applications
Computing a homography(e.g., image stitching)
Estimating fundamental matrix (relating two views)
55
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
56
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Steps
57
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Step 1 and 2
1 Smoothing
s = I ∗ g(x, y ) = g(x, y ) ∗ I
2 +y 2
−x
where, g(x, y ) = √1 e 2σ 2
2πσ
2 Derivative
∇S = ∇(g ∗ "
I) =#(∇g) ∗ I
∂g
g
where ∇g = ∂g = x
∂x
gy
∂y
g g ∗I S
∇S = x ∗ I = x = x
gy gy ∗ I Sy
58
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
59
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
60
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
61
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
63
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
q
|∇S| = Sx2 + Sy2 M(x, y )
For visualization
M ≥ Threshold = 25
64
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
65
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
Connectedness:
66
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
67
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
68
CS-477 Computer Vision by Dr. Mohsin Kamal
Basics Edge detectors
q
|∇S| = Sx2 + Sy2 M(x, y )