SlideShare a Scribd company logo
COMPUTER GRAPHICS & IMAGE PROCESSING
COM2304
Intensity Transformation and Spatial Filtering – II
Spatial Filtering and Smoothing
K.A.S.H.Kulathilake
B.Sc. (Hons) IT (SLIIT), MCS (UCSC), M.Phil (UOM), SEDA(UK)
Rajarata University of Sri Lanka
Faculty of Applied Sciences
Department of Physical Sciences
Learning Outcomes
COM2304 - Computer Graphics & Image
Processing
• At the end of this lecture, you should be
able to;
– describe the fundamentals of spatial filtering.
– generating spatial filter masks.
– identify smoothing via linear filters and non
linear filters.
– apply smoothing techniques for problem
solving.
Filters in Image Processing
• Filter can accept or reject certain frequency
components.
• In image processing filters are mainly used to
suppress either the high frequencies in the
image, i.e. smoothing the image, or the low
frequencies, i.e. enhancing/ sharpening or
detecting edges in the image.
• An image can be filtered either in the
frequency or in the spatial domain.
COM2304 - Computer Graphics & Image
Processing
Fundamentals of Frequency
Domain Filtering
• Frequency domain filtering involves ;
– transforming the image into the
frequency domain,
– multiplying it with the frequency
filter function and
– re-transforming the result into the
spatial domain.
• The filter function is shaped so as to
attenuate some frequencies and
enhance others.
• For example, a simple lowpass function
is 1 for frequencies smaller than the
cut-off frequency and 0 for all others.
COM2304 - Computer Graphics & Image
Processing
Fundamentals of Spatial Filtering
• Spatial filter contains two components;
– MASK/ CONVOLUTION MATRIX/ KERNEL: A neighborhood
(typically small rectangle:)
– FILTER FUNCTION: A predefined operation that is performed
on the image pixels encompassed by the neighborhood.
• Spatial filtering is the method of choice in situations when only
additive random noise is present.
• Filtering creates a new pixel value with coordinates equal to the
coordinates of the center of the neighborhood, and whose value
is the result of the filtering operation.
COM2304 - Computer Graphics & Image
Processing
Fundamentals of Spatial Filtering
(Cont….)
COM2304 - Computer Graphics & Image
Processing
Fundamentals of Spatial Filtering
(Cont….)
COM2304 - Computer Graphics & Image
Processing
If the operation
performed on the image
pixels is linear, then the
filter is called a linear
spatial filter, otherwise,
the filter is non-linear.
Fundamentals of Spatial Filtering
(Cont….)
• Spatial filtering of an image of size M×N with a filter of size
m×n is given by the expression;
• Where w is the mask and f is the image function, x and y
are varied so that each pixel in w visits every pixel in f.
• m = 2a+1 and n = 2b+1, where a and b are positive
integers.
• This concept is known as correlation.
COM2304 - Computer Graphics & Image
Processing
Fundamentals of Spatial Filtering
(Cont….)
• There are two closely related concepts that
must be understood clearly when performing
linear spatial filtering
– Correlation
• Correlation is the process of moving a filter mask over
the image and computing the sum of products at each
location exactly as explained previously.
– Convolution
• The mechanics of convolution are the same as
correlation except that the filter is first rotated by 180
degrees.
COM2304 - Computer Graphics & Image
Processing
Fundamentals of Spatial Filtering
(Cont….)
COM2304 - Computer Graphics & Image
Processing
If the filter mask is symmetric, correlation and convolution
yield the same result
Mask/Kernel/ Convolution Matrix
• In image processing, a kernel, convolution
matrix, or mask is a small matrix.
• It is useful for blurring, sharpening,
embossing, edge detection, and more.
• This is accomplished by means of convolution
between a kernel and an image.
COM2304 - Computer Graphics & Image
Processing
Mask/Kernel/ Convolution Matrix
(Cont…)
• Important Features of
Kernel
– Size: 3×3, 5×5, 9×9,
21×21
– Shape: rectangle, cross,
strip, circular, diamond
or user defined.
– Coefficients / Values:
set based on the
operation.
– Anchor point: mostly in
middle
COM2304 - Computer Graphics & Image
Processing
0 -1 0
-1 5 -1
0 -1 0
3×3 Kernel
Anchor
Values for
sharpening
operation
Mask/Kernel/ Convolution Matrix
(Cont…)
COM2304 - Computer Graphics & Image
Processing
0 -1 0
-1 5 -1
0 -1 0
Kernel
Mask/Kernel/ Convolution Matrix
(Cont…)
COM2304 - Computer Graphics & Image
Processing
http://setosa.io/ev/image-kernels/
https://en.wikipedia.org/wiki/Kernel_(image_processing)
Convolution
• Convolution is a simple mathematical
operation which is fundamental to many
common image processing operators.
• This can be used in image processing to
implement operators whose output pixel
values are simple linear combinations of
certain input pixel values.
COM2304 - Computer Graphics & Image
Processing
Convolution (Cont…)
COM2304 - Computer Graphics & Image
Processing
Each kernel position
corresponds to a single
output pixel, the value of
which is calculated by
multiplying together the
kernel value and the
underlying image pixel
value for each of the cells
in the kernel, and then
adding all these numbers
together.
The convolution is
performed by sliding the
kernel over the image,
generally starting at the
top left corner.
Convolution (Cont…)
COM2304 - Computer Graphics & Image
Processing
Generating Spatial Filter Masks
• Generating an m×n linear spatial filter requires that we
specify mn mask coefficients.
• These coefficients are selected based on what the filter
is supposed to do.
• There are different types of filters available, some of
them are;
– Linear filters - In signal processing, a linear filter is a filter
whose output is a linear function of its input.
– Continuous function based filters – e.g. Gaussian
smoothing (it’s a kind of linear filter).
– Non linear filters - In signal processing, a non-linear filter is
a filter whose output is not a linear function of its input.
COM2304 - Computer Graphics & Image
Processing
Generating Spatial Filter Masks (cont…)
• Linear filters
– Implement sum of products
– ex: filters used for smoothing
• Continuous function based filters
– ex: Gaussian function of two variables as shown in the following
equation;
– Where σ is the standard deviation and coordinates x and y are
the positive integers.
– Recall that 2D Gaussian function has bell shape and the σ
control the tightness of the bell.
COM2304 - Computer Graphics & Image
Processing
Generating Spatial Filter Masks (cont…)
• Non linear/ Order static filters
– Non linear filters require to specify the size of the
filter and the operation(s) to be performed on the
image pixel contained in the filter.
• ex: filter 5×5 filter centered at an arbitrary point and
perform max operation.
– Non linear filters are quiet powerful in some
applications, than the linear filters.
COM2304 - Computer Graphics & Image
Processing
Smoothing Spatial Filters
• Smoothing filters are used for blurring and
noise reduction.
• Blurring is used in preprocessing tasks, such as
removal of small details from an image prior
to object extraction, and bridging of small
gaps in lines or curves.
• Noise reduction can be accomplished by
blurring with a linear filter and also by
nonlinear filtering.
COM2304 - Computer Graphics & Image
Processing
Smoothing Linear Filters
• Average /Mean Filter
– The output is simply the average of the pixels
contained in the neighborhood of the filter mask.
– In smoothing filter, it replaces the value of every pixel
in an image by the average of the intensity levels in
the neighborhood defined by the filter mask.
– This process result in an image with reduced “sharp”
transitions in intensities.
– Most obvious application of smoothing is noise
reduction because random noise typically consists of
sharp transitions in intensity levels.
COM2304 - Computer Graphics & Image
Processing
Smoothing Linear Filters (Cont…)
COM2304 - Computer Graphics & Image
Processing
Smoothing Linear Filters (Cont…)
– Averaging filters blur edges, because edges
represent the sharp intensity transition.
– Average blurring smoothes the false contours that
result from using an insufficient number of
intensity levels.
– A major use of averaging filters is in the reduction
of “irrelevant” detail (pixel regions that are small
with respect to the size of the filter mask) in an
image.
COM2304 - Computer Graphics & Image
Processing
Smoothing Linear Filters (Cont…)
COM2304 - Computer Graphics & Image
Processing
Observe
blurring
occur during
smoothing
operation
Smoothing Linear Filters (Cont…)
– Let Sx,y represent the set of coordinates in neighbourhood
of size m×n, centered at point (x, y).
– The arithmetic mean filter computes the average value of
the corrupted image g( x, y) in the area defined by Sx,y.
– The value of the restored image f’ at point ( x, y) is simply
the arithmetic mean computed using the pixels in the
region defined by Sx,y.
COM2304 - Computer Graphics & Image
Processing


