%添加了典型噪声的图像滤波程序
A=imread('F:\滤波作业ut.BMP');
I=imnoise(A,'gaussian',0,0.01); %加入均值为 0、方差为 0.01
的高斯噪声
X=imnoise(A,'salt & pepper', 0.01); %加入椒盐噪声
figure,subplot(2,2,1),imshow(I);title('图 1.1 加高斯噪声后的
图像');
subplot(2,2,2),imshow(X);title('图 1.2 加椒盐噪声后的图像');
subplot(2,2,3),imhist(I);title('图 1.3 加高斯噪声后的直方图
');
subplot(2,2,4),imhist(X);title('图 1.4 加椒盐噪声后的直方图')
%加入椒盐噪声的图像经各种滤波后的程序
A1=imfilter(X,ones(3,3)/9);
figure,subplot(2,2,1),imshow(A1); title('图 2.1 均值滤波的图
像');
A2=medfilt2(X); %默认的模板为 3×3
subplot(2,2,2),imshow(A2); title('图 2.2 中值滤波的图像');
A3=ordfilt2(X,1,ones(3,3));
subplot(2,2,3),imshow(A3); title('图 2.3 最小值滤波的图像');
A4=ordfilt2(X,9,ones(3,3));
subplot(2,2,4),imshow(A4); title('图 2.4 最大值滤波的图像');
评论0