clear;
B=imread('E:1/1.bmp');
figure,imshow(B);
%求高斯阵
G33=zeros(3,3);%3*3的
G77=zeros(7,7);%7*7的
G91111=zeros(11,11);%11*11的
%求G33
G(1,1)=exp(-(1+1)/2);
for j=-1:1
for i=-1:1
G33(j+2,i+2)=exp(-(j^2+i^2)/2)/G(1,1);
end
end
%求G77
G(1,1)=exp(-(9+9)/2);
for j=-3:3
for i=-3:3
G77(j+4,i+4)=exp(-(j^2+i^2)/2)/G(1,1);
end
end
%求G1111
G(1,1)=exp(-(25+25)/2);
for j=-5:5
for i=-5:5
G1111(j+6,i+6)=exp(-(j^2+i^2)/2)/G(1,1);
end
end
B=double(B);
C=B;
xsize=size(B);
%用G33处理
gg=sum(G33);
gg=sum(gg);
for k=2:(xsize(1)-1)
for j=2:(xsize(2)-1)
t=sum(B(k-1:k+1,j-1:j+1).*G33);
C(k,j)=sum(t)/gg;
end
end
C=uint8(C);
figure,imshow(C);
%用G77处理
gg=sum(G77);
gg=sum(gg);
for k=4:(xsize(1)-3)
for j=4:(xsize(2)-3)
t=sum(B(k-3:k+3,j-3:j+3).*G77);
C(k,j)=sum(t)/gg;
end
end
D=uint8(C);
figure,imshow(D);
%用G1111处理
gg=sum(G1111);
gg=sum(gg);
for k=6:(xsize(1)-5)
for j=6:(xsize(2)-5)
t=sum(B(k-5:k+5,j-5:j+5).*G1111);
C(k,j)=sum(t)/gg;
end
end
E=uint8(C);
figure,imshow(E);