www.gusucode.com > 《matlab图像处理与界面编程宝典》秦襄培 编著,每章的MATLAB源代码程序 > 第18章/代码18-8.txt
I=imread('eight.tif'); % 读入图像 subplot(2,3,1),imshow(I); % 显示原始图像 title('original image'); % 设置图像标题 J=imnoise(I,'salt & pepper',0.02); % 加均值为 0,方差为 0.02 的椒盐噪声 subplot(2,3,2),imshow(J); % 显示处理后的图像 title('salt & pepper noise image'); % 设置图像标题 text(-20,320,'Med-value Filter for 3*3 window '); % 添加说明文字 K = medfilt2(J); %用于3×3的滤波窗口对图像J进行中值滤波。 %若用[m,n]的滤波窗口做中值滤波,语法为 K = medfilt2(J,[m,n]) subplot(2,3,3),imshow(K,[]); % 显示处理后的图像 title('medfilter image'); % 设置图像标题 I2=imread('eight.tif'); % 读入图像 subplot(2,3,4),imshow(I2); % 显示原始图像 title('original image'); % 设置图像标题 J2=imnoise(I2,'gaussian',0.02); % 加均值为 0,方差为 0.02 的高斯噪声 subplot(2,3,5),imshow(J2); % 显示处理后的图像 title('gaussian noise image'); % 设置图像标题 K2 = medfilt2(J2); % 图像滤波处理 subplot(2,3,6),imshow(K2,[]); % 显示处理后的图像 title('medfilter image'); % 设置图像标题 I=imread('eight.tif'); % 读入图像 subplot(2,3,1),imshow(I); % 显示原始图像 title('original image'); % 设置图像标题 J=imnoise(I,'salt & pepper',0.02); % 加均值为 0,方差为 0.02 的椒盐噪声 subplot(2,3,2),imshow(J); % 显示处理后的图像 title('salt & pepper noise image'); % 设置图像标题 text(-20,320,'Med-value Filter for 5*5 window '); % 添加说明文字 K = medfilt2(J,[5,5]); %用于5×5的滤波窗口对图像J进行中值滤波。 %若用[m,n]的滤波窗口做中值滤波,语法为 K = medfilt2(J,[m,n]) subplot(2,3,3),imshow(K,[]); % 显示处理后的图像 title('medfilter image'); % 设置图像标题 I2=imread('eight.tif'); % 读入图像 subplot(2,3,4),imshow(I2); % 显示原始图像 title('original image'); % 设置图像标题 J2=imnoise(I2,'gaussian',0.02); % 加均值为 0,方差为 0.02 的高斯噪声 subplot(2,3,5),imshow(J2); % 显示处理后的图像 title('gaussian noise image'); % 设置图像标题 K2 = medfilt2(J2,[5,5]); % 图像滤波处理 subplot(2,3,6),imshow(K2,[]); % 显示处理后的图像 title('medfilter image'); % 设置图像标题