www.kouroshkiani.com

Download Report

Transcript www.kouroshkiani.com

DREAM
IDEA
PLAN
IMPLEMENTATION
1
2
Introduction to Image Processing
Present to:
Amirkabir University of Technology (Tehran Polytechnic) &
Semnan University
Dr. Kourosh Kiani
Email: [email protected]
Email: [email protected]
Email: [email protected]
Web: www.kouroshkiani.com
3
Lecture 11
Introduction to Edge
Detection
4
• Edge : an edge is a significant, local change in the
image intensity.
• Edge Detection : Why we do it.
 Humans can recognize an enormous range of objects from just line images.
 Human visual system performs some sort of edge detection prior to
recognition on color or intensity images.
 Drastically reduces data to be processed.
 Preserves the structural information .
 Edge detection contributes significantly to algorithms for feature detection,
segmentation, and motion analysis
 Important features can be extracted from the edges of an image (e.g.,
corners, lines, curves).
 These features are used by higher-level computer vision algorithms (e.g.,
recognition).
What Causes Intensity Changes?
• Geometric events
– surface orientation (boundary) discontinuities
– depth discontinuities
– color and texture discontinuities
• Non-geometric events
– illumination changes
– specularities
– shadows
– inter-reflections
surface normal discontinuity
depth discontinuity
color discontinuity
illumination discontinuity
Gradient
• For a continuous two dimensional function
Gradient is defined as
 f 
Gx  x 
G[ f ( x, y )]      
Gy  f 
 y 
G  Gx 2  Gy 2  Gx  Gy
 Gy 
  tan  
 Gx 
1
Let
f ( x, y )  x y
2
f
( x, y )  2 xy
x
f
(3,2)  12
x
Find
f (3,2)
f
2
( x, y )  x
y
f
(3,2)  9
y
f (3,2)  12i  9 j  (12,9)
Let
f ( x, y, z )  xye
2
2
f
( x, y , z )  ( y  2 x 2 y )e x  z  5
x
f
(1,3,2)  9
x
x 2  z 2 5
Find
2
2
f
( x, y, z )  xe x  z 5
y
f
(1,3,2)  1
y
f (1,3,2)
2
2
f
( x, y, z )  2 xyze x  z 5
z
f
(1,3,2)  12
z
f (1,3,2)  9i  1 j  12k  (9,1,12)
Gradient Example 1: A scalar field is defined by: T = 10 + x for -10 < x < 10
The field T is displayed graphically in the figure, wherein the brightness of the image
at a given location is proportional to the magnitude of T at that location
The gradient of T is then given by i. This vector function is plotted below.
Gradient Example 2: A scalar field is defined by: T = x2 for -10 < x < 10
The field T is displayed graphically in the figure, wherein the brightness of the image
at a given location is proportional to the magnitude of T at that location
The gradient of T is then given by 2xi . This vector function is plotted below.
Gradient Example 3: A scalar field is defined by: T = 20 + x + y for -10 < x,y < 10
The field T is displayed graphically in the figure, wherein the brightness of the image
at a given location is proportional to the magnitude of T at that location
The gradient of T is then given by i + j. This vector function is plotted below.
Gradient Example 4: A scalar field is defined by: T = 100 + xy for -10 < x,y < 10
The field T is displayed graphically in the figure, wherein the brightness of the image
at a given location is proportional to the magnitude of T at that location
The gradient of T is then given by yi + xj. This vector function is plotted below.
Gradient Example 5 : A scalar field is defined by: T = x2y2 for -10 < x,y < 10
The field T is displayed graphically in the figure, wherein the brightness of the image
at a given location is proportional to the magnitude of T at that location
The gradient of T is then given by 2xy2i + 2x2yj. This vector function is plotted below.
Gradient Example 6 : A scalar field is defined by: T = 1 + sin (2px/6) for -10 < x < 10
The field T is displayed graphically in the figure, wherein the brightness of the image
at a given location is proportional to the magnitude of T at that location
The gradient of T is then given by (2p/6) cos(2px/6) i . This vector function is
plotted below.
WHAT IS THE GRADIENT?
No Change
 I I 
 ,   (k ,0)
 x y 
