# 一,經典濾波算法的基本原理
###1,中值濾波和均值濾波的基本原理
參考以前轉載的博客:http://blog.csdn.net/ebowtang/article/details/38960271
###2,高斯平滑濾波基本原理
參考以前轉載的博客:http://blog.csdn.net/ebowtang/article/details/38389747
# 二,噪聲測試效果
### 1,不同噪聲效果
三幅圖各噪聲濃度分別是0.01 0.03,0.05(比如第一副圖均是加入0.01的噪聲濃度)



### 2,實驗代碼
~~~
<span style="font-size:12px;">%讀入原始圖像并顯示
image_original=imread('dog.bmp');
figure(1)
subplot(2,4,1);
imshow(image_original);
title('原輸入圖像');
axis square;
%生成含高斯噪聲圖像并顯示
pp=0.05;
image_gaosi_noise=imnoise(image_original,'gaussian',0,pp);
subplot(2,4,2);
imshow(image_gaosi_noise);
title('添加高斯噪聲后圖像');
axis square;
%生成含椒鹽噪聲圖像并顯示
d=0.05;
image_saltpepper_noise=imnoise(image_original,'salt & pepper',d);
subplot(2,4,3);
imshow(image_saltpepper_noise);
title('添加椒鹽噪聲后圖像');
axis square;
%生成含乘性噪聲圖像并顯示
var=0.05;
image_speckle_noise=imnoise(image_original,'speckle',var);
subplot(2,4,4);
imshow(image_speckle_noise);
title('添加乘性噪聲后圖像');
axis square;
%原圖像直方圖
r=0:255;
bb=image_original(:);
pg=hist(bb,r);
pgr1=pg/length(bb);
subplot(245);bar(pgr1);title('源輸入圖像的直方圖');
r=0:255;
bl=image_gaosi_noise(:);
pg=hist(bl,r);
pgr2=pg/length(bl);
subplot(246);bar(pgr2);title('高斯噪聲污染后的直方圖');
r=0:255;
bh=image_saltpepper_noise(:);
pu=hist(bh,r);
pgr3=pu/length(bh);
subplot(247);bar(pgr3);title('椒鹽噪聲污染后的直方圖');
r=0:255;
ba=image_speckle_noise(:);
pa=hist(ba,r);
pgr4=pa/length(ba);
subplot(248);bar(pgr4);title('乘性噪聲污染后直方圖');</span>
~~~
# 三,椒鹽噪聲去除能力對比
### 1,三大去噪效果
三幅圖椒鹽噪聲濃度分別是0.01 0.03,0.05(比如第一副圖均是加入0.01的椒鹽噪聲去噪對比)



### 2,實現代碼
~~~
<span style="font-size:12px;"></span><pre name="code" class="cpp">%讀入原始圖像并顯示
image_original=imread('dog.bmp');
figure(1)
subplot(2,4,1);
imshow(image_original);
title('原輸入圖像');
axis square;
%生成含高斯噪聲圖像并顯示
%pp=0.05;
%image_gaosi_noise=imnoise(image_original,'gaussian',0,pp);
%生成含椒鹽噪聲圖像并顯示
dd=0.05;
image_saltpepper_noise=imnoise(image_original,'salt & pepper',dd);
%生成含乘性噪聲圖像并顯示
%var=0.05;
%image_speckle_noise=imnoise(image_original,'speckle',var);
image_saltpepper_noise_after1=medfilt2(image_saltpepper_noise,[3,3]);
subplot(2,4,2);
imshow(image_saltpepper_noise_after1);title('中值濾波去椒鹽噪聲效果圖');
axis square;
h_gaosi1=fspecial('gaussian',3,1);
image_saltpepper_noise_after2=imfilter(image_saltpepper_noise,h_gaosi1);
subplot(2,4,3);
imshow(image_saltpepper_noise_after2);title('高斯平滑去椒鹽噪聲效果');
axis square;
image_saltpepper_noise_after3=wiener2(image_saltpepper_noise,[5 5]);
subplot(2,4,4);
imshow(image_saltpepper_noise_after3);title('維納濾波去椒鹽噪聲效果');
axis square;
%原圖像直方圖
r=0:255;
bb=image_original(:);
pg=hist(bb,r);
pgr1=pg/length(bb);
subplot(245);bar(pgr1);title('源輸入圖像的直方圖');
r=0:255;
bl=image_saltpepper_noise_after1(:);
pg=hist(bl,r);
pgr2=pg/length(bl);
subplot(246);bar(pgr2);title('中值濾波去椒鹽噪聲后的直方圖');
r=0:255;
bh=image_saltpepper_noise_after2(:);
pu=hist(bh,r);
pgr3=pu/length(bh);
subplot(247);bar(pgr3);title('高斯平滑去椒鹽噪聲后的直方圖');
r=0:255;
ba=image_saltpepper_noise_after3(:);
pa=hist(ba,r);
pgr4=pa/length(ba);
subplot(248);bar(pgr4);title('維納濾波去除椒鹽噪聲后的直方圖');
~~~
# 四,高斯噪聲去除能力對比
### 1,去噪效果對比



