天天看點

matlab常用濾波器

首先關于fspecial函數的定義,fspecial函數用于建立預定義的濾波算子。

其文法格式為:     

h = fspecial(type)     

h = fspecial(type,para)

其中type指定算子的類型,para指定相應的參數;

函數type的類型有:

1、\'average\'averaging filter為均值濾波,參數為hsize代表模闆尺寸,預設值為[3,3]。

函數格式:H = fspecial(\'average\',hsize)

2、 \'disk\'circular averaging filter為圓形區域均值濾波,參數為radius代表區域半徑,預設值為5。

函數格式:H = fspecial(\'disk\',radius)

3、\'gaussian\'Gaussian lowpass filter為高斯低通濾波,有兩個參數,hsize表示模闆尺寸,預設值為[3 3],sigma為濾波器的标準值,機關為像素,預設值為0.5。

函數格式:H = fspecial(\'gaussian\',hsize,sigma)

4、\'laplacian\' filter approximating the 2-D Laplacian operatorlaplacian filter為拉普拉斯算子,參數alpha用于控制算子形狀,取值範圍為[0,1],預設值為0.2.

函數格式:H = fspecial(\'laplacian\',alpha)

5、\'log\'Laplacian of Gaussian filter為拉普拉斯高斯算子,有兩個參數,hsize表示模闆尺寸,預設值為[3 3],sigma為濾波器的标準差,機關為像素,預設值為0.5。

函數格式:H = fspecial(\'log\',hsize,sigma)

6、\'motion\'motion filter運動模糊算子,有兩個參數,表示攝像物體逆時針方向以theta角度運動了len個像素,len的預設值為9,theta的預設值為0。

函數格式:H = fspecial(\'motion\',len,theta)

7、\'prewitt\'Prewitt horizontal edge-emphasizing filter用于邊緣增強,大小為[3 3],無參數。

函數格式:H = fspecial(\'prewitt\')

8、\'sobel\'Sobel horizontal edge-emphasizing filter用于邊緣提取,無參數

函數格式:H = fspecial(\'sobel\')the filter H: H\'.9、\'unsharp\'unsharp contrast enhancement filter為對比度增強濾波器。參數alpha用于控制濾波器的形狀,範圍為[0,1],預設值為0.2.函數格式:H = fspecial(\'unsharp\',alpha)

下面是幾個應用的例子,另外還有一個中值濾波沒必要用fspecial函數,直接有對應的函數:

1、均值濾波器:

     A=fspecial(\'average\',n); %生成系統預定義的3X3濾波器  

     Y=filter2(A,g)/255;           %用生成的濾波器進行濾波,并歸一化  

其中n為設定的模闆大小,g為等待濾波的圖像資料;

2、中值濾波器:

    Y3=medfilt2(g,n);

其中n為設定的模闆大小,g為等待濾波的圖像資料;

3、高斯濾波器:

   n3=input(\'請輸入高斯濾波器的均值/n\');  

k=input(\'請輸入高斯濾波器的方差/n\');  

 A2=fspecial(\'gaussian\',k,n3);      %生成高斯序列  

Y5=filter2(A2,g)/255;              %用生成的高斯序列進行濾波

g為等待濾波的圖像資料;

matlab常用濾波器