基于matlab的图像处理——高斯噪声&均值滤波,椒盐噪声&中值滤波

 
 
 
 
 
 
figure
oriImg=imread('peppers.bmp');%读取并显示原有图像
subplot(1,2,1); imshow(oriImg); title ('原始图像');%显示原始图像

grayImg = rgb2gray(oriImg);%转成灰度图像
subplot(1,2,2); imshow(grayImg); title ('灰度图像');%显示灰度图像

figure
%加入高斯噪声,使用邻域平均滤波
Inoise=imnoise(grayImg,'gaussian',0,0.02);%对图像加入高斯噪声
subplot(1,2,1); imshow(Inoise); title('加入高斯噪声后的图像');%显示高斯噪声图像

h=ones(3,3)/8; h(2,2)=0;%构造邻域窗口
filters=imfilter(Inoise,h);%邻域平均滤波
subplot(1,2,2); imshow(filters); title('8邻域平均滤波后的图像')

figure
%加入椒盐噪声,使用中值滤波
Inoise=imnoise(grayImg,'salt & pepper');%加入椒盐噪声
subplot(1,2,1); imshow(Inoise); title('加入椒盐噪声后的图像');

filters=medfilt2(Inoise,[5,5]);%中值滤波
subplot(1,2,2); imshow(filters); title('中值滤波后的图像')

对于滤波方式要采用有针对性的,才会达到很好的效果。对于高斯噪声采用邻域均值滤波效果比较好,经过测试采用3x3,8邻域的滤波效果比较好。
而对于椒盐噪声,采用中值滤波效果很好,实验结果如下图,仅供参考。
 
 

  



猜你喜欢

转载自blog.csdn.net/seven159/article/details/72858703
今日推荐