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

Spatial Filtering ppt1

The document discusses various topics related to digital image processing, including image sampling and quantization, representing digital images, histogram processing, fundamentals of spatial filtering and image enhancement. It covers spatial filtering techniques like smoothing filters, which are used to reduce noise and blur images. Specifically, it describes linear smoothing filters like averaging filters, which replace each pixel value with the average of neighboring pixel values. This helps reduce noise but can also blur edges in an image.

Uploaded by

musicstand29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Spatial Filtering ppt1

The document discusses various topics related to digital image processing, including image sampling and quantization, representing digital images, histogram processing, fundamentals of spatial filtering and image enhancement. It covers spatial filtering techniques like smoothing filters, which are used to reduce noise and blur images. Specifically, it describes linear smoothing filters like averaging filters, which replace each pixel value with the average of neighboring pixel values. This helps reduce noise but can also blur edges in an image.

Uploaded by

musicstand29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 66

Unit I

Background
Fundamental steps and Components of Digital
Image Processing
Image Sampling and Quantization: Basic concepts
in Sampling and Quantization
Representing Digital images, Spatial and intensity
resolution
Relationship between Pixels
Histogram Processing: Definition, Histogram
Equalization

By Prof. Datta Deshmukh


Unit II
Fundamentals of Spatial Filtering‐ The Mechanics of
Image Enhancement

Spatial Filtering
Generating Spatial, Filter Masks, Noise Model
Smoothing Spatial Filters: Linear filters – Mean filters
Non‐linear (Order Statistic filters): Median, Mode,
Max, Min filters,
Image Enhancement by Frequency Domain Methods:
Basic steps for Filtering in Frequency Domain
Frequency Domain low pass (Smoothing), High pass
(Sharpening)

By Prof. Datta Deshmukh


Image Enhancement in Spatial
Domain (Neighbourhood Processing)

By Prof. Datta Deshmukh


Spatial domain Image Enhancement
Image Enhancement

Spatial Domain
(image plane) Frequency Domain

Point Processing Neighbourhood


Processing

•Image Negative
•Log Transformation
•Powerlaw Transformation
•Contrast stretching
•Gray level Slicing
•Bit plane slicing
•Histogram Based Processing Techniques
• Histogram equalisation
By Prof. Datta Deshmukh
• Histogram specification
Spatial domain Image Enhancement
Image Enhancement

Spatial Domain
Frequency Domain
(image plane)

Neighbourhood
Point Processing
Processing

• g(x,y) depends the values of neighbours of f(x,y)


• Used in techniques
Image smoothing (Low pass Filtering)
Image Sharpening (High pass Filtering)

It is also called Spatial Filtering


By Prof. Datta Deshmukh
Spatial Filtering
Filtering refers to passing or rejecting certain frequency components

Low frequency region

High frequency region


Low frequency region

By Prof. Datta Deshmukh


Filtering
It creates new pixel with coordinate
equal to the coordinates of the center of
the neigborhood and whose value is the
result of filtering operation.
If operation performed on image pixel is
linear, then filter is called linear filter
otherwise the filter is non linear filter.

By Prof. Datta Deshmukh


Simple Neighbourhood operations (Linear or
non linear)
Some simple neighbourhood operations include:
 Average: Set the pixel value to the average of neighborhood
(Linear Operation)
Min: Set the pixel value to the minimum in the neighborhood
(Non Linear Operation)
Max: Set the pixel value to the maximum in the neighborhood
(Non Linear Operation)
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.
(Non Linear Operation)

By Prof. Datta Deshmukh


Linear/ Nonlinear operations
Let H be an operator that produces an output image g(x,y), for a
given input image f(x,y).
H[f(x,y)]=g(x,y)
H is said to be linear if for any two images f1 and f2 :
H[a1f1(x,y) + a2f2(x,y)] = a1 H[f1(x,y)] + a2H[f2(x,y)]

a1H(f1)
a1 f1 H a1H(f1)+a2H(f2)
f1 +
+ H f2 H
H(a1f1+f2a2) a2H(f2)
f2 a2

By Prof. Datta Deshmukh


Basics of Mask Processing

filter (can also be called W(-1,-1) W(-1,0) W(-1,1)

mask/kernel/template or window)
the values in a mask/filter (subimage) are W(0,-1) W(0,0) W(0,1)

referred to as coefficients, rather than


