0% found this document useful (0 votes)
103 views86 pages

Edge Detection

this document explains about edge detection using canny and other sobel, laplacian and prewitt filters.

Uploaded by

anum_anh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views86 pages

Edge Detection

this document explains about edge detection using canny and other sobel, laplacian and prewitt filters.

Uploaded by

anum_anh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

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

Applying Masks to Images


Convolution Operation
Mask
Set of pixel positions and weights
Origin of mask

1
1

Applying Masks to Images


I1 mask = I2
Convention: I2 is the same size as I1
Mask Application:

For each pixel


Place mask origin on top of pixel
Multiply each weight with pixel under it
Sum the result and put in location of the pixel

Applying Masks to Images

40

40

40

80

80

80

1/9 x
40

40

40

80

80

80

1/9 1/9 1/9


40
40
40
80

80

80

1/9 1/9 1/9


40
40
80

80

80

40

1/9 1/9 1/9


40
40
40
80

80

80

40

80

80

40

40

80

6*(1/9*40)+3*(1/9*80) = 53

Applying Masks to Images

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

Overall effect of this


mask?

Smoothing filter

What about corner pixels


Expand image with virtual pixels
Options
Fill with a particular value, e.g. zeros
Fill with nearest pixel value

Or just ignore them

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)

Why Edge Detection is non-trivial?


Edges are not so clearly defined.
In (a) , edge is quite clear
5

152

148

149

148

149

(a)
In (b) where is an edge?
Or are there multiple edges?

?
5

41

113

(b)

Source: Wikipedia Edge detection

Finding Edges
How do we define Edge?
Edges are locations where intensity variation is high
OR rate of change of intensity is high

How do we find rate of change of intensity?


DIFFERENTIATION

First Order Differential


Continuous form

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

How do we find rate of change of intensity?


DIFFERENTIATION

First Order Differential


Continuous form

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

then f (x)=f(x) g(x)

1
origin

f (x)

Second Order Derivative

40

-40

Zero Crossing

Edge Detection
Its method of localizing intensity discontinuities by
First Order derivative of signal
finding local maxima

Second Order derivative


Look for zero crossings

Stages in Edge Detection


Stage 1: Smoothing
Because Noise is enhanced in differentiation, we often apply a smoothing
filter first

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.

Thinning wide edges to 1-pixel with (nonmaximum suppression);


Establishing the minimum value to declare a local maximum an edge (thresholding)

Edge Detection: Smoothing

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

Value of has to be specified

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

Continuous Gaussian Function


1-D Gaussian
x2

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

Continuous Gaussian Function

2-D Gaussian Function


g ( x, y )

1
2

( x2 y2 )
2 2

Gaussian Filter

Edge Detection: Derivative/Edge Enhancement

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.

Application of 2-D Masks


If fx is derivative in x-direction, fy is derivative in y-direction
Gradient Magnitude

f f
2
x

Gradient Direction

arctan

fy
fx

2
y

Edge Detection: Thresholding

Detection Stage - Threshold


Gradient Magnitude

Gradient Magnitude normalized b/w 0-100

Application of a threshold

Gradient Magnitude

Log of M to
enhance
visibility

Effect of Different Thresholds

T = 10

Effect of Different Thresholds

Effect of Different Thresholds

T = 20

Effect of Different Thresholds

T = 40

Effect of Different Thresholds

T = 80

What about Gradient Direction?


Gradient Direction is always perpendicular to edge
Direction of most change of gray levels
Thick edges can be eliminated using gradient direction
Weak edges also captured in this manner

What about Gradient Direction?

Canny Edge Detector

Cannys Edge Detector


Filtering + Derivative:
Uses first derivative Gaussian masks

Detection:
Uses Non-Maxima Suppression
Uses Hysteresis Thresholding

First Derivative of Gaussian


Expression?
Effect?
Filtering + Derivative

Canny Edge Operator


S G * I G * I
G
G
x
G
S
*I
x

G
y

G
*I
y

fx

fy

f x2 f y2

M Threshold 10

Non-Maximum Suppression

Remove all points along the gradient


direction that are not maximum points

Non-Maxima Suppression

Where M(x,y) and M(x,y) are gradient


magnitudes on both sides of edge at (x,y) in
the gradient magnitude direction

Non-Maxima Supression

Quantization of Gradient Direction

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}

Compare current value of M with two neighbors in


appropriate direction
If maximum, keep it, otherwise make it zero

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

Gradient Magnitude Results

sigma = 0.5

sigma = 2

M when = 2

Non-maxima
suppressed image

Gradient Direction Results

Raw

Quantized

Th = 50
Tl = 10

Th = 100
Th = 50
Tl = 10
Tl = 40
(incr. in Th only) (incr. in Tl only)

Using Second Derivatives

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

Forsyth and Ponce: Chapter 7


Dr. Sohaib Khans page on Canny Edge Detection
Gives step by step explanation of algorithm.
http://suraj.lums.edu.pk/~cs436a02/CannyImplementation.htm

You might also like