0% found this document useful (0 votes)
7 views

Chapter 3 - Filtering - 3

The document discusses spatial filtering techniques in machine vision. It describes how spatial filtering works by applying a filter kernel to neighborhoods of pixels. Common spatial filters include averaging, median, and order-statistics filters which are used to reduce noise or sharpen images. Methods like padding and replication are used to handle border pixels during filtering.

Uploaded by

2021002467.gcet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Chapter 3 - Filtering - 3

The document discusses spatial filtering techniques in machine vision. It describes how spatial filtering works by applying a filter kernel to neighborhoods of pixels. Common spatial filters include averaging, median, and order-statistics filters which are used to reduce noise or sharpen images. Methods like padding and replication are used to handle border pixels during filtering.

Uploaded by

2021002467.gcet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

COURSE CODE: 102100605

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

• Sharpening Spatial Filters


– First derivative
– Second Derivative
• Avg filter: For g(x,y) take the average of
neighborhood centered about f(x,y).
• Weighted Avg: For g(x,y) take the Weighted
average of neighborhood centered about
f(x,y).
Smoothing Filters
• Smoothing filters are used for blurring and
for noise reduction
• Removal of small details in an image prior to
large object extraction
• Bridging of small gaps in lines and curves
• Smoothing false contouring
Smoothing Linear Filters
• The output of smoothing, linear spatial filter
is simply the average of the pixels contained
in the neighborhood of the filter mask.
• Averaging filters or low pass filters
• It replaces the value of every pixel in an
image by the average of the gray levels in
the neighborhood defined by the filter mask.
• This reduces sharp transitions in gray levels
• Random noise typically consists of Sharp
transitions in gray levels, so it will be
reduced by average filter.
• Edges also belong to sharp transition in gray
level, so filters blur the edges
Box filter and Weighted Average
Filter
Generalized equation
• C = CONV2(A, B) performs the 2-D
convolution of matrices
• A and B. If [ma,na] = size(A) and
[mb,nb] = size(B), then
• size(C) = [ma+mb-1,na+nb-1].
• 'full' - (default) returns the full 2-D convolution,
• 'same' - returns the central part of the convolution
that is the same size as A.
• 'valid' - returns only those parts of the convolution
that are computed without the zero-padded edges.
size(C) = [ma-mb+1,na-nb+1] when all(size(A) >=
size(B)), otherwise C is empty.
Different mask Sizes
• Minimum Filter: For g(x,y) take the
Minimum of neighborhood centered about
f(x,y).
• Maximum Filter: For g(x,y) take the
Maximum of neighborhood centered about
f(x,y).
• Median Filter: For g(x,y) take the Median of
neighborhood centered about f(x,y).
200 222 189 199 221

199 221 180 199 221

210 232 0 210 232

220 250 199 221 222

223 190 210 232 235 100 98 100 98 100

90 98 90 98 90

89 88 250 99 89

88 97 88 92 88
200 222 189 199 221

199 221 180 199 221

210 232 0 210 232

220 250 199 221 222

223 190 210 232 235 100 98 100 98 100

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

You might also like