3 3 mask(center 4) |
3 3 mask (center 8) |
5 5 mask (center 12) |
5 5 mask (center 24) |
clc
clear all
close all
img=imread('11.bmp');
A=double(img);
[m,n]=size(A);
B=zeros(m+3,n+3);
B1=zeros(m+3,n+3);
% mask=[-1,-1,-1,-1,-1;
% -1,-1,-1,-1,-1;
% -1,-1,24,-1,-1;
% -1,-1,-1,-1,-1;
% -1,-1,-1,-1,-1];
mask=[0 , 0, -1, 0, 0;
0 ,-1, -1,-1, 0;
-1,-1, 12,-1,-1;
0, -1, -1,-1, 0;
0, 0, -1, 0, 0];
% mask1=[-1,-1,-1;
% -1, 8,-1;
% -1,-1,-1];
mask1=[0,-1,0;
-1, 4,-1;
0,-1,0];
for i=2:m
for j=2:n
B(i,j)=A(i-1,j-1);
B1(i,j)=A(i-1,j-1);
end
end
[m1,n1]=size(mask);
[m2,n2]=size(mask1);
Fsize=m1*n1;
Fsize1=m2*n2;
sum=0;
sum1=0;
row=0;
col=0;
for i=1:m
for j=1:n
for k=i:(i+m1-3)
row=row+1;
for l=j:(j+m1-3)
col=col+1;
sum=sum+(B(k,l)*mask(row,col));
end
col=0;
end
row=0;
for k=i:(i+m2-1)
row=row+1;
for l=j:(j+m2-1)
col=col+1;
sum1=sum1+(B1(k,l)*mask1(row,col));
end
col=0;
end
row=0;
B(i,j)=sum/Fsize;
B1(i,j)=sum1/Fsize1;
sum=0;
sum1=0;
end
end
% imshow(uint8(B));
% title('Laplacian Image');
% figure;
imshow(uint8(A));
title('Orignal Image');
for i=2:m
for j=2:n
B(i,j)=A(i,j)+B(i,j);
B1(i,j)=A(i,j)+B1(i,j);
end
end
figure
imshow(uint8(B));
imwrite(uint8(B),'5_5_Mask(Center 12)','bmp');
title('Final Image with 5*5 mask');
figure
imshow(uint8(B1));
imwrite(uint8(B1),'3_3_Mask(Center 4).bmp','bmp');
title('Final Image with 3*3 mask');
No comments:
Post a Comment