图像处理(三) 均值滤波与中值滤波的对比

均值滤波与中值滤波的对比

均值滤波与中值滤波

均值滤波是典型的线性滤波算法,均值滤波是对目标像素及周边像素取平均值后再填回目标像素来实现滤波目的的方法,通常用卷积来实现,由于其平均化的本质,该方法不能很好地保护图像细节,在图像去噪的同时也破坏了图像的细节部分,从而使图像变得模糊,不能很好地去除噪声点。中值滤波法是一种非线性平滑技术,它将每一像素点的灰度值设置为该点某邻域窗口内的所有像素点灰度值的中值,中值滤波对脉冲噪声有良好的滤除作用,特别是在滤除噪声的同时,能够保护信号的边缘,使之不被模糊。

实验对比

在这里插入图片描述

均值滤波对椒盐噪声的滤波效果不明显,同时导致图像模糊,并且尺度越大模糊程度越明显

在这里插入图片描述

中值滤波对椒盐噪声的滤波效果明显,同时可以保持原图清晰度

通过均值滤波与中值滤波运行结果的对比,可以看出中值滤波法对消除椒盐噪声非常有效,而均值滤波对椒盐噪声基本无作用。同时均值滤波使得图像整体更加模糊,该效果随着均值滤波的尺寸增大而更加明显,而中值滤波不会出现这样的问题。

matlab 代码

clc
clear
close all
image=imread('Fig1.tif');
subplot(2,2,1)
imshow(image)
title('原图')
%均值滤波
w1=fspecial('average',[3 3]);
image_average_3=imfilter(image,w1,'replicate');
subplot(2,2,2)
imshow(image_average_3)
title('3x3均值滤波')

w1=fspecial('average',[5 5]);
image_average_5=imfilter(image,w1,'replicate');
subplot(2,2,3)
imshow(image_average_5)
title('5x5均值滤波')

w1=fspecial('average',[7 7]);
image_average_7=imfilter(image,w1,'replicate');
subplot(2,2,4)
imshow(image_average_7)
title('7x7均值滤波')

%% 中值滤波
figure
image=imread('Fig1.tif');
subplot(2,2,1)
imshow(image)
title('原图')

subplot(2,2,2)
image_mean_3=medfilt2(image,[3,3]);
imshow(image_mean_3)
title('3x3中值滤波')

subplot(2,2,3)
image_mean_5=medfilt2(image,[5,5]);
imshow(image_mean_5)
title('5x5中值滤波')

subplot(2,2,4)
image_mean_7=medfilt2(image,[7,7]);
imshow(image_mean_7)
title('7x7中值滤波')


clc
clear
close all
image=imread('lena.png');
image=rgb2gray(image);
image=imnoise(image,'salt & pepper',0.2);
subplot(2,2,1)
imshow(image)
title('加入椒盐噪声的lena图')
%均值滤波
w1=fspecial('average',[3 3]);
image_average_3=imfilter(image,w1,'replicate');
subplot(2,2,2)
imshow(image_average_3)
title('3x3均值滤波')

w1=fspecial('average',[5 5]);
image_average_5=imfilter(image,w1,'replicate');
subplot(2,2,3)
imshow(image_average_5)
title('5x5均值滤波')

w1=fspecial('average',[7 7]);
image_average_7=imfilter(image,w1,'replicate');
subplot(2,2,4)
imshow(image_average_7)
title('7x7均值滤波')

%% 中值滤波
figure
subplot(2,2,1)
imshow(image)
title('加入椒盐噪声的lena图')

subplot(2,2,2)
image_mean_3=medfilt2(image,[3,3]);
imshow(image_mean_3)
title('3x3中值滤波')

subplot(2,2,3)
image_mean_5=medfilt2(image,[5,5]);
imshow(image_mean_5)
title('5x5中值滤波')

subplot(2,2,4)
image_mean_7=medfilt2(image,[7,7]);
imshow(image_mean_7)
title('7x7中值滤波')



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ACE_coder

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值