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


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



所有评论(0)