Change
WHAT IS THE GRADIENT?
Change
 I I 
 ,   (0, k )
 x y 
No Change
WHAT IS THE GRADIENT?
Gradient direction is perpendicular
to edge.
Gradient Magnitude measures edge
strength.
 I I 
 ,   (k1, k 2)
 x y 
Much Change
WHAT IS THE GRADIENT?
Edge Profiles
• Sharp discontinuities do not exist in
real images because of low-frequency
components or the smoothing
introduced by image acquisition.
• Step edges become ramp edges, and
line edges become roof edges, where
intensity changes are not
instantaneous but occur over a finite
distance.
• We concentrate on step (ramp) edges
because they are more commonly
encountered.
Edge Profiles
• Step edge: the image intensity abruptly changes
from one value on one side of the discontinuity
to a different value on the opposite side.
Edge Profiles
• Ramp edge: a step edge where the intensity
change is not instantaneous but occur over a
finite distance.
Edge Profiles
• Ridge edge: the image intensity abruptly
changes value but then returns to the starting
value within some short distance (i.e., usually
generated by lines).
Edge Profiles
• Roof edge: a ridge edge where the intensity
change is not instantaneous but occur over a
finite distance (i.e., usually generated by the
intersection of two surfaces).
Edge Detection Using Derivatives
• Often, points that lie on an edge
are detected by:
(1) Detecting the local maxima or
minima of the first derivative.
1st derivative
(2) Detecting the zero-crossings
of the second derivative.
2nd derivative
Image Derivatives
• How can we differentiate a digital image?
– Option 1: reconstruct a continuous image, f(x,y), then
compute the derivative.
– Option 2: take discrete derivative (i.e., finite differences)
Consider this case first!
Edge Detection Using First Derivative
1D functions
(not centered at x)
(centered at x)
(upward) step edge
(downward) step edge
ramp edge
roof edge
Edge Detection Using Second Derivative
• Approximate finding maxima/minima of
gradient magnitude by finding places where:
2
d f
( x)  0
2
dx
• Can’t always find discrete pixels where the
second derivative is zero – look for zerocrossing instead.
Edge Detection Using Second Derivative (cont’d)
1D functions:
f ( x  h)  f ( x)
f ( x)  lim
 f ( x  h)  f ( x) 
h 0
h
f ( x  2)  2 f ( x  1)  f ( x)
(h  1)
(centered at x+1)
Replace x+1 with x (i.e., centered at x):
Derivative filters
¶f
= f (x + 1)- f (x )
¶x
2 f
 f  x  1  f  x   f  x  1  1  f  x  1
2
x
 f  x  1  f  x  1  2 f  x 
A
B
1st Derivative
•The formula for the 1st derivative of a function
is as follows:
f
 f ( x  1)  f ( x)
x
•It’s just the difference between subsequent
values and measures the rate of change of the
function
st
1
Derivative (cont…)
Image Strip
8
7
6
f(x)
5
4
3
2
1
0
5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
Derivative
0 -1 -1 -1 -1 0 0 6 -6 01st 0
0 1 2 -2 -1 0 0 0 7 0 0 0
8
6
4
f’(x)
2
0
-2
-4
-6
-8
2nd Derivative
•The formula for the 2nd derivative of a
function is as follows:
2
d f
 f ( x  1)  f ( x  1)  2 f ( x)
