Digital Image Processing
Intensity Transformation and Spatial
Filtering
Prepared By: Dr. Anirban Bose
Dept. of CSE
Dr. B. C. Roy Engineering College, Durgapur
Spatial Filtering
A spatial filter consists of (a) a neighborhood, and
(b) a predefined operation
Linear spatial filtering of an image of size MxN with
a filter of size mxn is given by the expression
a b
w( x, y ) f ( x, y ) w( s, t ) f ( x s, y t )
s a t b
2
Spatial Filtering
3
1 -1
-2 3
11 3 6 1 -1 11 3 6
9 5 7 -2 3 9 5 7
8 2 2 Kernel 8 2 2
Spatial
Image 1 -1 Filtering 11x1+3x(-1)+9x(-2)+5x3
-2 3 =5
11 3 6 11 3 6
9 5 7 9 5 7
8 2 2 8 2 2
1 -1
-2 3
3x1+6x(-1)+5x(-2)+7x3 =
8
11 3 6 5x1+7x(-1)+2x(-2)+2x3 = 0
9 5 7
5 8
8 2 2
1 -1 -6 0
-2 3
Filtered
Image
9x1+5x(-1)+8x(-2)+2x3 = -
6 4
5
6
Smoothing Spatial Filters
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.
9
Spatial Smoothing Linear Filters
The general implementation for filtering an M N image
with a weighted averaging filter of size m n is given
a b
w(s, t ) f ( x s, y t )
g ( x, y ) s a t b a b
w( s, t )
s a t b
where m 2a 1, n 2b 1.
10
Two Smoothing Averaging Filter Masks
11
Order-statistic Filters
— Nonlinear
— 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.
E.g., median filter, max filter, min filter
14
15
Sharpening Spatial Filters
► To highlight finer details in an image or to enhance
detail that has been blurred, either due to some
error or as a natural effect of a particular method of
image acquisition.
► Foundation
► Laplacian Operator
► Unsharp Masking and High-boost Filtering
► Using First-Order Derivatives for Nonlinear Image
Sharpening — The Gradient
16
Sharpening Spatial Filters: Foundation
► The first-order derivative of a one-dimensional
function f(x) is the difference
f
f ( x 1) f ( x)
x
► The second-order derivative of f(x) as the difference
2 f
2
f ( x 1) f ( x 1) 2 f ( x)
x
17
18
Sharpening Spatial Filters: Laplace Operator
The second-order isotropic derivative operator is the
Laplacian for a function (image) f(x,y)
2 2
2 f f
f 2 2
x y
2 f
2
f ( x 1, y ) f ( x 1, y ) 2 f ( x, y )
x
2 f
2
f ( x, y 1) f ( x, y 1) 2 f ( x, y )
y
2 f f ( x 1, y ) f ( x 1, y ) f ( x, y 1) f ( x, y 1)
- 4 f ( x, y )
19
Sharpening Spatial Filters: Laplace Operator
20
Sharpening Spatial Filters: Laplace Operator
Image sharpening in the way of using the Laplacian:
𝑔(𝑥,𝑦)=𝑓(𝑥,𝑦)+𝑐 [ ∇ 𝑓(𝑥,𝑦)] 2
If the center coefficient of
the Laplacian mask is
{
2 negative
𝑓 ( 𝑥 , 𝑦 ) − ∇ 𝑓 (𝑥 , 𝑦)
𝑔 ( 𝑥 , 𝑦 )= 2
𝑓 ( 𝑥 , 𝑦 ) +∇ 𝑓 (𝑥 , 𝑦 )
If the center coefficient of
the Laplacian mask is
positive
21
Blurred Image of
North Pole of Moon
Laplacian with Laplacian without
scaling scaling
Sharpened Sharpened
Image using Image using
Laplacian with Laplacian with-
scaling Out scaling
22
Unsharp Masking and Highboost Filtering
► Unsharp masking
Sharpen images consists of 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
3. Add the mask to the original
23
Unsharp Masking and Highboost Filtering
Let f ( x, y ) denote the blurred image, unsharp masking is
g mask ( x, y ) f ( x, y ) f ( x, y )
Then add a weighted portion of the mask back to the original
g ( x, y ) f ( x, y ) k * g mask ( x, y ) k 0
when k 1, the process is referred to as highboost filtering.
24
Unsharp Masking and Highboost Filtering:
Example
25
Image Sharpening based on First-Order
Derivatives
For function f ( x, y ), the gradient of f at coordinates ( x, y )
is defined as
f
g x x
f grad( f )
g y f
y
The magnitude of vector f , denoted as M ( x, y)
Gradient Image M ( x, y) mag(f ) g x 2 g y 2
M ( x, y ) | g x | | g y |
26
Image Sharpening based on First-Order
Derivatives
Roberts Cross
Gradient Operators
Sobel
Operators
29
Sobel Roberts Example
30
Example:
Combining
Spatial
Enhancement
Methods
Goal:
Enhance the
image by
sharpening it
and by
bringing out
more of the
skeletal detail
31
Example:
Combining
Spatial
Enhancement
Methods
Goal:
Enhance the
image by
sharpening it
and by
bringing out
more of the
skeletal detail
32