Wednesday, November 18, 2009

Low Pass Filter in Spatial domain

CODE

% Low pass Average filter used on an image with Gaussian noise

clear all
clc

a = imread('cameraman.tif');
p = imnoise(a,'gaussian'); %Adding noise
q = double(p);
[row col]=size(q)

w = [1 1 1;1 1 1;1 1 1]/9 %Creating the low pass average mask

for i=2:1:row-1
for j=2:1:col-1
q1(i,j) = [ (w(1) * q(i-1,j-1)) + (w(2) * q(i-1,j)) + (w(3) * q(i-1,j+1)) + (w(4)
* q(i,j-1)) + (w(5) * q(i,j)) + (w(6) * q(i,j+1)) + (w(7) * q(i+1,j-1))
+ (w(8) * q(i+1,j)) + (w(9) * q(i+1,j+1)) ];
end
end

figure(1)
imshow(uint8(q))
title('Original Image with Gaussian Noise');

figure(2)
imshow(uint8(q1))
title('Image after using Low Pass Average Filter on Gaussian Noised image');

No comments:

Post a Comment