Professional Documents
Culture Documents
Edge Detection
2 Edges as Reduced Images
Edges seem to be important…
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
3 Why Edge Detection
- More compactly represents salient features of –
the scene than pixels
- Helps in determining object boundaries and
segmentation
- Further features can be extracted from the
edges of an image (e.g., corners, lines etc.)
- These features can be used by higher-level
computer vision algorithms (e.g., recognition).
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
4 Edge Detection
What is an edge? An edge is a set of connected pixels
that lie on the boundary between two regions. It is
locally identifiable place of local transition from one
object to another. They are not complete border.
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
6 Edges in reality
Depth
discontinuity:
Reflectance change, object boundary
texture
Cast shadows
Discontinuous
change in surface
orientation
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
7 Edges & Derivatives
We have already spoken about how derivatives are
used to find discontinuities
Image intensity function first derivative
(along horizontal scanline)
edges correspond to
extrema of derivative
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
9 Image gradient
f f
The gradient of an image: f = [ , ]
x y
f f f f
f = [ , 0] f= [ 0 , ] f = [ , ]
y x y
x
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
10 Image gradient
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
11 Image gradient (cont…)
= +
x y
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
12 Recollect our 1st Derivative
For 2D function, f(x,y), the partial derivative is defined as:
f ( x , y) f (x +,y) − f(x ,y )
= lim
x →0
For discrete data, we can approximate using finite
differences:
f (x, y)
f (x +1, y) − f (x, y)
• Right difference x
f (x, y)
f (x , y) − f (x-1, y)
• Left difference x
f
• Central difference ( f (x +1) − f (x −1)) / 2
x
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
13 1st derivatives as a filter
f ( x , y) f ( x , y)
x y
-1
-1 1 1
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
14 1st Derivative Kernels
-1 0 1 1 1 1
Prewitt Kernel:
1 -1 0 1 1 0 0 0
Try to reduce the ∗ ∗
6 -1 0 1 6 -1 -1 -1
sensitiveness to
noise by averaging
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
15 Sobel operator
-1 0 1 1 2 1
(Sobel) Gradient is 1 1
∗ -2 0 2 ∗ 0 0 0
8 -1 0 1 8 -1 -2 -1
I = [gx gy]T g𝑥 g𝑦
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
16 Edge Detection Example
Original Image Horizontal Gradient Component
f(x)
d
f(x) where’s
dx
the edge?
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
18
Solution: smooth first
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
19
Solution: smooth first
f
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
20
Solution: smooth first
f
h f
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
21
Solution: smooth first
f Where is the
edge?
h
h f
(h f ) Look for peaks
x
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
22 Importance of Scale
Structures exist at multiple scales
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
25 Optimal edge detector
Criteria for an “optimal” edge detector:
Good detection: the optimal detector must minimize the probability of false
positives (detecting spurious edges caused by noise), as well as that of
false negatives (missing real edges)
Good localization: edges detected must be as close as possible to true edges
Single response: the detector must return one point only for each true edge
point; that is, minimize the number of local maxima around the true edge
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
26 The Canny Edge Detection
1. Smooth the image with a Gaussian filter with spread .
2. Compute gradient magnitude and direction at each pixel of
the smoothed image.
3. non-maximum suppression: Thin multi-pixel wide “ridges”
down to single pixel width
4. Linking and thresholding (hysteresis): Use double
thresholding to segregate ‘strong’ (high-magnitude) and
‘weak’ edge pixels. Use strong edge pixels to start edge
curves and weak edge pixels to continue them.
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
27 Example Result
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
28 Example Result
thresholding
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
29 Example Result
How to turn
these thick
regions of
the gradient
into curves?
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
30 Non-maximal suppression
Problem:
pixels along this
edge didn’t
survive the
thresholding
thinning
(non-maximum
suppression)
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
32 Canny threshold hysteresis
1. Apply a high threshold to detect strong edge pixels.
2. Link those strong edge pixels to form strong edges.
3. Apply a low threshold to find weak but plausible edge
pixels.
4. Extend the strong edges to follow weak edge pixels by
doing connectivity analysis (keep only those weak
edge pixels which are connected to strong edge
pixels).
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
33 Final Canny edge result
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
34 Effect of (Gaussian kernel spread/size)
h
h f
(h f )
x
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
36 Derivative property of convolution
Derivativeproperty of convolution : ( f g ) = f
*g
x x
f
x
h
( x
h ) f
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
37 2nd Derivative Methods
• Finding optimal edges (maxima of gradient
magnitude) is equivalent to finding places where the
second derivative is zero. Why?
• How do we find maxima or minima of any functions?
We differentiate them and find places where the
derivative is zero.
• Differentiating the first derivative (gradient
magnitude) gives us the second derivative
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
38 2nd Derivative Methods: Laplacian
We encountered the 2nd-order derivative based
Laplacian filter already – isotropic i.e rotationally
invariant
2
(h f)
x
2
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
41 LOG (Marr-Hildreth edge detector)
• To reduce the noise effect and also to adjust the
scale, the image is first smoothed.
• When the filter chosen is a Gaussian, we call it the
LoG edge detector.
σ controls smoothing/adjusts scale
• It can be shown that:
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
42 LOG (Marr-Hildreth edge detector)
The Laplacian of Gaussian function can be
approximated over a discrete spatial neighborhood to
give a convolution kernel which looks like a Mexican
hat.
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
43 Example Result
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
44 Canny vs LoG Edge Detector
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT
45 Matlab
Demo
Image Processing and Computer Vision by Dr. Praveen Kumar @ CSE, VNIT