Lab Assignment
Making a Lot of Noise
First we take an image and corrupt it using
two types of noise: additive Gaussian noise, and salt and pepper
noise. Salt and pepper noise is a set of impulses randomly placed on the
image plane.
Using MATLAB, load lena.raw:
fid = fopen('lena.raw', 'r');
lena = fread(fid, [512, 512]);
lena = lena' / 255;
and generate two noisy versions of lena
lena_g = imnoise(lena, 'gaussian');
lena_s = imnoise(lena, 'salt & pepper');
Display lena_g and lena_s (using the matlab function imshow() for example) and describe in
your report how each type of noise affects the image quality.
Part A. Linear Filtering
Now we look at how two types of linear filters affect the noisy images.
Create two filters
h_gauss = fspecial ('gaussian', 5, 0.5);
h_log = fspecial ('log', 5, 0.5);
h_gauss is a Gaussian filter with a window of size 5x5 and a
main lobe width of 0.5. h_log is a 5x5 Laplacian of Gaussian
filter with a standard deviation of 0.5. The Gaussian filter is a low pass
filter, and the Laplacian of Gaussian filter can be thought of as the "second
derivative" of the Gaussian filter. Apply these filters to lena_g and
lena_s:
lena_g_smoothed = filter2 (h_gauss, lena_g);
lena_s_smoothed = filter2 (h_gauss, lena_s);
lena_g_logged = filter2 (h_log, lena_g);
lena_s_logged = filter2 (h_log, lena_s);
Vary the main lobe size (say 0.25, 0.5 and 1.0) and window size (say 5x5 and 10x10) of h_gauss and vary the window
size (say 5x5 and 10x10) and standard deviation (say 0.5 and 1.0) of h_log. View the output images in each
case, then summarize your observations in your report.
You should see that the filters are not very effective at removing salt and
pepper noise.
Part B. Median Filtering
A median filter is better at removing salt and pepper noise than the
two linear filters above. A median filter computes the median value in an
nxn block and sets the center pixel of the block to the
median value. Apply a 3x3 median filter to lena_s:
lena_s_median = medfilt2 (lena_s, [3 3]);
Compare lena_s_median with lena_s_smoothed and
lena_s_logged from Part A. Vary the median filter's size and
describe in your report how it affects the image.
Applying the median filter to lena_g and rate its performance. You
should see that the median filter tends to round the "corners" in the image; it
does not preserve the original image information.
Part B2: Ad Infinitum
Repeatedly apply the median filter (of size 3x3) several times (say 50 time) to the image and report
your observations (write a loop in MATLAB). In your report,
inlcude a printout of the final image, and comment on its appearance.
Lab 8 p.2 - Assignment
Last Edit 11-Mar-07