You are on page 1of 10

23-09-2023

Neighborhood processing
(Spatial Filtering)

Classification of Spatial Filtering


Spatial Filtering

Smoothing Filters Sharpening Filters

Linear Filters
Linear Filters Non-Linear Filters
(order Statistics filters) Laplacian Filter

Averaging Filters
Median Filter 1st Derivative Filter

Weighted
Averaging Filters Min/ Max Filter High Boost Filter

Linear Filters: If the


operation performed
on image pixels is
linear, than the filter is
called a linear spatial
filter.
23-09-2023
23-09-2023
23-09-2023
23-09-2023

• Equivalent to Low-pass spatial filtering in


Smoothing Spatial Filters frequency domain because smaller (high
frequency) details are removed based on
• Use: Blurring and Noise reduction neighborhood averaging (averaging filters)
• –Blurring Preprocessing steps • Implementation:
• Removal of small details from an image prior to object • –The simplest form of the spatial filter for
extraction. averaging is a square mask (assume m×mmask)
• Bridging of small gaps in lines or curves of the with the same coefficients 1/m2to preserve the
boundaries of object and text. Small gaps in boundary gray levels (averaging).
can lead to enormous results in object extraction. • Applications:
Smoothing fills up all small gaps and helps in producing
correct result. • –Reduce noise; smooth false contours
• –Noise reduction • Side effect:
• e.g. Averaging • –Edge blurring

• Linear filtering is a spatial domain process


where a filter with some coefficient values is
applied to input image to generate the
filtered/ output image. Filter size is either 3x3 • a - Box Filter (Averaging Filter)
or 5x5or 21x21 and filter is centred at a
• b - Weighted Average Filter
coordinate (x,y) called “Hot Spot” as shown in
figure below.

• Linear filtering of an image f(x, y) of size M x N


and filter mask of size m x n is given by
23-09-2023

Result of Smoothing Linear Filters

• Example
• Apply given 3 x 3 mask in fig 3.52 (b) on the
=

given image f(x, y) in fig 3.52(a)

Solution
•First consider top left 3 x 3 neighbourhoods in image f(x, y) fig 3.52(c) with hot spot coinciding with grey level 4 in f(x, y).
•Calculate output for that pixel position by

Replace grey level values 4 by 5 in the output image in fig (d).


23-09-2023

Order-Statistic Filters(Non Linear Filter)


• Order-statistics filters are nonlinear spatial
filters.
• Their response is based on ordering (ranking)
the pixels contained in the image area
encompassed by the filter, and then replacing
the value of the center pixel with the value
determined by the ranking result.
• Best-known Median filter, Max & Min filtering.

Median Filter Averaging Filter Vs. Median Filter Example


• Assigns the mid value of all the gray levels in the
mask to the center of mask
• Effective in the presence of salt & pepper noise
Idea:
• –Force points with distinct gray levels to be more
like their neighbors Original Image Image After Image After
• Outcome: With Noise Averaging Filter Median Filter

• –Isolated clusters of pixel that are light or dark •Filtering is often used to remove noise from
with respect to their neighbors & whose area is images
less than m2/2 are eliminated. •Sometimes a median filter works better than an
averaging filter

Process of Median filter


Averaging Filter Vs. Median Filter Example
23-09-2023

Averaging Filter Vs. Median Filter Example

• Minimum filter:
– Select the lowest pixel value from the ordered set.
– Remove salt-type noise.

Averaging Filter Vs. Median Filter Example Order Filters

Minimum Filter

Image with salt noise Result of minimum filtering


Probability = .04 Mask 3 x 3

Order Filters
• Maximum filter:
– Select the highest pixel value from the ordered
set.
– Remove pepper-type noise.

Minimum filtering Minimum filtering


Mask 5 x 5 Mask 9 x 9
23-09-2023

Order Filters Order Filters


Maximum Filter • Midpoint filter:
– Average of the maximum and minimum within the
window.
– Useful for removing gaussian and uniform noise.

I1  I N 2
Midpoint =
2

Image with pepper noise Maximum filtering


Probability = .04 Mask 3 x 3

Order Filters Order Filters

Maximum filtering Maximum filtering


Mask 5 x 5 Mask 9 x 9 Image with gaussian noise. Result of midpoint filter
Variance = 300, mean = 0 Mask size = 3

Order Filters Order Filters


• Order filters can also be defined to select a
specific pixel rank within the ordered set.
– For example, we may find the second highest
value is the better choice than the maximum value
for certain pepper noise.
– This type of ordered selection is application
specific.
• Minimum filter tend to darken the image and
maximum filter tend to brighten the image.
Image with uniform noise. Result of midpoint filter
Variance = 300, mean = 0 Mask size = 3
23-09-2023

For the image segment f(x, y) given below.


Apply
•Smoothing filter
•Weighted average filter
•Median filter
•Min filter
•Max filter
0 1 0 6 5
2 3 1 2 5
f(x, y) = 1 2 7 5 4
1 0 6 5 2
2 3 5 7 6

For the image segment f(x, y) given below.


Apply
•Smoothing filter
•Weighted average filter
•Median filter
•Min filter
•Max filter
110 157 0 69 52
222 37 123 212 59
f(x, y) = 110 221 77 58 49
231 19 69 89 122
223 73 95 78 69

You might also like