Lab6-Noise Filtering in Spatial Domain
Lab6-Noise Filtering in Spatial Domain
Student Id No:
Remarks if any:
Spatial filtering is an image processing technique for changing the intensities of a pixel
according to the intensities of the neighboring pixels. The spatial filtering can be character-
rized as a “fold, shift multiply and add” operation: the kernel folds and shifts over the initial
image producing a mask and multiplies its value with the corresponding pixel values of the
image. The resultant average is a new value that replaces the central value of the mask in
the new image. For example, filtering an image results in emphasize certain features or
remove other features. Image processing operations implemented with filtering include
smoothing, sharpening, and edge enhancement.
Noise Removal: Digital images are prone to various types of noise. Noise is the result of
errors in the image acquisition process that result in pixel values that do not reflect the true
intensities of the real scene. There are several ways that noise can be introduced into an
image, depending on how the image is created. For example:
a) If the image is scanned from a photograph made on film, the film grain is a source of
noise. Noise can also be the result of damage to the film, or be introduced by the
scanner itself.
b) If the image is acquired directly in a digital format, the mechanism for gathering the
data (such as a CCD detector) can introduce noise.
c) Electronic transmission of image data can introduce noise.
To simulate the effects of some of the problems listed above, the toolbox provides
the imnoise function, which you can use to add various types of noise to an image. The
examples in this section use this function.
Remove Noise by Linear Filtering: Linear filtering is used to remove certain types of
noise. Certain filters, such as averaging or Gaussian filters, are appropriate for this purpose.
Digital Image Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
For example, an averaging filter is useful for removing grain noise from a photograph.
Because each pixel gets set to the average of the pixels in its neighborhood, local variations
caused by grain are reduced.
The Mathlab Image Processing Toolbox supports a number of predefined 2-D linear spatial
filters, obtained by using function fspecial, which generates a filter mask, w, using the
syntax
w = fspecial('type', parameters)
where 'type' specifies the filter type, and parameters further define the specified filter.
Refer for the spatial filters supported by fspecial are summarized in Table 3.4, section
3.5 of text book Digital Image Processing using Matlab by Gonzalez.
The students are advised to study about the various types of noise corrupted the images in
various applications.
Mean Fltering: The mean filter is perhaps the simplest linear filter and operates by giving
1
equal weight W k to all pixels in the neighbourhood. A weight of W k = is used for an N x
MN
M neighbourhood and has the effect of smoothing the image, replacing every pixel in the
output image with the mean value from its NM neighbourhood. This weighting scheme
guarantees that the weights in the kernel sum to one over any given neighbourhood size.
Mean filters can be used as a method to suppress noise in an image. Another common use
is as a preliminary processing step to smooth the image in order that some subsequent
processing operation will be more effective.
Exercise 6.1: (a) Comment on the results of the above two examples.
(b) Now apply 5X5 and 7X7 average filter kernels for suppressing the Gaussian
noise. Now display the resultant denoised images. What affects you are
Digital Image Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
Median filtering: Another commonly used filter is the median filter that overcomes the main
limitations of the mean filter, albeit at the expense of greater computational cost. As each
pixel is addressed, it is replaced by the statistical median of its N X M neighbourhood rather
than the mean. The median filter is superior to the mean filter in that it is better at preserving
sharp high-frequency detail (i.e. edges) whilst also eliminating noise, especially isolated
noise spikes (such as ‘salt and pepper’ noise). By definition, the median operator requires an
ordering of the values in the pixel neighbourhood at every pixel location. This increases the
computational requirement of the median operator.
Example3:
Refer DIP_Ex_6_3.m
< Type the Matlab codes here >
< Plot the figures and type the results here >
Exercise2:
(a) Comment on the results.
(b) Now apply 5X5 and 7X7 filter kernels and display the resultant denoised
images. What affects you are observed on the resulting images? Comment
on the results.
(c) Now change the noise variance as (i) 0.1 and (ii) 0.5 for both Gaussian
and Salt and Pepper and apply to the original image. Display the resultant
noisy images. What do you observed in these noisy images?
(d) Apply the average filters 3X3, 5X5, and 7X7 to the noisy images generated
in (c) i.e., and display the resultant denoised images. What affects you are
observed on the resulting images? Comment on the results.
(e) Repeat the above steps for any image of your choice.
Digital Image Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
Rank filtering: The median filter is really just a special case of a generalized order (or
rank) filter. Order filters which select the maximum and minimum values in the defined
neighbourhood are (unsurprisingly) called maximum and minimum filters.
clear; close all; clc;
I = imread(‘eight.tif’); %Read in image
% Add Gaussian noise (with 0.02 variance)
Ig = imnoise(I,‘gaussian’,0.02);
% Add Salt and Pepper noise (with 0.03 variance)
Isp = imnoise(I,‘salt & pepper’,0.03);
Figure();
%Display the order statistical filtered original image
subplot(1,3,1);imshow(Im);
title(‘order statistical filtered original image’);
subplot(1,3,2);imshow(Igm);
title(‘order statistical filtered Gaussian noisy image’);
subplot(1,3,3);imshow(Ispm);
title(‘order statistical filtered salt & pepper noisy image’);
Exercise3:
(a) Comment on the results.
(b) Now apply 5X5 and 7X7 filter kernels and display the resultant denoised
images. What affects you are observed on the resulting images? Comment
on the results.
(c) Now change the noise variance as (i) 0.1 and (ii) 0.5 for both Gaussian
Digital Image Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
and Salt and Pepper and apply to the original image. Display the
resultant
noisy images. What do you observed in these noisy images?
(d) Apply the average filters 3X3, 5X5, and 7X7 to the noisy images generated
in (c) i.e., and display the resultant denoised images. What affects you are
observed on the resulting images? Comment on the results.
(e) Change the order from 9, 16 and 36 to the above in (d) display the results.
(f) Repeat the above steps for any image of your choice.
Gaussian filtering: The Gaussian filter has the effect of smoothing the image, but it is used
in a way that is somewhat different to the mean filter. First, the degree of smoothing is
controlled by the choice of the standard deviation parameters, not by the absolute value of
the kernel size (which is the case with the mean filter). Second, the Gaussian function has a
rather special property, namely that its Fourier transform is also a Gaussian function, which
makes it very convenient for the frequency-domain analysis of filters.
a)
SALT & PEPPER NOISE
I = imread('cameraman.tif');
subplot(2,2,1);imshow(I)title('Original Image')
J = imnoise(I,'salt & pepper',0.05);
subplot(2,2,2);imshow(J);title('Image with Salt & Pepper Noise')
K = filter2(fspecial('average',3),J)/255;
subplot(2,2,3);imshow(K);title('Filtered Image by Mean filter')
M = medfilt2(J);
subplot(2,2,4); imshow(M)title('Filtered Image by Median filter')
b)
GAUSSIAN NOISE
I=imread('cameraman.tif');
subplot(221);imshow(I)title('Original Image')
J=imnoise(I,'gaussian',0.02);
K=wiener2(J,[55]);
c)
SPECKLE NOISE
I=imread('cameraman.tif');
subplot(221);imshow(I);title('Original Image')
J=imnoise(I,'speckle',0.02);
subplot(222);imshow(J);title('Image with Speckle Noise');
K=wiener2(J,[55]);
Digital Image Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:
POISSON NOISE
I=imread('cameraman.tif');
subplot(221);imshow(I)title('Original Image')
J=imnoise(I,'poisson’);
subplot(222);imshow(J);title('Image with Poisson Noise');
K=wiener2(J,[55]);
M = filter2(fspecial('average',3),J)/255;