如何理解Gabor滤波器

转载自:(https://blog.csdn.net/xue_wenyuan/article/details/51533953).

介绍

我们已经知道,傅里叶变换是一种信号处理中的有力工具,可以帮助我们将图像从空域转换到频域,并提取到空域上不易提取的特征。但是经过傅里叶变换后,图像在不同位置的频度特征往往混合在一起,但是Gabor滤波器却可以抽取空间局部频度特征,是一种有效的纹理检测工具。

Alt

Figure 1. A sinusoid and it's Fourier spectrum

如何生成一个Gabor滤波器

在二维空间中,使用一个三角函数(如正弦函数)与一个高斯函数叠加我们就得到了一个Gabor滤波器[1],如下图。

Figure 2. Gabor filter composition: (a) 2D sinusoid oriented at 30◦ with the x-axis, (b) a Gaussian kernel, (c) the corresponding Gabor filter. Notice how the sinusoid becomes spatially localized.

Gabor核函数

二维Gabor核函数由一个高斯函数和一个余弦函数相乘得出,其中 θ , ϕ , γ , λ , σ \theta,\phi,\gamma,\lambda,\sigma 为参数。

(1) g λ , θ , ϕ , γ , σ ( x , y ) = e x 2 + γ 2 y 2 2 σ 2 c o s ( 2 π x λ + ϕ ) g_{\lambda,\theta,\phi,\gamma,\sigma}(x,y)=e^{-\frac{x'^2+\gamma^2y'^2}{2\sigma^2}}cos(2\pi \frac{x'}{\lambda}+\phi) \tag{1}

x = x c o s θ + y s i n θ x'=xcos\theta+ysin\theta

y = x s i n θ + y c o s θ y'=-xsin\theta+ycos\theta

在OpenCV中的getGaborKernel函数里需要传入的参数除了上述5个外,还需要传入卷积核的大小。

cv::Mat getGaborKernel(Size ksize, double sigma, double theta, double lambd, double gamma, double psi=CV_PI*0.5, int ktype=CV_64F );

在这里插入图片描述

Figure 3. The Gabor Filter in frequency with the orientation of 0°, 45°, 90°.

参数

Orientation θ \theta

θ \theta 表示Gabor滤波核中平行条带的方向,有效值为从0~360度的实数。
在这里插入图片描述

Phase offset ϕ \phi

ϕ \phi 表示Gabor核函数中余弦函数的相位参数,有效值为-180度~180度,0度和180度对应的方程与原点对称,-90度和90度的方程分别于原点成中心对称,可两项直角坐标系中的余弦函数。
在这里插入图片描述

Aspect ratio γ \gamma

γ \gamma , 纵横比,更准确的应称为空间纵横比,表示Gabor滤波器的椭圆度。
在这里插入图片描述

Wavelength λ \lambda

λ \lambda 表示Gabor核函数中余弦函数的波长参数,有效值应大于2,以像素为单位。
在这里插入图片描述

The standard deviation σ \sigma

σ \sigma 表示Gabor核函数中高斯函数的标准差,该参数决定了Gabor滤波核可接受区域的大小, σ \sigma 不能被直接指定,其值与 b b (Bandwidth)和 λ \lambda 有关。
Bandwidth( b b )表示高低频率之差。在实际选取Gabor滤波核中,我们会选取频域中半响应空间频度带宽(the half-response spatial frequency bandwidth),或者半峰量级(the half-peak magnitude),他们都指的是频域中Bandwidth/2的空间位置。 b b λ \lambda σ \sigma 的关系如下:

(2) b = l o g 2 σ λ π + l n 2 2 σ λ π l n 2 2 b=log_{2}\frac{\frac{\sigma}{\lambda}\pi+\sqrt{\frac{ln2}{2}}}{\frac{\sigma}{\lambda}\pi-\sqrt{\frac{ln2}{2}}}\tag{2}

(3) σ λ = 1 π l n 2 2 2 b + 1 2 b 1 \frac{\sigma}{\lambda}=\frac{1}{\pi}\sqrt{\frac{ln2}{2}}\cdot \frac{2^b+1}{2^b-1} \tag{3}

在这里插入图片描述

演示

这里用一张程序运行动态图可以清楚的显示出Gabor滤波核随各个参数变化的情况。
在这里插入图片描述

如何设计Gabor滤波器来提取特征

为了充分利用Gabor滤波器的特点,我们必然需要设计不同方向,不同尺度的GaborL滤波器来提取特征,[2]中提到了如下策略来使滤波器尽量无重叠覆盖频域中的各个方向:

“Then the design strategy is to ensure that the half-peak magnitude support of the filter responses in the frequency spectrum touch each other .”

在这里插入图片描述
首先通过如下公式计算出 a , σ x , σ y , a,\sigma_x,\sigma_y, 其中 U h , U l U_h,U_l 分别表示滤波器的中心频度,及波长 λ \lambda 的倒数, K K 为方向的数量, S S 为尺度的数量。
(3) a = ( U h U l ) 1 S 1 a=(\frac{U_h}{U_l})^{\frac{1}{S-1}} \tag{3}

(4) σ μ = ( a 1 ) U h ( a + 1 ) 2 l n 2 \sigma_\mu=\frac{(a-1)U_h}{(a+1)\sqrt{2ln2}} \tag{4}

(5) σ v = t a n ( π 2 K ) [ U h 2 l n ( 2 σ μ 2 U h ) ] [ 2 l n 2 ( 2 l n 2 ) 2 σ μ 2 U h 2 ] 1 2 \sigma_v=tan(\frac{\pi}{2K})[U_h-2ln(\frac{2\sigma_\mu^2}{U_h})][2ln2-\frac{(2ln2)^2\sigma_\mu^2}{U_h^2}]^{-\frac{1}{2}} \tag{5}

(6) σ μ = 1 2 π σ x , σ v = 1 2 π σ y \sigma_\mu=\frac{1}{2\pi\sigma_x},\sigma_v=\frac{1}{2\pi\sigma_y} \tag{6}

然后将上述结果带入下列Gabor核函数方程,从而求得Gabor卷积核上某点的值。其中 m = 0 , 1 , . . . , S 1 ; n = 0 , 1 , . . . , K 1 ; θ = n π / K m=0,1,...,S-1;n=0,1,...,K-1;\theta=n\pi/K
(7) g m n ( x , y ) = a m g ( x , y ) , a > 1 , m , n = i n t e g e r g_{mn}(x,y)=a^{-m}g(x',y'), a>1, m,n=integer \tag{7}

(8) g ( x , y ) = ( 1 2 π σ x σ y ) e [ 1 2 ( x 2 σ x 2 + y 2 σ y 2 ) + 2 π j W x ] g(x,y)=(\frac{1}{2\pi\sigma_x\sigma_y})e^{[-\frac{1}{2}(\frac{x^2}{\sigma_x^2}+\frac{y^2}{\sigma_y^2})+2\pi jWx]} \tag{8}

(9) x = a m ( x c o s θ + y s i n θ ) , y = a m ( x c o s θ + y s i n θ ) x'=a^{-m}(xcos\theta+ysin\theta), y'=a^{-m}(-xcos\theta+ysin\theta) \tag{9}
但是在OpenCV中的Gabor核函数采用式(1)的形式,因此我们需要对两种不同表达的Gabor核函数中的参数进行一些转换。比较两种表达式,不难看出,式(8)中的 2 π j W x 2\pi jWx' 是一个复数形式,可以分解成正余弦和的形式,与式(1)中的余弦函数部分相对应,式(8)最前端的部分为幅度。因此两种形式的主要区别在于高斯函数的指数以及 x x’ 的表达不同。通过如下转换,就可以将式(8)中的参数转换成式(1)中的参数。
在这里插入图片描述
在这里插入图片描述

不同的卷积核(kernel size)大小对Gabor滤波核的影响

如果卷积核的边长小于波长,那么整个波形不能包括在卷积核中,使得波形边缘的滤波效果起不到作用。相反,如果如果卷积核的边长大于波长,则不会对滤波器产生什么影响。

相位变化对Gabor滤波核的影响

通过相位变化可以改变滤波核中心点的波形,如果滤波核中心点正对波峰( ϕ = 0 \phi=0 ),则会对整张图像起到加强的作用,如果滤波核中心点正对波谷( ϕ = 180 \phi=180 ),则会对整张图像起到减弱的作用。我们应当避免滤波核中心点的波形位于零交叉点,因为这样我们可能会看不到滤波器的任何效果。

References

[1] Prasad V S N, Domke J. Gabor filter visualization[J]. J. Atmos. Sci, 2005, 13.

[2] Manjunath B S, Ma W Y. Texture features for browsing and retrieval of image data[J]. Pattern Analysis and Machine Intelligence, IEEE Transactions on, 1996, 18(8): 837-842.

[3] Movellan J R. Tutorial on Gabor filters[J]. Open Source Document, 2002.

[4] Celik T, Lee H K, Petznick A, et al. Bioimage informatics approach to automated meibomian gland analysis in infrared images of meibography[J]. Journal of optometry, 2013, 6(4): 194-204.

[5] Cheng E, Du L, Wu Y, et al. Discriminative vessel segmentation in retinal images by fusing context-aware hybrid features[J]. Machine Vision and Applications, 2014, 25(7): 1779-1792.

[6] Advances in Digital Document Processing and Retrieval[M]. World Scientific, 2013.

[7] 孔锐, 张冰. Gabor 滤波器参数设置[J]. 控制与决策, 2012, 27(8): 1277-1280.

Useful Web Sites

http://www.cs.rug.nl/~imaging/simplecell.html
http://www.juergenwiki.de/work/wiki/doku.php?id=public:gabor_filter
http://blog.163.com/hulin_feng/blog/static/9235253201231453211288/
帮助理解Gabor滤波器的有关文档,以及Gabor滤波器的可视化程序已经上传到Github.
以上内容编辑:崔健棣

猜你喜欢

转载自blog.csdn.net/DoctorCuiLab/article/details/83714641