DIGITAL IMAGE PROCESSING
(Course Code: CSE 4007)
Module-2:Lecture-3
SPATIAL DOMAIN FILTERING
Contents
In this lecture we will look at spatial filtering techniques:
• Neighbourhood operations
• What is spatial filtering?
• Correlation and convolution
• Smoothing operations
• What happens at the edges?
• Sharpening filters
• Combining filtering techniques
Spatial Domain Filtering 2
Neighborhood Operations
Neighborhood operations simply Origin x
operate on a larger neighborhood of
pixels than point operations
Neighborhoods are mostly a (x, y)
Neighbourhood
rectangle around a central pixel
Any size rectangle and any shape
filter are possible y Image f (x, y)
Spatial Domain Filtering 3
Simple Neighborhood Operations
Some simple neighborhood operations include:
Min: Set the pixel value to the minimum in the neighborhood
Max: Set the pixel value to the maximum in the neighborhood
Median: The median value of a set of numbers is the midpoint
value in that set (e.g. from the set [1, 7, 15, 18, 24] 15 is the median).
Sometimes the median works better than the average
Spatial Domain Filtering 4
SPATIAL FILTERING
A spatial filter consists of (a) a neighborhood, and (b) a
predefined
Origin operation x
a b c r s t
d
g
e
h
f
i
* u
x
v
y
w
z
Original Image Filter
Simple 3*3 Pixels
e 3*3 Filter
Neighbourhood
eprocessed = v*e +
r*a + s*b + t*c +
u*d + w*f +
y Image f (x, y) x*g + y*h + z*i
Spatial Domain Filtering 5
SPATIAL FILTERING-EQUATION FORM
The above is repeated for every pixel in
the original image to generate the
filtered image.
• Filtering can be given in equation form
as shown below
• Notations are based on the image
shown to the left
a b
g ( x, y ) w( s, t ) f ( x s, y t )
s at b
Spatial Domain Filtering 6
2D- FILTERING
f
1 1 1 0 0
0 1 1 1 0
0 0 1 1 1
0 0 1 1 0
0 1 1 0 0
w 1 0 1
0 1 0
1 0 1
Output image size without padding = image size (M) – filter size (m) + 1
=5–3+1=3
7
Spatial Domain Filtering 7
2D- FILTERING
8
Spatial Domain Filtering 8
SPATIAL CORRELATION
The correlation of a filter w( x, y ) of size m n
with an image f ( x, y ), denoted as w( x, y ) f ( x, y )
a b
w( x, y ) f ( x, y ) w(s, t ) f ( x s, y t )
s a t b
9
Spatial Domain Filtering 9
SPATIAL CONVOLUTION
The convolution of a filter w( x, y) of size m n
with an image f ( x, y ), denoted as w( x, y) f ( x, y)
a b
w( x, y ) f ( x, y ) w( s, t ) f ( x s, y t )
s a t b
10
Spatial Domain Filtering 10
CORRELATION & CONVOLUTION-1D
Illustration of 1-D correlation and
convolution of a kernel, w, with a
function f consisting of a discrete unit
impulse. Note that correlation and
convolution are functions of the variable
x, which acts to displace one function
with respect to the other. For the
extended correlation and convolution
results, the starting configuration places
the rightmost element of the kernel to be
coincident with the origin of f.
Additional padding must be used.
11
Spatial Domain Filtering 11
CORRELATION & CONVOLUTION-2D Without Padding
06/16/2025 Spatial Domain Filtering 12
12
CORRELATION & CONVOLUTION-2D With Padded Zeros
06/16/2025 Spatial Domain Filtering 13
13
06/16/2025 Spatial Domain Filtering 14
14
Pixel Relationships 15