pixel. W(1,-1) w(1,0) W(1,1)

our focus will be on masks of odd sizes,


e.g. 3x3, 5x5,…

By Prof. Datta Deshmukh


Mechanism of linear spatial filtering
• If the operation performed on
image pixels is linear, then filter is
called linear filter otherwise it is
non linear.
• At each point (x,y), the response,
g(x,y), of the filter is Sum of
product of filter coeff. and image
pixels

Response R, at (x,y) if given by

g ( x, y )  w(1, 1) f ( x  1, y  1)  w(1, 0) f ( x  1, y )  ...


By Prof. Datta Deshmukh w(0, 0) f ( x, y )  ...  w(1,1) f ( x  1, y  1)
Mechanism of linear spatial filtering
g ( x, y )  w(1, 1) f ( x  1, y  1)  w(1, 0) f ( x  1, y )  ...
 w(0, 0) f ( x, y )  ...  w(1,1) f ( x  1, y  1)

It can be written as

1 1
g ( x, y )    w(s, t ) f ( x  s, y  t )
s  1 t  1

By Prof. Datta Deshmukh


Types of Spatial Filtering

• Smoothing Spatial Filters (LPF)


• Averaging Filter (Linear filters)
• Median filter (non linear filters)
• Sharpening Spatial Filters (HPF)

By Prof. Datta Deshmukh


Smoothing Spatial Filters
• Used for blurring and for noise reduction.
• Blurring is used in preprocessing steps, such as
– removal of small details from an image prior to
object extraction
– bridging of small gaps in lines or curves

By Prof. Datta Deshmukh


Noise
Noise: Image noise is random (not present in the object imaged)
variation of brightness or color information in images.
source of noise: During image acquisition and during transmission.
Major types of Noise:
1. Salt and Pepper noise
2. Gaussian Noise

By Prof. Datta Deshmukh


Salt and Peeper Noise
• An image containing salt-and-
pepper noise will have dark pixels
in bright regions and bright pixels
in dark regions.
• This type of noise can be caused
by ADC errors or bit errors in
transmission.

•Noise pixels in image are very


different in color or intensity from
their surrounding pixels.
By Prof. Datta Deshmukh
Gaussian Noise
Each pixel in the image will be changed from its original
value by a (usually) small amount.

By Prof. Datta Deshmukh


Types of Smoothing Spatial Filters
Smoothing Spatial Filters (Low Pass Filters)

Linear Filters NonLinear Filters

Averaging/Mean Median/Min/Max

By Prof. Datta Deshmukh


Smoothing Linear Filters(LPF)

These filters are called Averaging filters


LPF means passes low frequency components and
removes high frequency components
It reduces the sharp transitions in gray level

random noise in the image


edges of objects in the image
thus, smoothing can reduce noise (desirable) and
blur edges (undesirable)
By Prof. Datta Deshmukh
Averaging Filters
The basic idea is replacing the value of every
pixel in an image by the average of gray levels
in the neighborhood defined by filter mask

104 100 108 1 1 1 104 100 108


99 106 98

95 90 85
* 1/9
1 1 1 99 98 98

1 1 1 95 90 85
Original Image Filter
Pixels

f(x,y)=(1/9)*(104+100+108+99+106+98+95+90+85)=98.33
By Prof. Datta Deshmukh
Averaging Filters: Equation form

Thus the linear filtering of an image f of size M X N with


filter mask of size m x n is given by

a b

  w(s, t ) f ( x  s, y  t )
g ( x, y )  s  a s  b
a b

  w(s, t )
s  a s  b

By Prof. Datta Deshmukh


Averaging Filters

1 1 1
(1/9) X 1 1 1 3 X 3 Averaging Mask

1 1 1

1 1 1 1 1
1 1 1 1 1
(1/25) X 1 1 1 1 1 Similarly we can have 5 X5 or 7 X 7 Masks

1 1 1 1 1
1 1 1
By Prof. Datta Deshmukh 1 1
Strange Things Happen At The Edges!

At the edges of an image we are missing pixels


to form a neighbourhood
Origin x
e e

e e e
By Prof. Datta Deshmukh
y Image f (x, y)
Strange Things Happen At The Edges!
There are a few approaches to dealing with
missing edge pixels:
Omit missing pixels
Pad the image
Typically with either all white or all black pixels
Replicate border pixels

By Prof. Datta Deshmukh


