%平滑
I=imread('coins.tif');
Inoised=imnoise(I,'gaussian',0.1,0.004);
h=ones(3,3)/5;
h(1,1)=0;
h(1,3)=0;
h(3,1)=0;
h(1,3)=0;
I2=imfilter(Inoised,h);
subplot(2,1,1);imshow(Inoised);
subplot(2,1,2);imshow(I2);
%中值滤波
I=imread('coins.tif');
J=imnoise(I,'salt&pepper',0.02);
K=medfilt2(J);
subplot(1,2,1);imshow(J);
subplot(1,2,2);imshow(K);