Download the files race.tif, noise1.tif and noise2.tif for this exercise.
Click here for help on the Matlab mesh command.
Among the many spatial lowpass filters, the Gaussian filter is of particular
importance.
This is because it results in very good spatial and
spectral localization characteristics.
The Gaussian filter has the form
h
(
i
,
j
)
=
C
exp
(

i
2
+
j
2
2
σ
2
)
h
(
i
,
j
)
=
C
exp
(

i
2
+
j
2
2
σ
2
)
(8)where σ2σ2, known as the variance, determines the size of
passband area. Usually the Gaussian filter is normalized by a scaling constant
CC such that the sum of the filter coefficient magnitudes is one,
allowing the average intensity of the image to be preserved.
∑
i
,
j
h
(
i
,
j
)
=
1
∑
i
,
j
h
(
i
,
j
)
=
1
(9)Write a Matlab function that will create a normalized
Gaussian filter that is centered around the origin
(the center element of your matrix should be h(0,0)h(0,0)).
Note that this filter is both separable and
symmetric, meaning
h(i,j)=h(i)h(j)h(i,j)=h(i)h(j) and h(i)=h(i)h(i)=h(i).
Use the syntax
h=gaussFilter(N, var)
where N
determines the size of filter, var
is the variance, and
h
is the N×NN×N filter. Notice that for this filter to
be symmetrically centered around zero, NN will need to be an odd number.
Use Matlab to compute the frequency response of a 7×77×7
Gaussian filter with σ2=1σ2=1. Use the command
H = fftshift(fft2(h,32,32));
to get a 32×3232×32 DFT.
Plot the magnitude of the frequency response
of the Gaussian filter, HGauss(ω1,ω2)HGauss(ω1,ω2), using the
mesh
command. Plot it over the region [π,π]×[π,π][π,π]×[π,π],
and label the axes.
Filter the image contained in the file
race.tif
with a 7×77×7 Gaussian filter, with σ2=1σ2=1.
You can filter the signal by using the Matlab command
Y=filter2(h,X);
,
where XX
is the matrix containing the input image and
hh
is the impulse response of the filter.
Display the original and the filtered images, and notice the blurring
that the filter has caused.
Now write a Matlab function to implement a 3×33×3
median filter (without using the medfilt2
command).
Use the syntax
Y = medianFilter(X);
where X
and Y
are the input and output image matrices,
respectively.
For convenience, you do not have to alter the pixels on the border of XX.
Use the Matlab command median
to find the median value of
a subarea of the image, i.e. a 3×33×3 window surrounding each pixel.
Download the image files
noise1.tif
and
noise2.tif
.
These images are versions of the previous race.tif image that have been degraded by
additive white Gaussian noise and "salt and pepper" noise, respectively.
Read them into Matlab, and display them using image
.
Filter each of the noisy images with both the 7×77×7
Gaussian filter (σ2=1σ2=1) and the 3×33×3 median filter.
Display the results of the filtering, and place a title on each figure.
(You can open several figure windows using the figure
command.)
Compare the filtered images with the original noisy images.
Print out the four filtered pictures.

Hand in your code for
gaussFilter
and medianFilter
.
 Hand in the plot of HGauss(ω1,ω2)HGauss(ω1,ω2).
 Hand in the results of filtering the noisy images (4 pictures).
 Discuss the effectiveness of each filter for the case of additive
white Gaussian noise. Discuss both positive and negative effects
that you observe for each filter.
 Discuss the effectiveness of each filter for the case of
"salt and pepper" noise. Again, discuss both positive and
negative effects that you observe for each filter.