Strange Things Happen At The Edges!
Omit missing pixels

Origin x

By Prof. Datta Deshmukh


y Image f (x, y)
Strange Things Happen At The Edges!

Filtered Image:
Zero Padding

Original
Image

Filtered Image:
Replicate Edge Pixels
Strange Things Happen At The Edges!
Strange Things Happen At The Edges!
Example
10 10 10 10 10 10
1 1 1
10 10 10 10 10 10

(1/9) X 1 1 1
10 10 10 10 10 10

50 50 50 50 50 50 1 1 1

50 50 50 50 50 50

50 50 50 50 50 50

By Prof. Datta Deshmukh


Example
10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10

50 50 50 50 50 50 50 50

50 50 50 50 50 50 50 50

50 50 50 50 50 50 50 50 50 50 50 50

Resultant Image
By Prof. Datta Deshmukh
Example
10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10

50 50 50 50 50 50 50 50

50 50 50 50 50 50 50 50

50 50 50 50 50 50 50 50 50 50 50 50
Resultant Image

By Prof. Datta Deshmukh


Example

10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10

50 50 50 50 50 50 50 50

50 50 50 50 50 50 50 50

50 50 50 50 50 50 50 50 50 50 50 50

By Prof. Datta Deshmukh


Resultant Image
Example
10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 23.3 10

50 50 50 50 50 50 50 50

50 50 50 50 50 50 50 50

50 50 50 50 50 50 50 50 50 50 50 50

By Prof. Datta Deshmukh


Resultant Image
Example
10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 23.3 23.3 23.3 23.3 10

50 50 50 50 50 50 50 36.6 50

50 50 50 50 50 50 50 50

50 50 50 50 50 50 50 50 50 50 50 50

By Prof. Datta Deshmukh


Resultant Image
Example
10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 23.3 23.3 23.3 23.3 10

50 50 50 50 50 50 50 36.6 36.6 50

50 50 50 50 50 50 50

50 50 50 50 50 50 50 50 50 50 50 50

Resultant Image
By Prof. Datta Deshmukh
Example
10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 23.3 23.3 23.3 23.3 10

50 50 50 50 50 50 50 36.6 36.6 36.6 36.6 50

50 50 50 50 50 50 50

50 50 50 50 50 50 50 50 50 50 50 50

By Prof. Datta Deshmukh Resultant Image


Example
10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 23.3 23.3 23.3 23.3 10

50 50 50 50 50 50 50 36.6 36.6 36.6 36.6 50

50 50 50 50 50 50 50 50 50

50 50 50 50 50 50 50 50 50 50 50 50

By Prof. Datta Deshmukh Resultant Image


Example
10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 23.3 23.3 23.3 23.3 10

50 50 50 50 50 50 50 36.6 36.6 36.6 36.6 50

50 50 50 50 50 50 50 50 50 50 50 50

50 50 50 50 50 50 50 50 50 50 50 50

Resultant Image
These kinds ofDatta
By Prof. averaging
Deshmukh filters are excellent when the image contains Gaussian
Noise
Image corrupted by Image after noise
Gaussian Noise reduction by averaging
filter
By Prof. Datta Deshmukh
Original image Noisy image (salt and Image after applying
pepper noise) averaging filter

By Prof. Datta Deshmukh


Image Smoothing Example
a) original image 500x500 pixel
(a) (b) b) - f) results of smoothing with square
averaging filter masks of size n = 3, 5, 9,
15 and 35, respectively.
 The black squares at top of size
3,5,9,15,25,35,45,55 pixels. Their
borders are 25 pixels apart.
 Letters at bottom range in size from 10 to
24
(c)  Larger letter is 60 points
(d)
 Vertical bars are 5 pixels wide and 100
pixels high. Their separation is 20 pixels
 Diameter of circles is 25 pixels and
borders are 15 pixels apart. Intensity
(e) (f)
levels range from 0% to 100% black in
increments of 20%.
 Noisy rectangles are of size 50 X 120
By Prof. Datta Deshmukh pixels 43
Image Smoothing Example

By Prof. Datta Deshmukh


Image Smoothing Example

By Prof. Datta Deshmukh


Image Smoothing Example

By Prof. Datta Deshmukh


Image Smoothing Example

By Prof. Datta Deshmukh


Image Smoothing Example

By Prof. Datta Deshmukh


Image Smoothing Example