2
dx
•Simply takes into account the values both
before and after the current value
2nd Derivative (cont…)
Image Strip
8
7
6
5
f(x)
4
3
2
1
0
5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
-1 0 0 0 0 1 0 6
10
5
f’’(x)
0
-5
-10
-15
-12 6
0 1
2nd0
Derivative
1 -4 1 1 0 0 7 -7 0 0
st
1
and
nd
2
Derivative
Image Strip
8
7
6
5
f(x)
4
3
2
1
1st Derivative
0
8
6
4
f’(x)
2
0
-2
-4
-6
-8
2nd Derivative
10
5
f’’(x)
0
-5
-10
-15
Noise Suppression
• Consider a single row or column of the image
Where is the edge??
Solution: Smoothing Filter
Where is the edge?
Look for peaks in
Effect Smoothing on Derivates
Where is the edge??
Effect of Smoothing on Derivatives
Combine Smoothing with Differentiation
(i.e., saves one operation)
Main Steps in Edge Detection
(1) Smoothing: suppress as much noise as
possible, without destroying true edges.
(2) Enhancement: apply differentiation to
enhance the quality of edges (i.e., sharpening).
Main Steps in Edge Detection
(3) Thresholding: determine which edge pixels
should be discarded as noise and which
should be retained (i.e., threshold edge
magnitude).
(4) Localization: determine the exact edge
location.
Using Second Derivatives For Image
Enhancement
•The 2nd derivative is more useful for image
enhancement than the 1st derivative
– Stronger response to fine detail
– Simpler implementation
– We will come back to the 1st order derivative later on
•The first sharpening filter we will look at is the
Laplacian
– Isotropic
– One of the simplest sharpening filters
– We will look at a digital implementation
First and Second-order derivative of f(x,y)


We consider an image function of two variables, f(x,y),
We deal with partial derivatives along the two spatial
axes.

f
(
x
,
y
)
f
(
x
,
y
)
f
(
x
,
y
)

f




x

y 
x

y

f
(
x
,y
)
f
(
x
,y
)

f 2  2

x

y
2
2
2
2nd Derivatives – The Laplacian
•The Laplacian is defined as follows:
 f  f
 f  2  2
 x  y
2
2
2
•where the partial 1st order derivative in the x
direction is defined as follows:
2 f
 f ( x  1, y )  f ( x  1, y )  2 f ( x, y )
2
 x
•and in the y direction as follows:
 f
 f ( x, y  1)  f ( x, y  1)  2 f ( x, y)
2
 y
2
2nd Derivatives – The Laplacian
•So, the Laplacian can be given as follows:
 f  [ f ( x  1, y)  f ( x 1, y)
 f ( x, y  1)  f ( x, y  1)]
 4 f ( x, y )
2
•We can easily build a filter based on this
0
1
0
1
-4
1
0
1
0
Basic Edge Detection 1 Step
I ( x, y )
INPUT IMAGE
Horizontal
[-1 0 1]
I ( x , y )
x
Edge
Enhancement
Vertical
[-1 0 1]T

I ( x, y )
y
But what about susceptibility to noise?
Basic Edge Detection 2 Step
I ( x, y )
INPUT IMAGE
1 2 1 
2 4 2 / 16


1 2 1
Noise
Smoothing
Horizontal
[-1 0 1]
I ( x , y )
x
Edge
Enhancement
Vertical
[-1 0 1]T
I ( x, y )
y
d
I
dx
d
I
dy
d  d 
   I   I 
 dx   dy 
2
2
  Threshold  100
d
I
dx
d
I
dy
d  d 
   I   I 
 dx   dy 
2
2
gradient magnitude
low threshold
high threshold
gradient magnitude
low threshold
high threshold
1st Derivative Filtering
• The magnitude of this vector is given by:
f  mag(f )

 G G
2
x
2
y

1
2
 f   f  
      
 x   y  
2
2
1
2
• For practical reasons this can be simplified as:
f  G x  G y
1st Derivative Filtering (cont…)
• Now we want to define digital approximations and their
Filter Masks
• For simplicity we use a 3x3 region
• For example z5 denotes f(x,y), z1 denotes f(x-1,y-1)
• A simple approximation for First Derivative is
z1
z2
z3
z4
z5
z6
z7
z8
z9
1st Derivative Filtering
A simple approximation for First Derivative is
Two other definitions proposed by Roberts use cross- difference
z1
z2
z3
z4
z5
z6
z7
z8
z9
If we use
1st Derivative Filtering
If we use absolute values then
The Masks corresponding to these equations are:
Roberts Cross-Gradient Operators
z1
z2
z3
z4
z5
z6
z7
z8
z9
Gradient Operators
Gradient Operators
Normally the smallest mask used is of size 3 x 3
Based on the concept of approximating the gradient several
spatial masks have been proposed:
Gradient Operators
Questions? Discussion? Suggestions ?
76