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為等待濾波的影象資料;

原作者: strangename2

相關問題答案