By Prof. Datta Deshmukh


Other Average filtering masks
Weighted Average Filter Mask

The center pixel of the mask is multiplied by


higher value than other, thus giving more
importance in calculation of the average and
reducing the blurring in smoothing process.

0 1 0 1 2 1

(1/6) X 1 2 1 (1/16) X 2 4 2

0 1
By Prof. Datta Deshmukh
0 1 2 1
Disadvantages of Linear Filters....
Linear filters (Averaging filter) removes the
noise by blurring it but it also blurs the edges.
Bigger the mask more is blurring.
If image contain Salt and peeper noise
averaging filter blurs the noise but also blurs the
edges.
Because of this blurring, linear filters are
seldom used in practice for noise reduction.

To remove salt and peeper noise order


By Prof. Datta Deshmukh
Order Statistic or Non linear smoothing filters
The response is based on ordering (ranking)
the pixels contained within the mask, and then
replacing the value of center pixel with the
value determined by ranking result.
The mask used is empty mask. i.e working
directly with 8 neighbors of centre pixel
example
median filter : R = median{z |k = 1,2,…,n x n}
k
max filter : R = max{z |k = 1,2,…,n x n}
k
min filter : R = min{z |k = 1,2,…,n x n}
k

TheBybest
Prof. Dattaexample
Deshmukh is Median Filter 52
Steps to perform Median Filtering

Assume m X m empty mask.


Place empty mask at start of an image.
Arrange 9 pixel values in ascending order.
Choose median from these 9 values.
Replace center pixel with median.
Move the mask same as averaging filter.

By Prof. Datta Deshmukh


Median Filtering Example

order (0, 2, 3, 3, 4, 6, 10, 19, 97) Median : 4

original
By Prof. Datta image
Deshmukh with noise 3x3 median filtered 54
Example
Before Filtering
10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10
10 250 10 10 10 10 10 10
10 10 10 10 10 10 10 10
50 50 50 50 50 250 50 50
50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50
By Prof. Datta Deshmukh
Median Filtering Example
After Filtering
10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10
50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50
50 50 50 50 50 50 50 50
By Prof. Datta Deshmukh
Function of Median Filtering

To force points with distinct gray


levels to be more like their
neighbors.

By Prof. Datta Deshmukh


Averaging Filter Vs. Median Filter Example

Original Image Image After Image After


With Noise Averaging Filter Median Filter

Filtering is often used to remove noise from images.


Sometimes a median filter works better than an averaging
filter
By Prof. Datta Deshmukh
Averaging Filter Vs. Median Filter Example

Original

By Prof. Datta Deshmukh


Averaging Filter Vs. Median Filter Example

Averaging
Filter

By Prof. Datta Deshmukh


Averaging Filter Vs. Median Filter Example

Median
Filter

By Prof. Datta Deshmukh


Max Filter
Max: Set the pixel value to the maximum in the neighborhood (Non
Linear Operation)

Useful in finding the brightest points in an Image.

Max filter : R = max{zk |k = 1,2,…,n x n}


The response of 3 X 3 max filter
R = max{zk |k = 1,2,…,9}

Used to reduce the pepper noise.


By Prof. Datta Deshmukh
Max Filter

By Prof. Datta Deshmukh


Min Filter
Min: Set the pixel value to the minimum in the neighborhood (Non
Linear Operation

Useful in finding the Darkest points in an Image.

Min filter : R = min{zk |k = 1,2,…,n x n}


The response of 3 X 3 max filter
R = min {zk |k = 1,2,…,9}

Used to reduce the Salt noise.


By Prof. Datta Deshmukh
Min Filter

By Prof. Datta Deshmukh


Basic steps for filtering in
the frequency domain

By Prof. Datta Deshmukh


Basic steps for filtering in the frequency domain

By Prof. Datta Deshmukh


67
Basics of filtering in the frequency domain

1. multiply the input image by (-1)x+y to center the


transform to u = M/2 and v = N/2 (if M and N are
even numbers, then the shifted coordinates will be
integers)
2. computer F(u,v), the DFT of the image from (1)
3. multiply F(u,v) by a filter function H(u,v)
4. compute the inverse DFT of the result in (3)
5. obtain the real part of the result in (4)
6. multiply the result in (5) by (-1)x+y to cancel the
multiplication of the input image
By Prof. Datta Deshmukh
68

You might also like