Convolution
1-D and 2-D
1
Introduction
Two important mathematical operations
commonly used in signal and image
processing
– Convolution and
– Correlation
2
Convolution
Convolution:
– It is an integral that expresses the amount of
overlap of one function has as it is shifted over
another function (more the overlap, greater the
value of convolution)
3
Convolution
Importance of Convolution
– Several important operations on images be
easily described in terms of convolutions
For example
– Pattern matching
– Filtering:
• blurring
• sharpening
• edge detection
• noise reduction
4
Convolution
Let us examine the concepts using 1-
D continuous functions
The convolution of two functions f(x)
and g(x) is written as f(x)*g(x)
It is defined by the integral
5
Convolution
Example:
– Consider two top hat functions, f(x) and g(x)
defined as:
6
Convolution
To compute following, we need f(α) and g(x- α)
We can easily compute f(α) from f(x)
1 1 1
f ( )
0 else
7
Convolution
Computation of g(x- α) from g(x)
1 0 1
g ( ) 2
0 else
1 0 1 1 1 0
g ( ) 2 2
0 else 0 else
1 0 x 1 1 x 1 x
g(x ) 2 2
0 else 0 else
Now to perform convolution, get f(α) and g(x- α)
at a particular x, and compute the integration 8
Convolution
Steps Summarization
– Compute g(-α by flipping the function w.r.t vertical
axis(y-axis)
– Compute g(x - α by shifting/sliding g(-α by x
– For any given x, get the product of f α and g x-α , by
finding the overlap of these two functions
– Keep repeating above steps for all values of x
Example:
To shift g(-α to left by 1, we
need to add -1 to g(-α in
argument, i.e. g(-1-α
This illustrates the situation
when x = -1 9
Convolution
Thus the convolution of f(x) and g(x), f(x)*g(x)
in this case has the following form:
10
Convolution
Mathematically, the output of this convolution
can be expressed by:
11
Convolution
12
Convolution in 2-D
Continuous Case
Discrete Case
13
Convolution in 2-D - Example
Consider two functions f and g as roof-top
functions in 2-D
– roof-top functions are 2-D equivalent of 1-D top-hat
functions
2D convolution of the functions will result into
images displayed below
14
Convolution Theorem
Convolution in spatial domain
– Convolution in spatial domain is very time consuming
and expensive for large size images
– If the image resolution is 32*32 or less than 64*64, it is
recommended to use the above techniques
• That is, perform convolution in the spatial domain
Use of Convolution Theorem
– Generally most of the digital images are larger in size
– In that case computation is time consuming in spatial
domain
– Hence for large images, use of convolution theorem is
recommended to get computational efficiency
15
Convolution Theorem
Convolution in spatial domain is multiplication
in frequency domain and vice versa
16
Convolution Theorem
FFT algorithm exists which computes the
Fourier transform of a digitized signal
efficiently
Hence it is recommended to
– first transform the signals to the frequency domain,
– multiply and then
– compute the inverse transform to obtain the
convolution
Since FFT is computationally efficient, this
method works faster for large images/signals
17
Periodicity of
Convolution
18
Periodicity of Convolution
Consider the convolution of
two discrete functions f
and h carried out in spatial
domain.
The result of convolution is
shown in the last figure
The result is correct
19
Periodicity of Convolution
If we use the DFT and the convolution
theorem to obtain the same result as in
the example in previous slide, we must
take into account the periodicity
inherent in the expression for the DFT
This is equivalent to convolving the two
periodic functions f and h
The convolution procedure is the same
as we just discussed, but the two
functions now are periodic.
Proceeding with these two functions as
in the previous case would yield the
result in the last image
This result is incorrect. 20
Periodicity of Convolution
The reason for incorrect result:
– Because we are convolving two periodic functions, the
convolution itself is periodic
– The closeness of the periods in functions f and h such that
they interfere with each other to cause what is commonly
referred to as wraparound error
According to the convolution theorem, if we had
computed the DFT of the two 400-point functions, f and
h, multiplied the two transforms, and then computed the
inverse DFT, we would have obtained the erroneous
400-point segment of the convolution shown in last
figure of the previous slide
21
Example Revisited
Convolution of the same
functions f and h shown in
slide 19, but taking into
account the Periodicity
implied by the DFT
Note in last figure how data
from adjacent periods
produce wraparound error,
yielding an incorrect
convolution result
To obtain the correct result,
function padding must be
used 22
Function Padding
Fortunately, the solution to the wraparound error
problem is simple.
Consider two functions, f(x) and h(x) composed of A
and B samples, respectively.
f(x) = {f(0), f(1), f(2), .., f(A-1)}
H(x) = {h(0), h(1), h(2), .., h(B-1)}
It is shown that if we append zeros to both
functions so that they have the same length,
denoted by P, then wraparound is avoided by
choosing
P A + B -1
23
Function Padding
In our example, each function, f and h has
400 points, so the minimum value we could
use is P=799 which implies that we would
append 399 zeros to the trailing edge of
each function.
This process is called zero padding.
24
1-D Case – Discrete Convolution
Hence we obtain the extended functions by
padding zeros
Then convolution is given by
ce(x) is a discrete, periodic array of length M 25
2-D Case – Discrete Convolution
f(x,y) is of size A x B
g(x,y) is of size C x D
ce(x,y) is of size M x N
The extended sequences are
26
2-D Case – Discrete Convolution
The 2-D convolution formula (in spatial domain)
For efficient computation
Perform 2D-DFT of the fe(x,y) and ge(x,y)
Multiply the two functions
Take the 2D-IDFT
We obtain the same convolution function
27
Function Padding Rule
As rule, DFT algorithms tend to execute faster
with arrays of even size, so it is good practice to
select P as the smallest even integers that satisfy
the equation P A + B -1.
If the two arrays are of the same size, this means
that P is selected as twice the array size
For 2-D functions (images) of size A x B and C x D,
Padded array is of size P x Q where
P A + B -1 and Q C + D -1
That means, if the two images (arrays) are of the
same size, then P and Q are selected as twice the
image size.
28
Exercise
Analyze the effect of wraparound error on
images.
29
Padding revisited
The two functions f and h in our example,
conveniently become zero before the end of
the sampling interval.
If one or both of the functions were not zero
at the end of the interval,
– In that case a discontinuity would be created
when zeros were appended to the function to
eliminate wraparound error.
30
Padding revisited
This is analogous to multiplying a function by
a box, which in the frequency domain would
imply convolution of the original transform
with a sinc function.
31
Padding revisited
Frequency leakage
– Any type of operation which creates new frequency
components can be referred to as spectral or
frequency leakage
– multiplying a function by a box creates frequency
leakage, caused by the high frequency components
of the sinc function.
– Leakage produces a blocky effect on images.
Although leakage never can be totally
eliminated, it can be reduced significantly using
Windowing or apodizing
32
Padding revisited
Windowing or apodizing
– Reduction in frequency leakage can be achieved
using windowing or apodizing
– It is multiplying the sampled function by another
function that tapers smoothly to near zero at both
ends of the sampled record to dampen the sharp
transitions (and thus the high frequency
components) of the box.
33
Padding revisited
Windowing or apodizing
– It is an important consideration when fidelity in
image reconstruction (as in high-definition
graphics) is desired.
Use of Gaussian function for windowing
– If you are faced with the need for windowing, a
good approach is to use a 2-D Gaussian function
– One advantage of Gaussian function is that its
Fourier transform is Gaussian also, thus producing
low leakage.
34
Exercise
Analyze the effect of spectral leakage in
images caused while removing the
wraparound errors.
Analyze how the use windowing using
Gaussian function helps in reducing spectral
leakage
35
End
36