1. 对给定的同一幅图像,加上不同强度的高斯噪声,分别使用均值滤波器、中值滤波器、高斯平滑滤波器对加噪后的图像进行滤波处理。
2. 对给定的同一幅图像,加上不同强度的椒盐噪声,分别使用均值滤波器、中值滤波器、高斯平滑滤波器对加噪后的图像进行滤波处理。
example 1:对灰度图片加入高斯噪声
I=imread('peppers.png'); subplot(2,3,1) imshow(I) title('\itOriginal image')%显示原始图像 [width,height,z]=size(I);%判断一幅图像是否为灰度图像 if(z>1) I=rgb2gray(I); end subplot(2,3,2); imshow(I); title('\itGray image');%转为灰度图像 av=0; std=0.09; u1=rand(width,height); u2=rand(width,height); x=std*sqrt(-2*log(u1)).*cos(2*pi*u2)+av;%加入高斯噪声,均值为0,标准差为0.1 I=double(I)/255+x; I=uint8(255*I); subplot(2,3,3); imshow(I); title('\itGaussian noise'); %中值滤波 subplot(2,3,4) medres=medfilt2(I); imshow(medres) title('\itMedian filter') %均值滤波 subplot(2,3,5) A=fspecial('average'); avres=filter2(A,I)/255; imshow(avres) title('\itAverage Filter') %高斯滤波 subplot(2,3,6) gaussres=imgaussfilt(I); imshow(gaussres) title('\itGaussian Filter')
效果展示:
example 2:对灰度图片加椒盐噪声
I=imread('peppers.png'); subplot(2,3,1) imshow(I) title('\itOriginal image')%显示原始图像 [width1,height1,z1]=size(I); if(z1>1) I=rgb2gray(I); end subplot(2,3,2); imshow(I); title('\itGray image');%产生灰度图像 k1=0.1; k2=0.3; a1=rand(width1,height1)<k1;%随机产生椒盐噪声 a2=rand(width1,height1)<k2; I(a1&a2)=0; I(a1& ~a2)=255; subplot(2,3,3); imshow(I); title('salt pepper noise'); %中值滤波 subplot(2,3,4) medres=medfilt2(I); imshow(medres) title('\itMedian Filter') %均值滤波 subplot(2,3,5) A=fspecial('average'); avres=filter2(A,I)/255; imshow(avres) title('\itAverage Filter') %高斯滤波 subplot(2,3,6) gaussres=imgaussfilt(I); imshow(gaussres) title('\itGaussian Filter')
效果展示:
以上结果表明,均值滤波对于高斯噪声具有较好处理效果,中值滤波对于椒盐噪声具有较好处理效果,高斯滤波在后续图像处理方面具有较好应用,如LOG或者DOG算子。
【尊重作者劳动成果,转载请声明】