程序送上希望对你有帮助%%%%%%%%%%%%读入图像%%%%%%%%%%%%%%%I=imread('');%读入图像文件imshow(I);title('原图.tif');%显示图标题像并设置标题J=imnoise(I,'salt&pepper',);%添加加噪声密度D为的椒盐噪声figure,imshow(J);title('加入椒盐噪声.tif');%显示处理后的图像并设置标题[m,n]=size(I);f=I;fori=2:(m-1)forj=2:(n-1)iff(i,j)>3&f(i,j)<252f(i,j)=f(i,j);elsef(i,j)=*f(i,j-1)+*f(i-1,j)*f(i-1,j-1);endendendfigure,imshow(f);title('过滤后图像')