Wednesday, November 18, 2009

High Pass Filter in Spatial Domain

CODE

% High pass filter done on an image

clear all
clc

a = imread('cameraman.tif');
p = double(a);

w=[-1 -1 -1;-1 8 -1;-1 -1 -1] %Creating the high pass average mask

[row col]=size(p)

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

figure(1)
imshow(uint8(p))
title('Original Image');

figure(2)
imshow(uint8(p1))
title('Image after ''High Pass'' Filtering');

No comments:

Post a Comment