CAP 5415 Computer Vision
Fall 2012
Dr. Mubarak Shah
Univ. of Central Florida
Alper Yilmaz, Mubarak Shah Fall 2011UCF
Edge Detection
Lecture-3
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Example
Alper Yilmaz, Mubarak Shah Fall 2012UCF
An Application
What is an object?
How can we find it?
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Edge Detection in Images
At edges intensity or color changes
Alper Yilmaz, Mubarak Shah Fall 2012UCF
What is an Edge?
Discontinuity of intensities in the image
Edge models
Step
Step Ramp
Roof
Ramp
Spike
Roof Spike
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Detecting Discontinuities
Image derivatives
f f x f x f f x n 1 f x
lim
x 0
x x
Backward difference [-1 1]
Convolve image with
Forward difference
derivative filters
[1 -1]
Central difference [-1 0 1]
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Derivative in Two-Dimensions
Definition
f x , y f x , y f x , y f x , y f x , y f x , y
lim lim
x 0
y 0
f x , y
Approximation f x , y f x , ym f x , y f x n , y m 1 f x n , y m
n 1 m n
x x y x
f x 1 1 1
fy
Convolution kernels 1
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Image Derivatives
1
Image I I x I * 1 1 Iy I *
1
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Derivatives and Noise
Strongly affected by noise What is to be done?
obvious reason: image Neighboring pixels look
noise results in pixels alike
that look very different Pixel along an edge look
from their neighbors alike
Image smoothing should
The larger the noise is the help
stronger the response Force pixels different to
their neighbors (possibly
noise) to look like
Alper Yilmaz, neighbors
Mubarak Shah Fall 2012UCF
Derivatives and Noise
Increasing noise
Zero mean additive gaussian noise
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Image Smoothing
Expect pixels to be like their neighbors
Relatively few reflectance changes
Generally expect noise to be independent
from pixel to pixel
Smoothing suppresses noise
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Gaussian Smoothing
(x2 y2
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
Alper Yilmaz, Mubaraksuppressed
Shah Fall 2012UCF
Gaussian Smoothing (Examples)
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Edge Detectors
Gradient operators
Prewit
Sobel
Laplacian of Gaussian (Marr-Hildreth)
Gradient of Gaussian (Canny)
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Prewitt and Sobel Edge Detector
Compute derivatives
In x and y directions
Find gradient magnitude
Threshold gradient magnitude
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Prewitt Edge Detector
image average blurred derivative edges in x
smoothing in x filtering in x
1 1
1 1
1 1
1 1 and 1 0 1
1 0 1
1 0 1
image average blurred derivative edges in x
smoothing in y filtering in y
1 1 1 1 1 1 1
1 1 0 0
1 1 and 0
1 1 1
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Sobel Edge Detector
1 0 1
2 0 2 d
I
1 0 1 dx
*
Image I d
2
d
2 Threshold Edges
I I
dx dy
1 1 d
* 2 I
0 0 0
dy
1 2 1
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Sobel Edge Detector
d
I
dx
d
I
dy
Alper Yilmaz, Mubarak Shah Fall 2012UCF
Sobel Edge Detector
2
d
2
d
I I
dx dy
Threshold 100
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Marr Hildreth Edge Detector
Smooth image by Gaussian filter S
Apply Laplacian to S
Used in mechanics, electromagnetics, wave theory, quantum
mechanics and Laplace equation
Find zero crossings
Scan along each row, record an edge point at the location of
zero-crossing.
Repeat above step along each column
Marr Hildreth Edge Detector
Gaussian smoothing
x2 y2
smoothed image image
Gaussian filter g
1
e
2 2
S g * I 2
Find Laplacian
second order second order
is used for gradient (derivative)
derivative in x derivative in y
2 2 is used for Laplacian
2 S S S
x 2 y 2
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Marr Hildreth Edge Detector
Deriving the Laplacian of Gaussian (LoG)
2 S 2 g * I 2 g * I
x2 y2
1 x2 y2
2 g 2 e 2 2
2 3
2
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Gaussian
Standard
deviation
x
-3 -2 -1 0 1 2 3
.011 .13 .6 1 .6 .13 .011
g(x)
2-D Gaussian
2-D Gaussian
LoG Filter
x2 y2
1 x2 y2
2G 2 e 2 2
2 3
2
Y
0.0008 0.0066 0.0215 0.031 0.0215 0.0066 0.0008
0.0066 0.0438 0.0982 0.108 0.0982 0.0438 0.0066
0.0215 0.0982 0 -0.242 0 0.0982 0.0215
0.031 0.108 -0.242 -0.7979 -0.242 0.108 0.031 X
0.0215 0.0982 0 -0.242 0 0.0982 0.0215
0.0066 0.0438 0.0982 0.108 0.0982 0.0438 0.0066
0.0008 0.0066 0.0215 0.031 0.0215 0.0066 0.0008
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Finding Zero Crossings
Four cases of zero-crossings :
{+,-}
{+,0,-}
{-,+}
{-,0,+}
Slope of zero-crossing {a, -b} is |a+b|.
To mark an edge
compute slope of zero-crossing
Apply a threshold to slope
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
On the Separability of LoG
Similar to separability of Gaussian filter
Two-dimensional Gaussian can be separated into
2 one-dimensional Gaussians
h ( x, y ) I ( x, y ) * g ( x, y ) n2 multiplications
h ( x , y ) I ( x , y ) * g 1 ( x ) * g 2 ( y ) 2n multiplications
.011
.13
x2
.6
2
2
g (x) e
g 2 g ( y) 1
.6
g1 g ( x ) .011 .13 .6 1 .6 .13 .011 .13
.011
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
On the Separability of LoG
2 S 2 g * I 2 g * I I * 2 g
Requires n2 multiplications
2 S I g xx ( x ) g ( y ) I g yy ( y ) g ( x )
Requires 4n multiplications
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Seperability
Gaussian Filtering
Image g(x) g(y) I g
Laplacian of Gaussian Filtering
gxx(x) g(y)
Image + 2 S
gyy(y) g(x)
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Example
I
I * 2 g Zero crossings of 2 S
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Example
6
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Algorithm
Compute LoG
2 g ( x, y )
Use 2D filter g ( x ), g xx ( x ), g ( y ), g yy ( y)
Use 4 1D filters
Find zero-crossings from each row
Find slope of zero-crossings
Apply threshold to slope and mark edges
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Quality of an Edge
Robust to noise
Localization
Too many or too less responses
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Quality of an Edge
True Poor robustness Poor Too many
edge to noise localization responses
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
Criterion 1: Good Detection: The optimal detector must
minimize the probability of false positives as well as false
negatives.
Criterion 2: Good Localization: The edges detected must
be as close as possible to the true edges.
Single Response Constraint: The detector must return
one point only for each edge point.
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector Steps
1. Smooth image with Gaussian filter
2. Compute derivative of filtered image
3. Find magnitude and orientation of gradient
4. Apply Non-maximum Suppression
5. Apply Hysteresis Threshold
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
First Two Steps
Smoothing 1
x2 y2
g ( x, y) 2 2
e
S I g ( x, y) g ( x, y) I 2
Derivative
S g I g I g
gx
g gx g
gx gx I y
S I g I y
g
y y
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
Derivative of Gaussian
g x ( x, y)
g y ( x, y)
g ( x, y)
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
First Two Steps
I Sx
Sy
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
Third Step
Gradient magnitude and gradient direction
( S x , S y ) Gradient Vector
magnitude ( S x2 S y2 )
Sy
direction tan 1
Sx
image gradient magnitude
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
Fourth Step
Non maximum suppression
We wish to mark points along the curve where the magnitude is largest. We can do this by
looking for a maximum along a slice normal to the curve (non-maximum suppression).
These points should form a curve. There are then two algorithmic issues: at which point is
the maximum, and where is the next one?
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
Non-Maximum Suppression
Suppress the pixels in |S| which are not
local maximum
S x , y if S x , y S x , y
x , y
M x , y & S x , y S x , y
x , y
0 otherwise
x , y
x and x are the neighbors of x along
normal direction to an edge
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
Non-Maximum Suppression
S S x2 S 2
y M
For visual ization
M Threshold 25
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
Hysteresis Thresholding
If the gradient at a pixel is
above High, declare it as an edge pixel
below Low, declare it as a non-edge-pixel
between low and high
Consider its neighbors iteratively then declare it an
edge pixel if it is connected to an edge pixel directly
or via pixels between low and high.
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
Hysteresis Thresholding
Connectedness
x x x
4 connected 8 connected 6 connected
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
Hysteresis Thresholding
Gradient High
magnitude
low
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
Hysteresis Thresholding
Scan the image from left to right, top-bottom.
The gradient magnitude at a pixel is above a high
threshold declare that as an edge point
Then recursively consider the neighbors of this
pixel.
If the gradient magnitude is above the low threshold
declare that as an edge pixel.
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Canny Edge Detector
Hysteresis Thresholding
regular
M M 25
Hysteresis
High 35
Low 15
Alper Yilmaz, Mubarak Shah Fall 2012, UCF
Suggested Reading
Chapter 4, Emanuele Trucco, Alessandro
Verri, "Introductory Techniques for 3-D
Computer Vision"
Chapter 2, Mubarak Shah, Fundamentals of
Computer Vision
Alper Yilmaz, Mubarak Shah Fall 2012, UCF