This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
BIM472 Image Processing
Processing in Spatial Domain
Part 2. Spatial Filtering
BIM472 Image Processing 2Processing in Spatial Domain – Spatial Filtering
Outline
• Spatial Filtering Intro
• Spatial Correlation and Convolution
• Smoothing Spatial Filters
– Linear Smoothing Filters
– Nonlinear Smoothing Filters
• Sharpening Filters
– Laplacian Operator
– Unsharp Masking and Highboost Filtering
– Using First-Order Derivatives for Nonlinear Image Sharpening - The
Gradient
• Matlab Example
2
BIM472 Image Processing 3Processing in Spatial Domain – Spatial Filtering
• A spatial filter consists of
(a) a neighborhood
(b) a predefined operation
• Linear spatial filtering of an image of size (M x N) with a filter of size
(m x n) is given by the expression
( , ) ( , ) ( , )a b
s a t b
g x y w s t f x s y t=− =−
= + +∑ ∑
Spatial Filtering Intro
2 1, 2 1m a n b= + = +
BIM472 Image Processing 4Processing in Spatial Domain – Spatial Filtering
Spatial Filtering Intro
(3 x 3) mask
3
BIM472 Image Processing 5Processing in Spatial Domain – Spatial Filtering
• Spatial filtering is actually a correlation or convolution process.
• Correlation is the process of moving a filter mask over the image and
computing the sum of products at each location.
• The mechanics of convolution are the same, except that the filter is first
rotated by 180 degree.
• Correlation and convolution are functions of displacements.
Spatial Correlation and Convolution
BIM472 Image Processing 6Processing in Spatial Domain – Spatial Filtering
The correlation of a filter ( , ) of size
with an image ( , ), denoted as ( , ) ( , )
w x y m n
f x y w x y f x y
×
( , ) ( , ) ( , ) ( , )a b
s a t b
w x y f x y w s t f x s y t=− =−
= + +∑ ∑
Spatial Correlation and Convolution
4
BIM472 Image Processing 7Processing in Spatial Domain – Spatial Filtering
The convolution of a filter ( , ) of size
with an image ( , ), denoted as ( , ) ( , )
w x y m n
f x y w x y f x y
×
( , ) ( , ) ( , ) ( , )a b
s a t b
w x y f x y w s t f x s y t=− =−
= − −∑ ∑
Spatial Correlation and Convolution
BIM472 Image Processing 8Processing in Spatial Domain – Spatial Filtering
Spatial Correlation and Convolution
5
BIM472 Image Processing 9Processing in Spatial Domain – Spatial Filtering
• Smoothing filters are used for blurring and for noise reduction
• Blurring is used in removal of small details and bridging of small
gaps in lines or curves
• Smoothing spatial filters include linear filters and nonlinear filters.
Smoothing Spatial Filters
BIM472 Image Processing 10Processing in Spatial Domain – Spatial Filtering
The general implementation for filtering an M N image
with a weighted averaging filter of size m n is given
( , ) ( , )
( , )
( , )
where 2 1
a b
s a t b
a b
s a t b
w s t f x s y t
g x y
w s t
m a
=− =−
=− =−
×
×
+ +
=
= +
∑ ∑
∑ ∑
, 2 1.n b= +
Linear Smoothing Filters
6
BIM472 Image Processing 11Processing in Spatial Domain – Spatial Filtering
Two Smoothing Averaging Filter Masks
Linear Smoothing Filters
BIM472 Image Processing 12Processing in Spatial Domain – Spatial Filtering
Linear Smoothing Filters
7
BIM472 Image Processing 13Processing in Spatial Domain – Spatial Filtering
Example: Gross Representation of Objects
Linear Smoothing Filters
BIM472 Image Processing 14Processing in Spatial Domain – Spatial Filtering
• Nonlinear (order-statistic)
• Based on ordering (ranking) the pixels contained in the filter mask
• Replacing the value of the center pixel with the value determined
by the ranking result (median, max, min, etc.)
• Median filter is the best known filter for this category. This filter is
particularly effective in the presence of impulse noise (salt-and-
pepper noise).
Nonlinear Smoothing Filters
8
BIM472 Image Processing 15Processing in Spatial Domain – Spatial Filtering
Example:
• Suppose that a 3x3 neigborhood has values
• Median of these values is 20 which is the middle value.
(10, 15, 20, 20, 20, 20, 20, 25, 100)
• Principal function of median filters is to force points with distinct
intensity levels to be more like their neighbors.
Nonlinear Smoothing Filters
10 25 20
20 100 20
20 20 15
BIM472 Image Processing 16Processing in Spatial Domain – Spatial Filtering
Example: Use of Median Filtering for Noise Reduction
Nonlinear Smoothing Filters
9
BIM472 Image Processing 17Processing in Spatial Domain – Spatial Filtering
• The principal objective of sharpening is to highlight transitions in
intensity.
• Uses of image sharpening include applications ranging from
electronic printing and medical imaging to industrial inspection
and autonomous guidance in military systems.
• We know that blurring can be obtained by integration.
• So, we can state that sharpening can be obtained by
differentiation.
Sharpening Filters
BIM472 Image Processing 18Processing in Spatial Domain – Spatial Filtering
• Foundation
• Laplacian Operator
• Unsharp Masking and Highboost Filtering
• Using First-Order Derivatives for Nonlinear Image Sharpening —The Gradient
Sharpening Filters
10
BIM472 Image Processing 19Processing in Spatial Domain – Spatial Filtering
Foundation
• The first-order derivative of a one-dimensional function f(x) is the
difference
• The second-order derivative of f(x) is the difference
( 1) ( )f
f x f xx
∂= + −
∂
2
2( 1) ( 1) 2 ( )
ff x f x f x
x
∂= + + − −
∂
Sharpening Filters
BIM472 Image Processing 20Processing in Spatial Domain – Spatial Filtering
Sharpening Filters
11
BIM472 Image Processing 21Processing in Spatial Domain – Spatial Filtering
Laplace Operator
• The second-order isotropic (rotation invariant) derivative operator is the
Laplacian for a function (image) f(x,y)
2 22
2 2
f ff
x y
∂ ∂∇ = +
∂ ∂2
2( 1, ) ( 1, ) 2 ( , )
ff x y f x y f x y
x
∂= + + − −
∂2
2( , 1) ( , 1) 2 ( , )
ff x y f x y f x y
y
∂= + + − −
∂2 ( 1, ) ( 1, ) ( , 1) ( , 1)
- 4 ( , )
f f x y f x y f x y f x y
f x y
∇ = + + − + + + −
Sharpening Filters
f(x-1, y-1) f(x-1, y) f(x-1, y+1)
f(x, y-1) f(x, y) f(x, y+1)
f(x-1, y-1) f(x+1, y) f(x+1, y+1)
BIM472 Image Processing 22Processing in Spatial Domain – Spatial Filtering
Laplace Operator
Sharpening Filters
12
BIM472 Image Processing 23Processing in Spatial Domain – Spatial Filtering
Image sharpening in the way of using the Laplacian:
2
2
( , ) ( , ) ( , )
where,
( , ) is input image,
( , ) is sharpenend images,
-1 if ( , ) corresponding to Fig. 3.37(a) or (b)
and 1 if either of the other two filters is us
g x y f x y c f x y
f x y
g x y
c f x y
c
= + ∇
= ∇
= ed.
Laplace Operator
Sharpening Filters
BIM472 Image Processing 24Processing in Spatial Domain – Spatial Filtering
Sharpening Filters
13
BIM472 Image Processing 25Processing in Spatial Domain – Spatial Filtering
Unsharp Masking and Highboost Filtering
• Unsharp masking sharpen images by subtracting an unsharp (smoothed)
version of an image from the original image (e.g., printing and publishing
industry)
• Steps
1. Blur the original image
2. Subtract the blurred image from the original (the resulting difference is
called the masks.
3. Add the mask to the original image
Sharpening Filters
BIM472 Image Processing 26Processing in Spatial Domain – Spatial Filtering
Unsharp Masking and Highboost Filtering
Let ( , ) denote the blurred image, unsharp masking is
( , ) ( , ) ( , )
Then add a weighted portion of the mask back to the original
( , ) ( , ) * ( , )
mask
mask
f x y
g x y f x y f x y
g x y f x y k g x y
= −
= + 0k ≥
Sharpening Filters
• When k=1, we have unsharp masking
• When k>1, the process is referred to as high boost filtering
14
BIM472 Image Processing 27Processing in Spatial Domain – Spatial Filtering
Unsharp Masking: Illustration
Sharpening Filters
• Figure 3.39(a) can be
interpreted as a
horizontal scan line
through a vertical
edge that transitions
from a dark to a light
region in an image.
BIM472 Image Processing 28Processing in Spatial Domain – Spatial Filtering
Unsharp Masking and Highboost Filtering: Example
Sharpening Filters
15
BIM472 Image Processing 29Processing in Spatial Domain – Spatial Filtering
Image Sharpening based on First-Order Derivatives
For function ( , ), the gradient of at coordinates ( , )
is defined as
grad( )x
y
f x y f x y
f
g xf f
fg
y
∂ ∂ ∇ ≡ ≡ = ∂ ∂
2 2
The of vector , denoted as ( , )
( , ) mag( ) x y
magnitude f M x y
M x y f g g
∇
= ∇ = +Gradient Image
Sharpening Filters
BIM472 Image Processing 30Processing in Spatial Domain – Spatial Filtering
Image Sharpening based on First-Order Derivatives
z1 z2 z3
z4 z5 z6
z7 z8 z9
2 2
The of vector , denoted as ( , )
( , ) mag ( ) x y
magnitude f M x y
M x y f g g
∇
= ∇ = +
( , ) | | | |x yM x y g g≈ +
8 5 6 5( , ) | | | |M x y z z z z= − + −
Sharpening Filters
( 1) ( )f
f x f xx
∂= + −
∂
16
BIM472 Image Processing 31Processing in Spatial Domain – Spatial Filtering
Image Sharpening based on First-Order Derivatives
z1 z2 z3
z4 z5 z6
z7 z8 z9
9 5 8 6
Roberts Cross-gradient Operators
( , ) | | | |M x y z z z z≈ − + −
7 8 9 1 2 3
3 6 9 1 4 7
Sobel Operators
( , ) | ( 2 ) ( 2 ) |
| ( 2 ) ( 2 ) |
M x y z z z z z z
z z z z z z
≈ + + − + +
+ + + − + +
Sharpening Filters
BIM472 Image Processing 32Processing in Spatial Domain – Spatial Filtering
Image Sharpening based on First-Order Derivatives
Sharpening Filters
17
BIM472 Image Processing 33Processing in Spatial Domain – Spatial Filtering
Example
Sharpening Filters
BIM472 Image Processing 34Processing in Spatial Domain – Spatial Filtering
Example:
Combining Spatial
Enhancement Methods
Goal:
Enhance the image by
sharpening it and by
bringing out more of the
skeletal detail
Sharpening Filters
18
BIM472 Image Processing 35Processing in Spatial Domain – Spatial Filtering
Example:
Combining Spatial
Enhancement Methods
Goal:
Enhance the image by
sharpening it and by
bringing out more of the
skeletal detail
Sharpening Filters
BIM472 Image Processing 36Processing in Spatial Domain – Spatial Filtering
MATLAB Example
• Averaging filter
19
BIM472 Image Processing 37Processing in Spatial Domain – Spatial Filtering
MATLAB Example
BIM472 Image Processing 38Processing in Spatial Domain – Spatial Filtering
MATLAB Example
Edges of the image
• What happens at the edge of the image, where the mask
partly falls outside the image?
Solutions
• Ignore the edges:
– Apply mask excluding the edges.
– Resulting image is smaller than original one.
• Pad with zeros:
– All values outside the image are zero.
– Resulting image is of the same size with the original one.
– Causes unwanted artifacts around the image.
20
BIM472 Image Processing 39Processing in Spatial Domain – Spatial Filtering
MATLAB Example
BIM472 Image Processing 40Processing in Spatial Domain – Spatial Filtering
MATLAB Example
21
BIM472 Image Processing 41Processing in Spatial Domain – Spatial Filtering
MATLAB Example
BIM472 Image Processing 42Processing in Spatial Domain – Spatial Filtering
Some other useful functions:
• imnoise - Add noise to image.
• medfilt2 - 2-D median filtering.
• ordfilt2 - 2-D order-statistic filtering.
MATLAB Example
22
BIM472 Image Processing 43Processing in Spatial Domain – Spatial Filtering
Summary
• Spatial Filtering Intro
• Spatial Correlation and Convolution
• Smoothing Spatial Filters
– Linear Smoothing Filters
– Nonlinear Smoothing Filters
• Sharpening Filters
– Laplacian Operator
– Unsharp Masking and Highboost Filtering
– Using First-Order Derivatives for Nonlinear Image Sharpening - The
Gradient
• Matlab Example
BIM472 Image Processing 44Processing in Spatial Domain – Spatial Filtering
References
• “Digital Image Processing”, 3rd Edition, R. C. Gonzalez &
R. E. Woods, Pearson Prentice Hall.
• “Lecture Notes”, Frank (Qingzhong) Liu, University of New
Mexico Tech.
• “Lecture Notes”, Alasdair McAndrew, Victoria University of