0% found this document useful (0 votes)
9 views36 pages

Lecture 05

The document discusses edge detection in digital image processing, focusing on the use of first and second derivatives to identify abrupt intensity changes in images. It covers various gradient operators, including the Sobel and Canny edge detectors, and emphasizes the importance of smoothing before derivative calculations to enhance edge detection accuracy. Additionally, it highlights techniques like hysteresis thresholding and the Laplacian of Gaussian filter for robust edge detection in the presence of noise.

Uploaded by

Adeel Ijaz
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)
9 views36 pages

Lecture 05

The document discusses edge detection in digital image processing, focusing on the use of first and second derivatives to identify abrupt intensity changes in images. It covers various gradient operators, including the Sobel and Canny edge detectors, and emphasizes the importance of smoothing before derivative calculations to enhance edge detection accuracy. Additionally, it highlights techniques like hysteresis thresholding and the Laplacian of Gaussian filter for robust edge detection in the presence of noise.

Uploaded by

Adeel Ijaz
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/ 36

Digital Image Processing

Lecture # 5
Edge Detection

1
Edge Segmentation
Use of first derivatives for image
enhancement: The Gradient

• The gradient of a function f(x,y) is defined as

 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

Emphasize more the current point


(y direction)

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

Sobel filters are typically used for edge


detection
Edge Detection
• Edge detectors can be based on the first and second
derivatives which can detect abrupt intensity changes.
• Derivates of digital functions are defined in terms of
differences
• See approximations on using first and second derivatives
in Gonzalez section 10.2.1

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’’

image Laplacian edge


zero-crossing
operator map
x(m,n) g(m,n) I(m,n)

21
Edge Detection
First Second
derivative derivative

Results of first and


  0 .0
second derivative for
edges with Gaussian
noise of mean = 0.   0 .1

•Smoothing step is a must before taking   1 .0


derivative for edge detection

  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

where r2 = x2 + y2,  : standard deviation


• The Laplacian of this function gives the LoG
function:  2 G ( r )  r 2  2 2  
r 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

Smoothing by Gaussian convolution

Differential operators along x and y axis

Non-maximum suppression
finds peaks in the image gradient

Hysteresis thresholding locates edge strings

Edge map
29
Canny Edge Detector (smoothing and enhancement)
CANNY_ENHANCER

Given image I

1. Apply Gaussian Smoothing to I.


2. For each pixel (i, j):
1. Compute the gradient components
2. Estimate the edge strength
3. Estimate the orientation of the edge normal
Canny Edge Detector (Nonmaximum suppression)

The input is the output of CANNY_ENHANCER. We need to thin the


edges. Given Es, Eo, the edge strength and orientation images. For each
pixel (i, j),

1. Find the direction best approximate the direction Eo(i,


j).
2. If Es(i, j) is smaller than at least one of its two
neighbors along this direction, suppress this pixel.

The output is an image of the thinned edge points after suppressing


nonmaxima edge points.
Canny Edge Detector (Hysteresis Thresholding)

Performs edge tracking and reduces the probability of false contours.


Input I is the output of nonmaximum_suppression, Eo and two threshold
parameters
Scan I in a fixed order:

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:

- Can only select “strong” edges.


- Does not guarantee “continuity”.

gradient magnitude low threshold high threshold


Hysteresis thresholding (cont’d)
• Hysteresis thresholding uses two thresholds:
- low threshold tl
- high threshold th (usually, th = 2tl)

th
tl th
tl

• For “maybe” edges, decide on the edge if neighboring


pixel is a strong edge.
Canny Edge Detector Example

original image vertical edges horizontal edges

norm of the gradient after thresholding after thinning


EE465: Introduction to Digital Image
35
Processing Copyright Xin Li
Acknowledgements
 Statistical Pattern Recognition: A Review – A.K Jain et al., PAMI (22) 2000
 Pattern Recognition and Analysis Course – A.K. Jain, MSU
Material in these slides has been taken from, the following resources

 Pattern Classification” by Duda et al., John Wiley & Sons.


 Digital Image Processing”, Rafael C. Gonzalez & Richard E. Woods, Addison-Wesley, 2002
 Machine Vision: Automated Visual Inspection and Robot Vision”, David Vernon, Prentice Hall,
1991
 www.eu.aibo.com/
 Advances in Human Computer Interaction, Shane Pinder, InTech, Austria, October 2008

36

You might also like