### 2,實驗代碼
~~~
<span style="font-size:12px;"></span><pre name="code" class="cpp">%讀入原始圖像并顯示
image_original=imread('dog.bmp');
figure(1)
subplot(2,4,1);
imshow(image_original);
title('原輸入圖像');
axis square;
%生成含高斯噪聲圖像并顯示
pp=0.05;
image_gaosi_noise=imnoise(image_original,'gaussian',0,pp);
%生成含椒鹽噪聲圖像并顯示
%dd=0.01;
%image_saltpepper_noise=imnoise(image_original,'salt & pepper',dd);
%生成含乘性噪聲圖像并顯示
%var=0.05;
%image_speckle_noise=imnoise(image_original,'speckle',var);
image_gaosi_noise_after1=medfilt2(image_gaosi_noise,[3,3]);
subplot(2,4,2);
imshow(image_gaosi_noise_after1);title('中值濾波去高斯噪聲效果圖');
axis square;
h_gaosi1=fspecial('gaussian',3,1);
image_gaosi_noise_after2=imfilter(image_gaosi_noise,h_gaosi1);
subplot(2,4,3);
imshow(image_gaosi_noise_after2);title('高斯平滑去高斯噪聲效果');
axis square;
image_gaosi_noise_after3=wiener2(image_gaosi_noise,[5 5]);
subplot(2,4,4);
imshow(image_gaosi_noise_after3);title('維納濾波去高斯噪聲效果');
axis square;
%原圖像直方圖
r=0:255;
bb=image_original(:);
pg=hist(bb,r);
pgr1=pg/length(bb);
subplot(245);bar(pgr1);title('源輸入圖像的直方圖');
r=0:255;
bl=image_gaosi_noise_after1(:);
pg=hist(bl,r);
pgr2=pg/length(bl);
subplot(246);bar(pgr2);title('中值濾波去高斯噪聲后的直方圖');
r=0:255;
bh=image_gaosi_noise_after2(:);
pu=hist(bh,r);
pgr3=pu/length(bh);
subplot(247);bar(pgr3);title('高斯平滑去高斯噪聲后的直方圖');
r=0:255;
ba=image_gaosi_noise_after3(:);
pa=hist(ba,r);
pgr4=pa/length(ba);
subplot(248);bar(pgr4);title('維納濾波去除高斯噪聲后的直方圖');
~~~
# 五,乘性噪聲去除能力對比
### 1,去噪效果對比



### 2,實驗代碼
~~~
<span style="font-size:12px;">%讀入原始圖像并顯示
image_original=imread('dog.bmp');
figure(1)
subplot(2,4,1);
imshow(image_original);
title('原輸入圖像');
axis square;
%生成含高斯噪聲圖像并顯示
%pp=0.01;
%image_gaosi_noise=imnoise(image_original,'gaussian',0,pp);
%生成含椒鹽噪聲圖像并顯示
%dd=0.01;
%image_saltpepper_noise=imnoise(image_original,'salt & pepper',dd);
%生成含乘性噪聲圖像并顯示
var=0.01;
image_speckle_noise=imnoise(image_original,'speckle',var);
image_speckle_noise_after1=medfilt2(image_speckle_noise,[3,3]);
subplot(2,4,2);
imshow(image_speckle_noise_after1);title('中值濾波去乘性噪聲效果圖');
axis square;
h_gaosi1=fspecial('gaussian',3,1);
image_speckle_noise_after2=imfilter(image_speckle_noise,h_gaosi1);
subplot(2,4,3);
imshow(image_speckle_noise_after2);title('高斯平滑去乘性噪聲效果');
axis square;
image_speckle_noise_after3=wiener2(image_speckle_noise,[5 5]);
subplot(2,4,4);
imshow(image_speckle_noise_after3);title('維納濾波去乘性噪聲效果');
axis square;
%原圖像直方圖
r=0:255;
bb=image_original(:);
pg=hist(bb,r);
pgr1=pg/length(bb);
subplot(245);bar(pgr1);title('源輸入圖像的直方圖');
r=0:255;
bl=image_speckle_noise_after1(:);
pg=hist(bl,r);
pgr2=pg/length(bl);
subplot(246);bar(pgr2);title('中值濾波去乘性噪聲后的直方圖');
r=0:255;
bh=image_speckle_noise_after2(:);
pu=hist(bh,r);
pgr3=pu/length(bh);
subplot(247);bar(pgr3);title('高斯平滑去乘性噪聲后的直方圖');
r=0:255;
ba=image_speckle_noise_after3(:);
pa=hist(ba,r);
pgr4=pa/length(ba);
subplot(248);bar(pgr4);title('維納濾波去除乘性噪聲后的直方圖');</span>
~~~
# 六,PNSR客觀對比
(PNSR客觀對比越高越好)
本對比也囊括了其他常見去噪方式的對比

#參考資源
【1】《百度百科》
【2】《維基百科》
【3】岡薩雷斯《數字圖像處理》
【4】http://blog.csdn.net/ebowtang/article/details/38960271