Chapter 3 - Filtering - 3
Chapter 3 - Filtering - 3
MACHINE VISION
Dr. AJAY M PATEL
MECHATRONICS DEPARTMENT
Chapter 3
Spatial Filtering
Filtering?
• Removing noise (unwanted data) or
highlighting specific detail in an image using
sub image is called filtering
• Can be done both in frequency domain &
spatial domain
• Subimage is operated on neighborhood of
each pixel
• Subimage is called filter, kernel, mask
• Values in subimage are called coefficients
Filtering Process
• Filter mask is moved from point to point in
an image.
• At each point (x,y), the response of filter is
calculated using predefined relationship
• For gray value at any g(x,y) location in the
output image, process the neighborhood of
the input image centered at (x,y) using a
filter w.
• Size of neighborhood considered depends
on ……….?
• Image size, f: M X N, filter size, w: m x n
Output Image g
0 0 0 0 0
0 0
0 0
0 0
0 0 0 0 0
Output Image g
0 0 0 0 0
0 0
0 0
0 0
0 0 0 0 0
1 1 1
5 8 10 2 3
1 1 1
1 1 1 6 7 1 3 7
2 8 11 20 10
10 87 56 20 7
31 47 52 36 10
1 1 1
5 8 10 2 3
1 1 1
1 1 1 6 7 1 3 7
2 8 11 20 10
10 87 56 20 7
31 47 52 36 10
Conv2
A = zeros(5);
A(:) = 1:25;
%KERNEL/MASK/FILTER
avg3 = ones(3)/9;
%CONVOLUTION
Result = conv2(A,avg3,'same');
display(Result);
How to do filtering for border pixels?
• 3 ways
1. Move center of mask always less than
(n-1)/2 pixels from the border
2. Padding input image with 0
3. Replicating Rows & Columns
Spatial Filters
• Smoothing Spatial Filters
– Smoothing Linear Filters
• Average Filter
• Weighted Average Filter
– Order-Statistics Filters
• Median Filter
• Minimum Filter
• Maximum Filter
90 98 90 98 90
89 88 250 99 89
88 97 88 92 88
200 222 189 199 221
90 98 90 98 90
89 88 250 99 89
88 97 88 92 88
Order-Statistics Filters
• These are non linear spatial filters
• Response of filter is based on ordering
(ranking) the pixels contained in the image
area encompassed by the filter
• Centre pixel value is replaced by ranking
result
Types
• Min filter
• Max Filter
• Median Filter
Min Filter
• For any pixel at (x, y) consider n x n
neighborhood
• Sort pixel values
• Place the lowest (minimum) gray value in
the output image at location (x, y)
• Repeat this process for all pixels
• Good in removing salt noise
Max Filter
• For any pixel at (x, y) consider n x n
neighborhood
• Sort pixel values
• Place the highest (maximum) gray value in
the output image at location (x, y)
• Repeat this process for all pixels
• Good in removing pepper noise
Median Filter
• For any pixel at (x, y) consider n x n
neighborhood
• Sort pixel values
• Place the median gray value in the output
image at location (x, y)
• Repeat this process for all pixels
• Good in removing salt & pepper noise
• Median value for 3 x 3 filter is value at
location 5 after sorting 9 pixels.
Topics not in course
• 3.3.3 – Local enhancement
• 3.3.4 – Use of Histogram Statistics for Image
Enhancement