多种滤波在图像处理中的对比

% 自选图像,添加高斯噪声椒盐噪声,然后对比高斯滤波、均值滤波和中值滤波的去噪效果。
im=imread('shucai.png');
imshow(im);
% 1)生成含有高斯噪声、椒盐噪声的图像
% imnoise 是表示添加噪声污染一幅图像,叫做噪声污染图像函数
im_noise_salt = imnoise(im,'salt & pepper'); % 加入椒盐噪声
im_noise_gaussian = imnoise(im,'gaussian'); % 加入高斯噪声
 
%figure;
subplot(131),imshow(im);title('彩色原图');
subplot(132),imshow(im_noise_salt);title('加入椒盐噪声后的图像');
subplot(133),imshow(im_noise_gaussian);title('加入高斯噪声后的图像');
%获得灰度图
I=rgb2gray(im);
S=rgb2gray(im_noise_salt);
G=rgb2gray(im_noise_gaussian);
subplot(131),imshow(I);title('灰度原图');
subplot(132),imshow(S);title('加入椒盐噪声后的图像');
subplot(133),imshow(G);title('加入高斯噪声后的图像');

%高斯滤波
f1=fspecial('gaussian', 3, 1);
subplot(121),imshow(S);title('加入椒盐噪声后的图像');
subplot(122),imshow(imfilter(S,f1));title('高斯滤波处理椒盐图像');

subplot(121),imshow(G);title('加入高斯噪声后的图像');
subplot(122),imshow(imfilter(G,f1));title('高斯滤波处理高斯图像');

%均值滤波
f2=fspecial('average',3);
subplot(121),imshow(S);title('加入椒盐噪声后的图像');
subplot(122),imshow(imfilter(S,f2));title('均值滤波处理椒盐图像');

subplot(121),imshow(G);title('加入高斯噪声后的图像');
subplot(122),imshow(imfilter(G,f2));title('均值滤波处理高斯图像');

%中值滤波
subplot(121),imshow(S);title('加入椒盐噪声后的图像');
subplot(122),imshow(medfilt2(S));title('中值滤波处理椒盐图像');

subplot(121),imshow(G);title('加入高斯噪声后的图像');
subplot(122),imshow(medfilt2(G));title('中值滤波处理高斯图像');

%综合对比图
SG=rgb2gray(imnoise(im_noise_salt,'gaussian')); % 加入椒盐噪声和高斯噪声
subplot(431),imshow(S);title('加入椒盐噪声后的图像');
subplot(432),imshow(G);title('加入高斯噪声后的图像');
subplot(433),imshow(SG);title('加入椒盐+高斯噪声后的图像');
subplot(434),imshow(imfilter(S,f1));title('高斯滤波处理椒盐图像');
subplot(435),imshow(imfilter(G,f1));title('高斯滤波处理高斯图像');
subplot(436),imshow(imfilter(SG,f1));title('高斯滤波处理椒盐+高斯图像');
subplot(437),imshow(imfilter(S,f2));title('均值滤波处理椒盐图像');
subplot(438),imshow(imfilter(G,f2));title('均值滤波处理高斯图像');
subplot(439),imshow(imfilter(SG,f2));title('均值滤波处理椒盐+高斯图像');
subplot(4,3,10),imshow(medfilt2(S));title('中值滤波处理椒盐图像');
subplot(4,3,11),imshow(medfilt2(G));title('中值滤波处理高斯图像');
subplot(4,3,12),imshow(medfilt2(SG));title('中值滤波处理椒盐+高斯图像');
 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值