Lecture 05
Lecture 05
Lecture # 5
Edge Detection
1
Edge Segmentation
Use of first derivatives for image
enhancement: The Gradient
f
Gx x
f f
G y
y
Gradient Operators
Sobel Operator
-1 -2 -1 -1 0 1
0 0 0 -2 0 2
1 2 1 -1 0 1
Extract horizontal edges Extract vertical edges
f ( z7 2 z8 z9 ) ( z1 2 z2 z3 )
( z3 2 z6 z9 ) ( z1 2 z4 z7 )
Emphasize more the current point (x
direction) Pixel Arrangement
Sobel Operator: Example
An image of a
contact lens
which is
enhanced in
order to make
defects more
obvious
6
Edge Detection
• First order derivatives produce thick edges while second order
derivatives produce finer ones. See ramp edge on the figure
10.2 on previous slide
• Second order derivatives enhance sharp changes and fine
details more aggressively than first order derivatives see the
isolated point and the line in the same figure. This can be a
problem if the noise is present in the image
• Second derivative changes its sign as it transitions into and
out of a ramp or step edge. See the step edge. This “double
edge” effect can be used to locate edges.
• The sign of the second derivative is also used to determine
whether an edge is a transition from light to dark (-ve value)
or from dark to light (+ve value). See step edge
8
Edge Detection
9
Edges
Gradient Operators
• Most common differentiation operator is the
gradient vector.
f ( x , y )
x G x
f ( x, y )
f ( x , y ) G y
y
Magnitude:
f ( x, y ) G x G y
2
2 1/ 2
Gx Gx
Direction:
Gy
1
f ( x , y ) tan
Gx
12
Gradient Operators
Some common gradient operators
Roberts and Prewitt masks are the simplest
but not robust against noise
Sobel edge detection masks are the most
common and give satisfactory results in
presence of noise
13
Gradient Operators
Direction of an Edge
•The direction of an edge at a point is orthogonal to the direction of the
gradient vector at the point
Edge Detection
• First and second derivative
for smooth noiseless edge
• The zero crossings of the
second derivative can be
used for locating edges in
an image.
20
Zero Crossings
zero crossing
f f’ f’’
21
Edge Detection
First Second
derivative derivative
10 . 0
22
Laplacian of a Gaussian (LoG)
• A filter which combines the smoothing function
(Gaussian) with the Laplacian is called Laplacian
of a Gaussian (LoG) filter.
• Robust against noise.
• Consider a smoothing Gaussian function:
r2
G (r ) e 2 2
2G ( r ) e
2 2
r 2 4 23
Laplacian of a Gaussian (LoG) Filter
24
Edge detection by LoG
• Due the shape of this function it is also called
Mexican hat function (or Mexican hat filters).
• Better performance against noise. Reduces the
intensity of structures or noise, which are at scales
much smaller than sigma.
• Choose size of Gaussian mask to be n >= 6*sigma
• Then use a 3x3 Laplacian
• Find the zero crossings
25
Canny Edge Detector
(J. Canny’1986)
Original image
Non-maximum suppression
finds peaks in the image gradient
Edge map
29
Canny Edge Detector (smoothing and enhancement)
CANNY_ENHANCER
Given image I
1. Locate the next unvisited edge pixel (i, j) such that I(i, j)
2. Starting from (I, j), follow the chains of connected local maxima in both
directions perpendicular to the edge normal as long as I
3. Marked all visited points and save a list of the locations of all points in the
connected contour found.
Hysteresis thresholding
• Standard thresholding:
th
tl th
tl
36