/*MATLAB PROGRAM FOR IMAGE ENHANCEMENT USING
FILTERS*/
clc
clear
all
subplot(3,2,1)
A=imread('cameraman.tif')
colormap(gray)
imagesc(A)
title('original
image')
B=double(A)
[m
n] = size(B)
mask
= [1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9]
for
i= 2:1:m-1
for
j=2:1:n-1
L(i,j)=B(i-1,j-1)*mask(1)+B(i-1,j)*mask(2)+B(i-1,j+1)*mask(3)+B(i,j-1)*mask(4)+B(i,j)*mask(5)+B(i,j+1)*mask(6)+B(i+1,j-1)*mask(7)+B(i+1,j)*mask(8)+B(i+1,j+1)*mask(9);
end
end
subplot(3,2,2)
colormap(gray)
imagesc(L)
title('low
pass filter image')
mask1
= [-1/9 -1/9 -1/9 -1/9 8/9 -1/9 -1/9 -1/9 -1/9]
for
i=2:1:m-1
for
j=2:1:n-1
H(i,j)=B(i-1,j-1)*mask1(1)+B(i-1,j)*mask1(2)+B(i-1,j+1)*mask1(3)+B(i,j-1)*mask1(4)+B(i,j)*mask1(5)+B(i,j+1)*mask1(6)+B(i+1,j-1)*mask1(7)+B(i+1,j)*mask1(8)+B(i+1,j+1)*mask1(9);
end
end
subplot(3,2,3)
colormap(gray)
imagesc(H)
title('high
pass filter image')
BN=imnoise(A,'salt&
pepper')
subplot(3,2,4)
colormap(gray)
imagesc(BN)
title('salt
and pepper noise image')
for
i=2:1:m-1
for
j=2:1:n-1
mr=[BN(i-1,j-1)
BN(i-1,j) BN(i-1,j+1) BN(i,j-1) BN(i,j) BN(i,j+1) BN(i+1,j-1) BN(i+1,j)
BN(i+1,j+1)];
smr=sort(mr);
M(i,j)=smr(5);
end
end
subplot(3,2,5)
colormap(gray)
imagesc(M)
title('median
filter image')
s=2.5;
x=(9*s)-1;
mask1
= [-1/9 -1/9 -1/9 -1/9 x -1/9 -1/9 -1/9 -1/9]
for
i=2:1:m-1
for
j=2:1:n-1
H(i,j)=B(i-1,j-1)*mask1(1)+B(i-1,j)*mask1(2)+B(i-1,j+1)*mask1(3)+B(i,j-1)*mask1(4)+B(i,j)*mask1(5)+B(i,j+1)*mask1(6)+B(i+1,j-1)*mask1(7)+B(i+1,j)*mask1(8)+B(i+1,j+1)*mask1(9);
end
end
subplot(3,2,6)
colormap(gray)
imagesc(H)
title('high
boost filter image')
OUTPUT
No comments:
Post a Comment