Dr.
Muhammad Shahzad
Department Of Computing (DOC), SEECS, NUST
http://seecs.nust.edu.pk/faculty/muhammadshahzad.html
[email protected]
Spring 2019, MSCS-8
▪ They don’t know where they are in an image
▪ They don’t know anything about their neighbors
▪ Most image features (edges, textures, etc) involve a spatial
neighborhood of pixels
▪ If we want to enhance or manipulate these features, we need to
go beyond point operations
2
▪ Spatial Filtering : Basics
3
Basics
4
Basics
5
Basics
6
Basics
7
Basics
8
Basics
9
Basics
10
▪ The output intensity value at (x,y) depends not only on the
input intensity value at (x,y) but also on the specified number of
neighbouring intensity values around (x,y)
▪ Spatial masks (also called window, filter, kernel, template) are
used and convolved over the entire image for enhancement
(spatial filtering)
▪ The size of the masks determines the number of neighbouring
pixels which influence the output value at (x,y)
▪ The values (coefficients) of the mask determine the nature and
properties of enhancing technique
11
12
= wTz
13
g ( x, y ) = w ( −1, −1) f ( x − 1, y − 1) + w ( −1,0 ) f ( x − 1, y ) + w ( −1,1) f ( x − 1, y + 1)
+ w ( 0, −1) f ( x, y − 1) + w ( 0,0 ) f ( x, y ) + w ( 0,1) f ( x, y + 1)
+ w (1, −1) f ( x + 1, y − 1) + w (1,0 ) f ( x + 1, y ) + w (1,1) f ( x + 1, y + 1)
In general, linear spatial filtering of an Filter
image of size M x N with a filter of size coefficients
m x n is given below
Pixels of
m −1 n −1 image
where a = ,b =
2 2 section
under filter
where x and y are varied so that each
pixel in w visits every pixel in f
14
▪ There are two closely related concepts that must be understood
clearly when performing linear spatial filtering
▪ Correlation
▪ Convolution
▪ Correlation is the process of moving a filter mask w over the
image f and computing the sum of products at each location
exaxctly as explained in the previous slide
▪ Mechanically, convolution is the same process, except that w is
rotated by 180 degrees prior to passing it over the image f
▪ Read section 3.4.1 and section 3.4.2; DIP 3e by Gonzalez
15
Correlation Convolution
16
Correlation Convolution
17
▪ Two important points
▪ Correlating a filter w with a function that contains all 0s and a single
1 yields a copy of w (rotated)
▪ We call a function that contains a single 1 with the rest being 0s
a discrete unit impulse
▪ Thus correlation of a function with a discrete unit impulse
yields a rotated version of the function at the location of the
impulse
▪ Concept of convolution is cornerstone of linear system theory
▪ A fundamental property of convolution is that convolving a function
with a unit impulse yields a copy of the function at the location of
the impulse
18
If the filter mask is
symmetric, correlation
and convolution yield the
same result
Correlation and Convolution
19
Now, try something special:
▪ place a mask over a part of an image
▪ multiply pixels under red dot by 1
▪ multiply pixels under empty pixel by 0
▪ add up the products
20
For the image,
take dark pixel value = 1,
light pixel value = 0
21
▪ The final result is
▪ The above process is called template matching
▪ It finds the locations at which the template best matches the image
▪ Template matching is a kind of cross correlation
22
▪ To summarize
In general, correlation of an image of
size M x N with a filter of size m x n is
given below
a b
w ( s, t ) f ( x + s, y + t )
s =− a t =−b m −1 n −1
where a = ,b =
2 2
In general, convolution of an image of
and x and y are varied so that each
size M x N with a filter of size m x n is
given below pixel in w visits every pixel in f
a b
w ( s, t ) f ( x − s, y − t )
s =− a t =−b
23
Various contents in this presentation have been taken from
different books, lecture notes, and the web. These solely belong
to their owners, and are here used only for clarifying various
educational concepts. Any copyright infringement is not
intended.
24