Edge Detection
Edge Detection
Edge Detection
Portions of these slides are based on
Dr. Sohaib Khans lecture slide
Dr. Jeffrey Hos lecture slides
Some images were taken from
Wikipedia
Bill Greens Canny Edge Detection Tutorial
What is an Edge?
An edge is a location of rapid intensity variation
The often mark boundaries of objects, occlusion contours, shadow
boundaries or surface contours
Edges are very important in human perception
1
1
40
40
40
80
80
80
1/9 x
40
40
40
80
80
80
80
80
80
80
40
80
80
40
80
80
40
40
80
6*(1/9*40)+3*(1/9*80) = 53
40
40
53
67
80
80
40
40
53
67
80
80
40
40
53
67
80
80
40
40
53
67
80
80
40
40
53
67
80
80
40
40
53
67
80
80
Smoothing filter
Edge Detection
Input
Output
Choice of Mask?
Should give a zero on smooth
output
Should give a high value on nonsmooth regions
-1
-1
-1
Original Image, I
e=I
1 0 1
1 0 1
1 0 1
abs(e)
152
148
149
148
149
(a)
In (b) where is an edge?
Or are there multiple edges?
?
5
41
113
(b)
Finding Edges
How do we define Edge?
Edges are locations where intensity variation is high
OR rate of change of intensity is high
df
f ( x) f ( x x)
f '
lim
dx x0
x
Discrete form
df
f '
f ( x) f ( x 1)
dx
Finding Edges
Edges are locations where intensity variation is high
OR rate of change of intensity is high
Discrete form
df
f ( x) f ( x x)
f '
lim
dx x0
x
df
f '
f ( x) f ( x 1)
dx
Discrete Derivatives
f(x)
40
40
40
40
40
80
80
80
80
80
f (x)
40
g(x)
If
-1
1
origin
f (x)
40
-40
Zero Crossing
Edge Detection
Its method of localizing intensity discontinuities by
First Order derivative of signal
finding local maxima
Stage 2: Differentiation
Enhances edge areas
Stage 3: Detection/Localization
Produces a binary output, with edges marked by 1, other areas as zero
Decide which local maxima in the filters output are edges and which are just
caused by noise.
1.
2.
Smoothing Masks
Mean Filter
Gaussian Filter
g ( x, y) ce
( x2 y 2 )
2 2
21
35
21
21
94
155
94
21
35
155
255
155
35
21
94
155
94
21
21
35
21
1/9 x
Why Smoothing?
Local Operators (Differential Operators) accentuate
noise !!
Therefore, need smoothing before computing image
gradients.
Motivation: Smoothing removes local intensity
variation and what remains are the prominent edges.
Gaussian Smoothing with exponential kernel function
Examples
Smoothing/Filtering
Filtering
Gaussian Filter
Pixel weight is inversely proportional to distance
from origin
g ( x, y ) e
( x2 y2 )
2 2
Gaussian Filtering
Example
g ( x, y ) e
( x2 y2 )
2 2
x = -1, y = -1, = 1
g (1,1) e
( 1) 2 ( 1) 2
0.367
0.367
Gaussian Filtering
Implementation problem
Float multiplications are slow
Solution
Multiply mask with 255, round to nearest integer
Scale answer by sum of all weights
Gaussian Filtering
94
155
94
155
255
155
94
155
94
21
35
21
21
94
155
94
21
35
155
255
155
35
21
94
155
94
21
21
35
21
Round(g/70)
Gaussian Filtering
2
1
g ( x)
e 2
2
Non zero from - to
Width is controlled by
Symmetric
Area under curve = 1
x2
2
1
e 2 1
2
1
2
( x2 y2 )
2 2
Gaussian Filter
Approximating Derivatives
Derivative Masks
From definition
of derivatives
-1
-1
Prewitt Operator
-1
-1
-1
-1
-1
-1
Sobel Operator
-1
-1
-2
-1
-2
-1
-1
-1
Roberts Operator
Combines
Smoothing
and
Properties of Masks
Filtering Masks
All values are +ve
Sum to 1
Output on smooth region is
unchanged
Blurs areas of high contrast
Larger mask -> more smoothing
Derivative Masks
opposite signs
Sum to zero
Output on smooth region is zero
Gives high output in areas of high
contrast
Larger mask -> more edges
detected
Image Gradients
The gradient of a differentiable function I gives the direction
in which the values of the function
change most rapidly.
Its magnitude gives you the rate of
change.
f f
2
x
Gradient Direction
arctan
fy
fx
2
y
Application of a threshold
Gradient Magnitude
Log of M to
enhance
visibility
T = 10
T = 20
T = 40
T = 80
Detection:
Uses Non-Maxima Suppression
Uses Hysteresis Thresholding
G
y
G
*I
y
fx
fy
f x2 f y2
M Threshold 10
Non-Maximum Suppression
Non-Maxima Suppression
Non-Maxima Supression
Non-Maximum Suppression
Hysteresis Thresholding
Two thresholds, TH and TL
Apply non-maxima suppression to M (gradient
magnitude)
Scan image from left to right, top to bottom
If M(x,y) is above TH mark it as edge
Recursively look at neighbors; if gradient magnitude
is above TL mark it as edge
Gradient Magnitude
Hysteresis Thresholding
High
Low
Algorithm Summary
Compute gradient of image f(x,y) by convolving
with first derivative of Gaussian in x and y
directions
Algorithm Summary
Compute gradient magnitude and direction at each
pixel
Perform non-maxima suppression
Find gradient direction at pixel
Quantize it in 8 directions
{0, 45, 90, 135, 315}
Algorithm Summary
Perform Hysteresis thresholding
Scan image from left to right, top to bottom
If M(x,y) is above TH mark it as edge
Recursively look at neighbors; if gradient magnitude is above TL mark it as
edge
Choice of Sigma
Choice of Sigma
sHalf is computed by finding the point on the curve where the
Gaussian value drops below T
exp(-x^2/(2*sigma^2) = T
sHalf = round(sqrt(-log(T) * 2 * sigma^2))
mask size is then 2*sHalf + 1
Choice of Sigma
Conv. Results
sigma = 0.5
sigma = 2
sigma = 0.5
sigma = 2
M when = 2
Non-maxima
suppressed image
Raw
Quantized
Th = 50
Tl = 10
Th = 100
Th = 50
Tl = 10
Tl = 40
(incr. in Th only) (incr. in Tl only)
Further Readings
Classical Feature Detection
Wikipedia Edge Detection
Bill Greens Canny Edge Detection Tutorial
http://dasl.mem.drexel.edu/alumni/bGreen/www.pages.drexel.edu/_weg22/
can_tut.html