www.gusucode.com > 《matlab图像处理与界面编程宝典》秦襄培 编著,每章的MATLAB源代码程序 > 第18章/代码18-7.txt
I=imread('eight.tif'); % 读入图像 subplot(2,3,1),imshow(I); % 显示原始图像 title('original'); % 设置图像标题 J=imnoise(I,'salt & pepper',0.2); % 添加加噪声密度 D 为 0.2 的椒盐噪声 subplot(2,3,2),imshow(J); % 显示处理后的图像 title('noise image'); % 设置图像标题 text(-20,320,'Salt & Pepper Noise filter');% 添加说明文字 h=[1,1,1;1,0,1;1,1,1]; % 模板矩阵 h=h/8; % 产生滤波归一化的模板 K=conv2(J,h); % 用均值模板对图像滤波 subplot(2,3,3),imshow(K,[]); % 显示处理后的图像 title('filter image'); % 设置图像标题 I2=imread('eight.tif'); % 读入图像 subplot(2,3,4),imshow(I2); % 显示原始图像 title('original'); % 设置图像标题 J2=imnoise(I2,'gaussian',0.2); % 加均值为0,方差为0.2的高斯噪声 subplot(2,3,5),imshow(J2); % 显示处理后的图像 title('noise image'); % 设置图像标题 text(-20,320,'gaussian Noise filter'); % 添加说明文字 h=[1,1,1;1,0,1;1,1,1]; % 模板矩阵 h=h/8; % 产生滤波归一化的模板 K2=conv2(J2,h); % 用均值模板对图像滤波 subplot(2,3,6),imshow(K2,[]); % 显示处理后的图像 title('filter image'); % 设置图像标题