xySts
tsg
mn
yxf
),(
),(
1
),(ˆ
Smoothing Linear Filters (Cont…)
• There are different kinds of mean filters all of
which exhibit slightly different behaviour:
• Geometric Mean:
– Achieves similar smoothing to the arithmetic
mean, but tends to lose less image detail
COM2304 - Computer Graphics & Image
Processing
mn
Sts xy
tsgyxf
1
),(
),(),(ˆ








 
Smoothing Linear Filters (Cont…)
• Harmonic Mean:
– Works well for salt noise, but fails for pepper
noise.
– Also does well for other kinds of noise such as
Gaussian noise
COM2304 - Computer Graphics & Image
Processing


xySts tsg
mn
yxf
),( ),(
1
),(ˆ
Smoothing Linear Filters (Cont…)
• Contraharmonic Mean:
– Q is the order of the filter and adjusting its value
changes the filter’s behaviour.
– Positive values of Q eliminate pepper noise.
– Negative values of Q eliminate salt noise.
– If Q =0 it represents the arithmetic filter.
COM2304 - Computer Graphics & Image
Processing






xy
xy
Sts
Q
Sts
Q
tsg
tsg
yxf
),(
),(
1
),(
),(
),(ˆ
Smoothing Linear Filters (Cont…)
Original
Image
Image
Corrupted
By Gaussian
Noise
After A 3*3
Geometric
Mean Filter
After A 3*3
Arithmetic
Mean Filter
COM2304 - Computer Graphics & Image
Processing
Smoothing Linear Filters (Cont…)
Image
Corrupted
By Pepper
Noise
Result of
Filtering Above
With 3*3
Contraharmonic
Q=1.5
COM2304 - Computer Graphics & Image
Processing
Smoothing Linear Filters (Cont…)
Image
Corrupted
By Salt
Noise
Result of
Filtering Above
With 3*3
Contraharmonic
Q=-1.5
COM2304 - Computer Graphics & Image
Processing
Smoothing Linear Filters (Cont…)
Choosing the wrong value for Q when using the
contraharmonic filter can have drastic results
COM2304 - Computer Graphics & Image
Processing
Smoothing Linear Filters (Cont…)
• A spatial averaging filter in which all
coefficients are equal is called a Box
Filter.
• The basic strategy behind weighting
the center point the highest and then
reducing the value of the coefficients
as a function of increasing distance
from the origin in spatial averaging
filter is simply an attempt to reduce
blurring in the smoothing process.
COM2304 - Computer Graphics & Image
Processing
Smoothing Linear Filters (Cont…)
• Gaussian Smoothing:
– The Gaussian filter is a non-uniform low pass filter.
– The kernel coefficients diminish with increasing distance from
the kernel’s centre.
– Central pixels have a higher weighting than those on the
periphery.
– Larger values of σ produce a wider peak (greater blurring).
– Kernel size must increase with increasing σ to maintain the
Gaussian nature of the filter (`bell-shaped') .
– Gaussian kernel coefficients depend on the value of σ.
– At the edge of the mask, coefficients must be close to 0.
– The kernel is rotationally symmetric with no directional bias.
– Gaussian filters might not preserve image brightness.
COM2304 - Computer Graphics & Image
Processing
Smoothing Linear Filters (Cont…)
• The Gaussian distribution
in 1-D has the form:
• Where σ is the standard
deviation of the
distribution.
• We have also assumed
that the distribution has a
mean of zero (i.e. it is
centered on the line x=0).
COM2304 - Computer Graphics & Image
Processing
1-D Gaussian distribution with
mean 0 and σ=1
Smoothing Linear Filters (Cont…)
• In 2-D, an isotropic
(i.e. circularly symmetric)
Gaussian has the form:
COM2304 - Computer Graphics & Image
Processing
2-D Gaussian distribution with
mean (0,0) and σ=1
Discrete approximation to Gaussian
function with σ=1
The std. dev σ of the Gaussian
determines the amount of
smoothing.
Smoothing Linear Filters (Cont…)
COM2304 - Computer Graphics & Image
Processing
Smoothing Order Static (Nonlinear)
Filters
• The response of the order static or nonlinear
filters 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 determine by the ranking
result.
• Useful nonlinear filters include;
– Median filter
– Max and min filter
– Midpoint filter
COM2304 - Computer Graphics & Image
Processing
Smoothing Order Static (Nonlinear)
Filters (Cont…)
• Median Filter:
– It can reduce certain typed of random noise with
less blurring than the linear smoothing filters of
similar size.
– Provides excellent results when applying to reduce
salt and pepper noise.
COM2304 - Computer Graphics & Image
Processing
)},({),(ˆ
),(
tsgmedianyxf
xySts 

Smoothing Order Static (Nonlinear)
Filters (Cont…)
COM2304 - Computer Graphics & Image
Processing
Smoothing Order Static (Nonlinear)
Filters (Cont…)
COM2304 - Computer Graphics & Image
Processing
Smoothing Order Static (Nonlinear)
Filters (Cont…)
• Median filter smoothes ("washes") all edges
and boundaries and may "erase" all details
whose size is about n/2× m/2, where n × m is
a window size.
• As a result, an image becomes "fuzzy".
• Median filter is not so efficient for additive
Gaussian noise removal, it yields to linear
filters.
COM2304 - Computer Graphics & Image
Processing
Smoothing Order Static (Nonlinear)
Filters (Cont…)
• Max Filter:
• Min Filter:
–Max filter is useful for finding the brightest points in an
image and min filter for finding the darkest points in an
image.
–Max filter is good for pepper noise and min filter is good for
salt noise
COM2304 - Computer Graphics & Image
Processing
)},({max),(ˆ
),(
tsgyxf
xySts 

)},({min),(ˆ
),(
tsgyxf
xySts 

Smoothing Order Static (Nonlinear)
Filters (Cont…)
• Midpoint Filter:
– Good for random Gaussian and uniform noise
COM2304 - Computer Graphics & Image
Processing



 

)},({min)},({max
2
1
),(ˆ
),(),(
tsgtsgyxf
xyxy StsSts
Smoothing Order Static (Nonlinear)
Filters (Cont…)
• Alpha-trimmed Mean Filter:
– We can delete the d/2 lowest and d/2 highest grey
levels.
– So g(s, t) represents the remaining mn – d pixels.
– When d= 0 : arithmetic mean filter.
– Good for combination of salt and pepper and
Gaussian noise.
COM2304 - Computer Graphics & Image
Processing


xySts
tsg
dmn
yxf
),(
),(
1
),(ˆ
Smoothing Order Static (Nonlinear)
Filters (Cont…)
COM2304 - Computer Graphics & Image
Processing
Removing Periodic Noise
• Removing periodic noise form an image
involves removing a particular range of
frequencies from that image.
• Band reject filters can be used for this
purpose.
Out of the scope of this course -   
COM2304 - Computer Graphics & Image
Processing
Reference
• Chapter 03, Chapter 05 of Gonzalez, R.C.,
Woods, R.E., Digital Image Processing, 3rd ed.
Addison-Wesley Pub.
• http://setosa.io/ev/image-kernels/
• https://en.wikipedia.org/wiki/Kernel_(image_
processing)
COM2304 - Computer Graphics & Image
Processing
Learning Outcomes Revisit
• Now, you should be able to;
– describe the fundamentals of spatial filtering.
– generating spatial filter masks.
– identify smoothing via linear filters and non
linear filters.
– apply smoothing techniques for problem
solving.
COM2304 - Computer Graphics & Image
Processing
QUESTIONS ?
Next Lecture – Intensity Transformation and Spatial Filtering – III
COM2304 - Computer Graphics & Image
Processing

More Related Content

What's hot (20)

PPT
Spatial filtering
shabanam tamboli
 
PPTX
Fundamentals and image compression models
lavanya marichamy
 
PPTX
Image Sensing and Acquisition.pptx
RUBIN (A) JEBIN
 
PPT
Spatial domain and filtering
University of Potsdam
 
PPTX
RECURSIVE DESCENT PARSING
Jothi Lakshmi
 
PPTX
SPATIAL FILTERING IN IMAGE PROCESSING
muthu181188
 
PPT
Sharpening using frequency Domain Filter
arulraj121
 
PPSX
Image Enhancement in Spatial Domain
Dr. A. B. Shinde
 
PPT
08 frequency domain filtering DIP
babak danyal
 
PDF
Image processing, Noise, Noise Removal filters
Kuppusamy P
 
PPTX
Image Enhancement in Spatial Domain
DEEPASHRI HK
 
PPTX
Chapter 3 image enhancement (spatial domain)
asodariyabhavesh
 
PPTX
Anti- aliasing computer graphics
Safayet Hossain
 
PPTX
Image filtering in Digital image processing
Abinaya B
 
PPT
Window to viewport transformation
Ankit Garg
 
PDF
Image segmentation
Kuppusamy P
 
PPT
Spatial filtering
Sanyam Agarwal
 
PPTX
Computer Graphics: Visible surface detection methods
Joseph Charles
 
PPTX
Image feature extraction
Rushin Shah
 
Spatial filtering
shabanam tamboli
 
Fundamentals and image compression models
lavanya marichamy
 
Image Sensing and Acquisition.pptx
RUBIN (A) JEBIN
 
Spatial domain and filtering
University of Potsdam
 
RECURSIVE DESCENT PARSING
Jothi Lakshmi
 
SPATIAL FILTERING IN IMAGE PROCESSING
muthu181188
 
Sharpening using frequency Domain Filter
arulraj121
 
Image Enhancement in Spatial Domain
Dr. A. B. Shinde
 
08 frequency domain filtering DIP
babak danyal
 
Image processing, Noise, Noise Removal filters
Kuppusamy P
 
Image Enhancement in Spatial Domain
DEEPASHRI HK
 
Chapter 3 image enhancement (spatial domain)
asodariyabhavesh
 
Anti- aliasing computer graphics
Safayet Hossain
 
Image filtering in Digital image processing
Abinaya B
 
Window to viewport transformation
Ankit Garg
 
Image segmentation
Kuppusamy P
 
Spatial filtering
Sanyam Agarwal
 
Computer Graphics: Visible surface detection methods
Joseph Charles
 
Image feature extraction
Rushin Shah
 

Viewers also liked (20)

PPTX
Digital image processing
Vandana Verma
 
PPTX
Spatial enhancement
abinarkt
 
PPT
Texture in image processing
Anna Aquarian
 
PPTX
Smoothing Filters in Spatial Domain
Madhu Bala
 
PPT
Image Texture Analysis
lalitxp
 
PPTX
Edge detection of video using matlab code
Bhushan Deore
 
PDF
Digital Image Processing: Image Restoration
Mostafa G. M. Mostafa
 
PPTX
Edge Detection algorithm and code
Vaddi Manikanta
 
PDF
Digital Image Processing: Image Enhancement in the Spatial Domain
Mostafa G. M. Mostafa
 
PDF
Digital Image Processing: Image Enhancement in the Frequency Domain
Mostafa G. M. Mostafa
 
PPTX
Introduction to wavelet transform
Raj Endiran
 
PPTX
Edge detection
Ishraq Al Fataftah
 
PPTX
Image enhancement
Ayaelshiwi
 
PPT
Enhancement in spatial domain
Ashish Kumar
 
PPTX
Image enhancement techniques
Saideep
 
PPT
Image enhancement techniques
sakshij91
 
PDF
Image Restoration (Digital Image Processing)
Kalyan Acharjya
 
PPT
image_enhancement_spatial
honeyjecrc
 
PPTX
Image processing ppt
Raviteja Chowdary Adusumalli
 
PPTX
discrete wavelet transform
piyush_11
 
Digital image processing
Vandana Verma
 
Spatial enhancement
abinarkt
 
Texture in image processing
Anna Aquarian
 
Smoothing Filters in Spatial Domain
Madhu Bala
 
Image Texture Analysis
lalitxp
 
Edge detection of video using matlab code
Bhushan Deore
 
Digital Image Processing: Image Restoration
Mostafa G. M. Mostafa
 
Edge Detection algorithm and code
Vaddi Manikanta
 
Digital Image Processing: Image Enhancement in the Spatial Domain
Mostafa G. M. Mostafa
 
Digital Image Processing: Image Enhancement in the Frequency Domain
Mostafa G. M. Mostafa
 
Introduction to wavelet transform
Raj Endiran
 
Edge detection
Ishraq Al Fataftah
 
Image enhancement
Ayaelshiwi
 
Enhancement in spatial domain
Ashish Kumar
 
Image enhancement techniques
Saideep
 
Image enhancement techniques
sakshij91
 
Image Restoration (Digital Image Processing)
Kalyan Acharjya
 
image_enhancement_spatial
honeyjecrc
 
Image processing ppt
Raviteja Chowdary Adusumalli
 
discrete wavelet transform
piyush_11
 
Ad

Similar to COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filtering and Smoothing (20)

PPTX
COM2304: Intensity Transformation and Spatial Filtering – III Spatial Filters...
Hemantha Kulathilake
 
PPTX
Segmentation Techniques -I
Hemantha Kulathilake
 
PPTX
COM2304: Morphological Image Processing
Hemantha Kulathilake
 
PPTX
Digital Image Fundamentals - II
Hemantha Kulathilake
 
PPTX
Segmentation Techniques -II
Hemantha Kulathilake
 
PDF
Lecture 4
Wael Sharba
 
PPTX
ACMP340.pptx
FelixGathage
 
PPT
Fidelity criteria in image compression
KadamPawan
 
PDF
Translation Invariance (TI) based Novel Approach for better De-noising of Dig...
IRJET Journal
 
PPTX
COM2304: Introduction to Computer Vision & Image Processing
Hemantha Kulathilake
 
PPT
Spatial Filtering in intro image processingr
kumarankit06875
 
PPTX
When Discrete Optimization Meets Multimedia Security (and Beyond)
Shujun Li
 
PPT
Machine Vision lecture notes for Unit 3.ppt
SATHISHKUMARSD1
 
PPTX
COM2304: Digital Image Fundamentals - I
Hemantha Kulathilake
 
PPTX
Image processing
kamal330
 
PDF
IRJET - Computer-Assisted ALL, AML, CLL, CML Detection and Counting for D...
IRJET Journal
 
PPTX
COMPUTER GRAPHICS
Jagan Raja
 
PPTX
DIP Notes Unit-1 PPT , engineering, computer Science
baaburao4200
 
PPTX
Presentation
Vikash Kumar Das
 
PDF
IRJET - Change Detection in Satellite Images using Convolutional Neural N...
IRJET Journal
 
COM2304: Intensity Transformation and Spatial Filtering – III Spatial Filters...
Hemantha Kulathilake
 
Segmentation Techniques -I
Hemantha Kulathilake
 
COM2304: Morphological Image Processing
Hemantha Kulathilake
 
Digital Image Fundamentals - II
Hemantha Kulathilake
 
Segmentation Techniques -II
Hemantha Kulathilake
 
Lecture 4
Wael Sharba
 
ACMP340.pptx
FelixGathage
 
Fidelity criteria in image compression
KadamPawan
 
Translation Invariance (TI) based Novel Approach for better De-noising of Dig...
IRJET Journal
 
COM2304: Introduction to Computer Vision & Image Processing
Hemantha Kulathilake
 
Spatial Filtering in intro image processingr
kumarankit06875
 
When Discrete Optimization Meets Multimedia Security (and Beyond)
Shujun Li
 
Machine Vision lecture notes for Unit 3.ppt
SATHISHKUMARSD1
 
COM2304: Digital Image Fundamentals - I
Hemantha Kulathilake
 
Image processing
kamal330
 
IRJET - Computer-Assisted ALL, AML, CLL, CML Detection and Counting for D...
IRJET Journal
 
COMPUTER GRAPHICS
Jagan Raja
 
DIP Notes Unit-1 PPT , engineering, computer Science
baaburao4200
 
Presentation
Vikash Kumar Das
 
IRJET - Change Detection in Satellite Images using Convolutional Neural N...
IRJET Journal
 
Ad

More from Hemantha Kulathilake (20)

PPTX
NLP_KASHK:Parsing with Context-Free Grammar
Hemantha Kulathilake
 
PPTX
NLP_KASHK:Context-Free Grammar for English
Hemantha Kulathilake
 
PPTX
NLP_KASHK:POS Tagging
Hemantha Kulathilake
 
PPTX
NLP_KASHK:Markov Models
Hemantha Kulathilake
 
PPTX
NLP_KASHK:Smoothing N-gram Models
Hemantha Kulathilake
 
PPTX
NLP_KASHK:Evaluating Language Model
Hemantha Kulathilake
 
PPTX
NLP_KASHK:N-Grams
Hemantha Kulathilake
 
PPTX
NLP_KASHK:Minimum Edit Distance
Hemantha Kulathilake
 
PPTX
NLP_KASHK:Finite-State Morphological Parsing
Hemantha Kulathilake
 
PPTX
NLP_KASHK:Morphology
Hemantha Kulathilake
 
PPTX
NLP_KASHK:Text Normalization
Hemantha Kulathilake
 
PPTX
NLP_KASHK:Finite-State Automata
Hemantha Kulathilake
 
PPTX
NLP_KASHK:Regular Expressions
Hemantha Kulathilake
 
PPTX
NLP_KASHK: Introduction
Hemantha Kulathilake
 
PPTX
COM1407: File Processing
Hemantha Kulathilake
 
PPTX
COm1407: Character & Strings
Hemantha Kulathilake
 
PPTX
COM1407: Structures, Unions & Dynamic Memory Allocation
Hemantha Kulathilake
 
PPTX
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
PPTX
COM1407: Working with Pointers
Hemantha Kulathilake
 
PPTX
COM1407: Arrays
Hemantha Kulathilake
 
NLP_KASHK:Parsing with Context-Free Grammar
Hemantha Kulathilake
 
NLP_KASHK:Context-Free Grammar for English
Hemantha Kulathilake
 
NLP_KASHK:POS Tagging
Hemantha Kulathilake
 
NLP_KASHK:Markov Models
Hemantha Kulathilake
 
NLP_KASHK:Smoothing N-gram Models
Hemantha Kulathilake
 
NLP_KASHK:Evaluating Language Model
Hemantha Kulathilake
 
NLP_KASHK:N-Grams
Hemantha Kulathilake
 
NLP_KASHK:Minimum Edit Distance
Hemantha Kulathilake
 
NLP_KASHK:Finite-State Morphological Parsing
Hemantha Kulathilake
 
NLP_KASHK:Morphology
Hemantha Kulathilake
 
NLP_KASHK:Text Normalization
Hemantha Kulathilake
 
NLP_KASHK:Finite-State Automata
Hemantha Kulathilake
 
NLP_KASHK:Regular Expressions
Hemantha Kulathilake
 
NLP_KASHK: Introduction
Hemantha Kulathilake
 
COM1407: File Processing
Hemantha Kulathilake
 
COm1407: Character & Strings
Hemantha Kulathilake
 
COM1407: Structures, Unions & Dynamic Memory Allocation
Hemantha Kulathilake
 
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
COM1407: Working with Pointers
Hemantha Kulathilake
 
COM1407: Arrays
Hemantha Kulathilake
 

Recently uploaded (20)

PDF
RODENT PEST MANAGEMENT-converted-compressed.pdf
S.B.P.G. COLLEGE BARAGAON VARANASI
 
PPTX
Phage Therapy and Bacteriophage Biology.pptx
Prachi Virat
 
PPTX
Akshay tunneling .pptx_20250331_165945_0000.pptx
akshaythaker18
 
PPTX
Cooking Oil Tester How to Measure Quality of Frying Oil.pptx
M-Kube Enterprise
 
PPTX
Vectors and applications of genetic engineering Pptx
Ashwini I Chuncha
 
PDF
Annual report 2024 - Inria - English version.pdf
Inria
 
PDF
Chemokines and Receptors Overview – Key to Immune Cell Signaling
Benjamin Lewis Lewis
 
PDF
NRRM 330 Dynamic Equlibrium Presentation
Rowan Sales
 
PPTX
GB1 Q1 04 Life in a Cell (1).pptx GRADE 11
JADE ACOSTA
 
PDF
Phosphates reveal high pH ocean water on Enceladus
Sérgio Sacani
 
PDF
A proposed mechanism for the formation of protocell-like structures on Titan
Sérgio Sacani
 
PDF
The role of the Lorentz force in sunspot equilibrium
Sérgio Sacani
 
PPTX
Lamarckism is one of the earliest theories of evolution, proposed before Darw...
Laxman Khatal
 
PPTX
Hypothalamus_nuclei_ structure_functions.pptx
muralinath2
 
PDF
crestacean parasitim non chordates notes
S.B.P.G. COLLEGE BARAGAON VARANASI
 
PPTX
LESSON 2 PSYCHOSOCIAL DEVELOPMENT.pptx L
JeanCarolColico1
 
PDF
WUCHERIA BANCROFTI-converted-compressed.pdf
S.B.P.G. COLLEGE BARAGAON VARANASI
 
PPTX
Envenomation AND ANIMAL BITES DETAILS.pptx
HARISH543351
 
PPT
Cell cycle,cell cycle checkpoint and control
DrMukeshRameshPimpli
 
PDF
Adding Geochemistry To Understand Recharge Areas - Kinney County, Texas - Jim...
Texas Alliance of Groundwater Districts
 
RODENT PEST MANAGEMENT-converted-compressed.pdf
S.B.P.G. COLLEGE BARAGAON VARANASI
 
Phage Therapy and Bacteriophage Biology.pptx
Prachi Virat
 
Akshay tunneling .pptx_20250331_165945_0000.pptx
akshaythaker18
 
Cooking Oil Tester How to Measure Quality of Frying Oil.pptx
M-Kube Enterprise
 
Vectors and applications of genetic engineering Pptx
Ashwini I Chuncha
 
Annual report 2024 - Inria - English version.pdf
Inria
 
Chemokines and Receptors Overview – Key to Immune Cell Signaling
Benjamin Lewis Lewis
 
NRRM 330 Dynamic Equlibrium Presentation
Rowan Sales
 
GB1 Q1 04 Life in a Cell (1).pptx GRADE 11
JADE ACOSTA
 
Phosphates reveal high pH ocean water on Enceladus
Sérgio Sacani
 
A proposed mechanism for the formation of protocell-like structures on Titan
Sérgio Sacani
 
The role of the Lorentz force in sunspot equilibrium
Sérgio Sacani
 
Lamarckism is one of the earliest theories of evolution, proposed before Darw...
Laxman Khatal
 
Hypothalamus_nuclei_ structure_functions.pptx
muralinath2
 
crestacean parasitim non chordates notes
S.B.P.G. COLLEGE BARAGAON VARANASI
 
LESSON 2 PSYCHOSOCIAL DEVELOPMENT.pptx L
JeanCarolColico1
 
WUCHERIA BANCROFTI-converted-compressed.pdf
S.B.P.G. COLLEGE BARAGAON VARANASI
 
Envenomation AND ANIMAL BITES DETAILS.pptx
HARISH543351
 
Cell cycle,cell cycle checkpoint and control
DrMukeshRameshPimpli
 
Adding Geochemistry To Understand Recharge Areas - Kinney County, Texas - Jim...
Texas Alliance of Groundwater Districts
 

COM2304: Intensity Transformation and Spatial Filtering – II Spatial Filtering and Smoothing

  • 1. COMPUTER GRAPHICS & IMAGE PROCESSING COM2304 Intensity Transformation and Spatial Filtering – II Spatial Filtering and Smoothing K.A.S.H.Kulathilake B.Sc. (Hons) IT (SLIIT), MCS (UCSC), M.Phil (UOM), SEDA(UK) Rajarata University of Sri Lanka Faculty of Applied Sciences Department of Physical Sciences
  • 2. Learning Outcomes COM2304 - Computer Graphics & Image Processing • At the end of this lecture, you should be able to; – describe the fundamentals of spatial filtering. – generating spatial filter masks. – identify smoothing via linear filters and non linear filters. – apply smoothing techniques for problem solving.
  • 3. Filters in Image Processing • Filter can accept or reject certain frequency components. • In image processing filters are mainly used to suppress either the high frequencies in the image, i.e. smoothing the image, or the low frequencies, i.e. enhancing/ sharpening or detecting edges in the image. • An image can be filtered either in the frequency or in the spatial domain. COM2304 - Computer Graphics & Image Processing
  • 4. Fundamentals of Frequency Domain Filtering • Frequency domain filtering involves ; – transforming the image into the frequency domain, – multiplying it with the frequency filter function and – re-transforming the result into the spatial domain. • The filter function is shaped so as to attenuate some frequencies and enhance others. • For example, a simple lowpass function is 1 for frequencies smaller than the cut-off frequency and 0 for all others. COM2304 - Computer Graphics & Image Processing
  • 5. Fundamentals of Spatial Filtering • Spatial filter contains two components; – MASK/ CONVOLUTION MATRIX/ KERNEL: A neighborhood (typically small rectangle:) – FILTER FUNCTION: A predefined operation that is performed on the image pixels encompassed by the neighborhood. • Spatial filtering is the method of choice in situations when only additive random noise is present. • Filtering creates a new pixel value with coordinates equal to the coordinates of the center of the neighborhood, and whose value is the result of the filtering operation. COM2304 - Computer Graphics & Image Processing
  • 6. Fundamentals of Spatial Filtering (Cont….) COM2304 - Computer Graphics & Image Processing
  • 7. Fundamentals of Spatial Filtering (Cont….) COM2304 - Computer Graphics & Image Processing If the operation performed on the image pixels is linear, then the filter is called a linear spatial filter, otherwise, the filter is non-linear.
  • 8. Fundamentals of Spatial Filtering (Cont….) • Spatial filtering of an image of size M×N with a filter of size m×n is given by the expression; • Where w is the mask and f is the image function, x and y are varied so that each pixel in w visits every pixel in f. • m = 2a+1 and n = 2b+1, where a and b are positive integers. • This concept is known as correlation. COM2304 - Computer Graphics & Image Processing
  • 9. Fundamentals of Spatial Filtering (Cont….) • There are two closely related concepts that must be understood clearly when performing linear spatial filtering – Correlation • Correlation is the process of moving a filter mask over the image and computing the sum of products at each location exactly as explained previously. – Convolution • The mechanics of convolution are the same as correlation except that the filter is first rotated by 180 degrees. COM2304 - Computer Graphics & Image Processing
  • 10. Fundamentals of Spatial Filtering (Cont….) COM2304 - Computer Graphics & Image Processing If the filter mask is symmetric, correlation and convolution yield the same result
  • 11. Mask/Kernel/ Convolution Matrix • In image processing, a kernel, convolution matrix, or mask is a small matrix. • It is useful for blurring, sharpening, embossing, edge detection, and more. • This is accomplished by means of convolution between a kernel and an image. COM2304 - Computer Graphics & Image Processing
  • 12. Mask/Kernel/ Convolution Matrix (Cont…) • Important Features of Kernel – Size: 3×3, 5×5, 9×9, 21×21 – Shape: rectangle, cross, strip, circular, diamond or user defined. – Coefficients / Values: set based on the operation. – Anchor point: mostly in middle COM2304 - Computer Graphics & Image Processing 0 -1 0 -1 5 -1 0 -1 0 3×3 Kernel Anchor Values for sharpening operation
  • 13. Mask/Kernel/ Convolution Matrix (Cont…) COM2304 - Computer Graphics & Image Processing 0 -1 0 -1 5 -1 0 -1 0 Kernel
  • 14. Mask/Kernel/ Convolution Matrix (Cont…) COM2304 - Computer Graphics & Image Processing http://setosa.io/ev/image-kernels/ https://en.wikipedia.org/wiki/Kernel_(image_processing)
  • 15. Convolution • Convolution is a simple mathematical operation which is fundamental to many common image processing operators. • This can be used in image processing to implement operators whose output pixel values are simple linear combinations of certain input pixel values. COM2304 - Computer Graphics & Image Processing
  • 16. Convolution (Cont…) COM2304 - Computer Graphics & Image Processing Each kernel position corresponds to a single output pixel, the value of which is calculated by multiplying together the kernel value and the underlying image pixel value for each of the cells in the kernel, and then adding all these numbers together. The convolution is performed by sliding the kernel over the image, generally starting at the top left corner.
  • 17. Convolution (Cont…) COM2304 - Computer Graphics & Image Processing
  • 18. Generating Spatial Filter Masks • Generating an m×n linear spatial filter requires that we specify mn mask coefficients. • These coefficients are selected based on what the filter is supposed to do. • There are different types of filters available, some of them are; – Linear filters - In signal processing, a linear filter is a filter whose output is a linear function of its input. – Continuous function based filters – e.g. Gaussian smoothing (it’s a kind of linear filter). – Non linear filters - In signal processing, a non-linear filter is a filter whose output is not a linear function of its input. COM2304 - Computer Graphics & Image Processing
  • 19. Generating Spatial Filter Masks (cont…) • Linear filters – Implement sum of products – ex: filters used for smoothing • Continuous function based filters – ex: Gaussian function of two variables as shown in the following equation; – Where σ is the standard deviation and coordinates x and y are the positive integers. – Recall that 2D Gaussian function has bell shape and the σ control the tightness of the bell. COM2304 - Computer Graphics & Image Processing
  • 20. Generating Spatial Filter Masks (cont…) • Non linear/ Order static filters – Non linear filters require to specify the size of the filter and the operation(s) to be performed on the image pixel contained in the filter. • ex: filter 5×5 filter centered at an arbitrary point and perform max operation. – Non linear filters are quiet powerful in some applications, than the linear filters. COM2304 - Computer Graphics & Image Processing
  • 21. Smoothing Spatial Filters • Smoothing filters are used for blurring and noise reduction. • Blurring is used in preprocessing tasks, such as removal of small details from an image prior to object extraction, and bridging of small gaps in lines or curves. • Noise reduction can be accomplished by blurring with a linear filter and also by nonlinear filtering. COM2304 - Computer Graphics & Image Processing
  • 22. Smoothing Linear Filters • Average /Mean Filter – The output is simply the average of the pixels contained in the neighborhood of the filter mask. – In smoothing filter, it replaces the value of every pixel in an image by the average of the intensity levels in the neighborhood defined by the filter mask. – This process result in an image with reduced “sharp” transitions in intensities. – Most obvious application of smoothing is noise reduction because random noise typically consists of sharp transitions in intensity levels. COM2304 - Computer Graphics & Image Processing
  • 23. Smoothing Linear Filters (Cont…) COM2304 - Computer Graphics & Image Processing
  • 24. Smoothing Linear Filters (Cont…) – Averaging filters blur edges, because edges represent the sharp intensity transition. – Average blurring smoothes the false contours that result from using an insufficient number of intensity levels. – A major use of averaging filters is in the reduction of “irrelevant” detail (pixel regions that are small with respect to the size of the filter mask) in an image. COM2304 - Computer Graphics & Image Processing
  • 25. Smoothing Linear Filters (Cont…) COM2304 - Computer Graphics & Image Processing Observe blurring occur during smoothing operation
  • 26. Smoothing Linear Filters (Cont…) – Let Sx,y represent the set of coordinates in neighbourhood of size m×n, centered at point (x, y). – The arithmetic mean filter computes the average value of the corrupted image g( x, y) in the area defined by Sx,y. – The value of the restored image f’ at point ( x, y) is simply the arithmetic mean computed using the pixels in the region defined by Sx,y. COM2304 - Computer Graphics & Image Processing   xySts tsg mn yxf ),( ),( 1 ),(ˆ
  • 27. Smoothing Linear Filters (Cont…) • There are different kinds of mean filters all of which exhibit slightly different behaviour: • Geometric Mean: – Achieves similar smoothing to the arithmetic mean, but tends to lose less image detail COM2304 - Computer Graphics & Image Processing mn Sts xy tsgyxf 1 ),( ),(),(ˆ          
  • 28. Smoothing Linear Filters (Cont…) • Harmonic Mean: – Works well for salt noise, but fails for pepper noise. – Also does well for other kinds of noise such as Gaussian noise COM2304 - Computer Graphics & Image Processing   xySts tsg mn yxf ),( ),( 1 ),(ˆ
  • 29. Smoothing Linear Filters (Cont…) • Contraharmonic Mean: – Q is the order of the filter and adjusting its value changes the filter’s behaviour. – Positive values of Q eliminate pepper noise. – Negative values of Q eliminate salt noise. – If Q =0 it represents the arithmetic filter. COM2304 - Computer Graphics & Image Processing       xy xy Sts Q Sts Q tsg tsg yxf ),( ),( 1 ),( ),( ),(ˆ
  • 30. Smoothing Linear Filters (Cont…) Original Image Image Corrupted By Gaussian Noise After A 3*3 Geometric Mean Filter After A 3*3 Arithmetic Mean Filter COM2304 - Computer Graphics & Image Processing
  • 31. Smoothing Linear Filters (Cont…) Image Corrupted By Pepper Noise Result of Filtering Above With 3*3 Contraharmonic Q=1.5 COM2304 - Computer Graphics & Image Processing
  • 32. Smoothing Linear Filters (Cont…) Image Corrupted By Salt Noise Result of Filtering Above With 3*3 Contraharmonic Q=-1.5 COM2304 - Computer Graphics & Image Processing
  • 33. Smoothing Linear Filters (Cont…) Choosing the wrong value for Q when using the contraharmonic filter can have drastic results COM2304 - Computer Graphics & Image Processing
  • 34. Smoothing Linear Filters (Cont…) • A spatial averaging filter in which all coefficients are equal is called a Box Filter. • The basic strategy behind weighting the center point the highest and then reducing the value of the coefficients as a function of increasing distance from the origin in spatial averaging filter is simply an attempt to reduce blurring in the smoothing process. COM2304 - Computer Graphics & Image Processing
  • 35. Smoothing Linear Filters (Cont…) • Gaussian Smoothing: – The Gaussian filter is a non-uniform low pass filter. – The kernel coefficients diminish with increasing distance from the kernel’s centre. – Central pixels have a higher weighting than those on the periphery. – Larger values of σ produce a wider peak (greater blurring). – Kernel size must increase with increasing σ to maintain the Gaussian nature of the filter (`bell-shaped') . – Gaussian kernel coefficients depend on the value of σ. – At the edge of the mask, coefficients must be close to 0. – The kernel is rotationally symmetric with no directional bias. – Gaussian filters might not preserve image brightness. COM2304 - Computer Graphics & Image Processing
  • 36. Smoothing Linear Filters (Cont…) • The Gaussian distribution in 1-D has the form: • Where σ is the standard deviation of the distribution. • We have also assumed that the distribution has a mean of zero (i.e. it is centered on the line x=0). COM2304 - Computer Graphics & Image Processing 1-D Gaussian distribution with mean 0 and σ=1
  • 37. Smoothing Linear Filters (Cont…) • In 2-D, an isotropic (i.e. circularly symmetric) Gaussian has the form: COM2304 - Computer Graphics & Image Processing 2-D Gaussian distribution with mean (0,0) and σ=1 Discrete approximation to Gaussian function with σ=1 The std. dev σ of the Gaussian determines the amount of smoothing.
  • 38. Smoothing Linear Filters (Cont…) COM2304 - Computer Graphics & Image Processing
  • 39. Smoothing Order Static (Nonlinear) Filters • The response of the order static or nonlinear filters 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 determine by the ranking result. • Useful nonlinear filters include; – Median filter – Max and min filter – Midpoint filter COM2304 - Computer Graphics & Image Processing
  • 40. Smoothing Order Static (Nonlinear) Filters (Cont…) • Median Filter: – It can reduce certain typed of random noise with less blurring than the linear smoothing filters of similar size. – Provides excellent results when applying to reduce salt and pepper noise. COM2304 - Computer Graphics & Image Processing )},({),(ˆ ),( tsgmedianyxf xySts  
  • 41. Smoothing Order Static (Nonlinear) Filters (Cont…) COM2304 - Computer Graphics & Image Processing
  • 42. Smoothing Order Static (Nonlinear) Filters (Cont…) COM2304 - Computer Graphics & Image Processing
  • 43. Smoothing Order Static (Nonlinear) Filters (Cont…) • Median filter smoothes ("washes") all edges and boundaries and may "erase" all details whose size is about n/2× m/2, where n × m is a window size. • As a result, an image becomes "fuzzy". • Median filter is not so efficient for additive Gaussian noise removal, it yields to linear filters. COM2304 - Computer Graphics & Image Processing
  • 44. Smoothing Order Static (Nonlinear) Filters (Cont…) • Max Filter: • Min Filter: –Max filter is useful for finding the brightest points in an image and min filter for finding the darkest points in an image. –Max filter is good for pepper noise and min filter is good for salt noise COM2304 - Computer Graphics & Image Processing )},({max),(ˆ ),( tsgyxf xySts   )},({min),(ˆ ),( tsgyxf xySts  
  • 45. Smoothing Order Static (Nonlinear) Filters (Cont…) • Midpoint Filter: – Good for random Gaussian and uniform noise COM2304 - Computer Graphics & Image Processing       )},({min)},({max 2 1 ),(ˆ ),(),( tsgtsgyxf xyxy StsSts
  • 46. Smoothing Order Static (Nonlinear) Filters (Cont…) • Alpha-trimmed Mean Filter: – We can delete the d/2 lowest and d/2 highest grey levels. – So g(s, t) represents the remaining mn – d pixels. – When d= 0 : arithmetic mean filter. – Good for combination of salt and pepper and Gaussian noise. COM2304 - Computer Graphics & Image Processing   xySts tsg dmn yxf ),( ),( 1 ),(ˆ
  • 47. Smoothing Order Static (Nonlinear) Filters (Cont…) COM2304 - Computer Graphics & Image Processing
  • 48. Removing Periodic Noise • Removing periodic noise form an image involves removing a particular range of frequencies from that image. • Band reject filters can be used for this purpose. Out of the scope of this course -    COM2304 - Computer Graphics & Image Processing
  • 49. Reference • Chapter 03, Chapter 05 of Gonzalez, R.C., Woods, R.E., Digital Image Processing, 3rd ed. Addison-Wesley Pub. • http://setosa.io/ev/image-kernels/ • https://en.wikipedia.org/wiki/Kernel_(image_ processing) COM2304 - Computer Graphics & Image Processing
  • 50. Learning Outcomes Revisit • Now, you should be able to; – describe the fundamentals of spatial filtering. – generating spatial filter masks. – identify smoothing via linear filters and non linear filters. – apply smoothing techniques for problem solving. COM2304 - Computer Graphics & Image Processing
  • 51. QUESTIONS ? Next Lecture – Intensity Transformation and Spatial Filtering – III COM2304 - Computer Graphics & Image Processing