0% found this document useful (0 votes)
99 views8 pages

Lab6-Noise Filtering in Spatial Domain

This document provides instructions for a lab on noise filtering in the spatial domain. It discusses different types of noise that can affect digital images, such as Gaussian noise and salt and pepper noise. It then describes several noise removal techniques using linear spatial filters, including mean filtering, median filtering, and order statistical filtering. Students are asked to add noise to test images, apply various filtering kernels to denoise the images, and observe and comment on the results. Exercises are provided to experiment with different noise levels, filter sizes, and order statistical filtering.
Copyright
© Public Domain
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views8 pages

Lab6-Noise Filtering in Spatial Domain

This document provides instructions for a lab on noise filtering in the spatial domain. It discusses different types of noise that can affect digital images, such as Gaussian noise and salt and pepper noise. It then describes several noise removal techniques using linear spatial filters, including mean filtering, median filtering, and order statistical filtering. Students are asked to add noise to test images, apply various filtering kernels to denoise the images, and observe and comment on the results. Exercises are provided to experiment with different noise levels, filter sizes, and order statistical filtering.
Copyright
© Public Domain
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Digital Image Processing Lab, Dept. of ECE, KL University, A.P., India.

Student Id No:

Name:            Lab Section: Id No:


Pre-lab Session In-Lab Session Post Lab session Viva Total Marks
work (5M) work (15M) work (5M) (5M) 30M

Remarks if any:

Date: Signature of the Instructor Marks awarded

Digital Image Processing-Lab (15-EC 4110L)


Lab6-Noise Filtering in Spatial Domain

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.

Example1: Removing the Gaussian noise using Average filtering


Refer DIP_Ex_6_1.m
< Type the Matlab codes here >
< Plot the figures and type the results here >
Example2: Removing the Salt and Pepper noise using Average filtering
Refer DIP_Ex_6_2.m
< Type the Matlab codes here >
< Plot the figures and type the results here >

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:

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 above image. Display the resultant
noisy images. What do you observed in these noisy images?
(d) Apply the average filters with kernels, 3X3, 5X5, and 7X7 for the images
generated in (c) 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.

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);

% Apply order statistical filter with kernel size 3X3, order=25 to


% the original image
Im = ordfilt2(I,25,ones(5,5));

%Apply order statistical filter with size 3X3, order=25 to the


Gaussian noisy %image
Igm = ordfilt2(Ig,25,ones(5,5)));

% Apply order statistical filter with size 3X3, order = 25 to the


% salt & pepper noisy image
Ispm = ordfilt2(Isp,25,ones(5,5)));

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.

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);

K = fspecial(‘gaussian’, [5 5], 2); %Define Gaussian filter with σ = 2


Ig = imfilter(I,k); %Apply to original image
Ispg = imfilter(Isp,k); %Apply to salt and pepper image
Igg = imfilter(Ig,k); %Apply to Gaussian image
subplot(1,3,1); imshow(Ig); %Display result image
subplot(1,3,2); imshow(Ispg); %Display result image
subplot(1,3,3); imshow(Igg); %Display result image
Exercise4:
(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
Digital Image Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

noisy images. What do you observed from 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 sigma for various values (i) σ = 3 (ii) σ = 5, and (iii) σ = 7.
(f) Repeat the above steps for any image of your choice.

Periodic Noise suppression:


Digital Image Processing Lab, Dept. of ECE, KL University, A.P., India. Student Id No:

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);

subplot(222);imshow(J)title('Image with Gaussian Noise')

K=wiener2(J,[55]);

subplot(223);imshow(K);title('Filtered Image by Wiener Filter')

 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:

subplot(223);imshow(K);title('Filtered Image by Wiener Filter')


M = medfilt2(J);
subplot(2,2,4);imshow(M)title('Filtered Image by Median filter')

 
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]);

subplot(223);imshow(K);title('Filtered Image by Wiener Filter')

M = filter2(fspecial('average',3),J)/255;

subplot(2,2,3);imshow(M)title('Filtered Image by Mean filter')

You might also like