gabor小波代码



一:定义
http://en.wikipedia.org/wiki/Gabor_filter

There is considerable evidence (reviewed in MacLennan 1991) that images in primary visual cortex (V1) are represented in terms of Gabor wavelets, that is, hierarchically arranged, Gaussian-modulated sinusoids (equivalent to the pure states of quantum mechanics). The Gabor-wavelet transform of a two-dimensional visual field generates a four-dimensional field: two of the dimensions are spatial, the other two represent spatial frequency and orientation. To represent this four-dimensional field in two-dimensional cortex, it is necessary to ``slice'' the field, which gives rise to the columns and stripes of striate cortex. The representation is nearly optimal, as defined by the Gabor Uncertainty Principle (a generalization of the Heisenberg Uncertainty Principle to information representation and transmission). Time-varying two-dimensional visual images may be viewed as three-dimensional functions of space-time, and it is possible that time-varying images are represented in vision areas by a three-dimensional Gabor-wavelet transform, which generates a time-varying five-dimensional field (representing two spatial dimensions, spatial frequency, spatial orientation and temporal frequency). The effect is to represent the ``optic flow'' of images in terms spatially fixed, oriented grating patches with moving gratings. (See MacLennan 1991 for more details.) Finally, Pribram provides evidence that Gabor representations are also used for controlling the generation of motor fields (see citations in MacLennan 1997, p. 64).

二:源码
MATLAB源码:
http://www.mathworks.com/matlabcentral/fileexchange/7287
C源码
http://vision.ece.ucsb.edu/texture/software/

三:纹理示例
http://www.ux.uis.no/~tranden/brodatz.html

Gabor 滤波器定义为:其脉冲响应为一个谐波函数(即下式中的余弦函数)和一个高斯函数的乘积。根据信号与系统理论,时频域的卷积和乘积互为傅里叶变换。Gabor滤波器的傅里叶变换为谐波和高斯函数各自傅里叶变换的卷积。

Gabor 滤波器,其中,在上式 ,λ代表余弦函数波长,θ代表Gabor函数平行条纹法线的方向【θ epresents the orientation of the normal to the parallel stripes】,ψ为相位补偿,σ为高斯包络的sigma,γ为空间相位比和Gabor函数中的椭圆率

以下是MATLAB中实现:

复制代码
 1 function gb=gabor_fn(sigma,theta,lambda,psi,gamma)
 2 
 3 sigma_x = sigma;
 4 sigma_y = sigma/gamma;
 5 
 6 % Bounding box
 7 nstds = 3;
 8 xmax = max(abs(nstds*sigma_x*cos(theta)),abs(nstds*sigma_y*sin(theta)));
 9 xmax = ceil(max(1,xmax));
10 ymax = max(abs(nstds*sigma_x*sin(theta)),abs(nstds*sigma_y*cos(theta)));
11 ymax = ceil(max(1,ymax));
12 xmin = -xmax; ymin = -ymax;
13 [x,y] = meshgrid(xmin:xmax,ymin:ymax);
14 
15 % Rotation 
16 x_theta=x*cos(theta)+y*sin(theta);
17 y_theta=-x*sin(theta)+y*cos(theta);
18 
19 gb=exp(-.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+psi);
复制代码

==============================================================

另外一个MATLAB实现函数:

复制代码
 1 function [gab]=gaborcreate(M,N)
 2 
 3 %CREATION OF GABOR MASK
 4 %Parameters -m=0,1,...M-1 scales ; n=0,1,...N-1 orientation
 5 
 6 %CREATION OF GABOR MASK
 7 %Parameters -m=0,1,...M-1 scales ; n=0,1,...N-1 orientation
 8 
 9 M=4;
10 N=3;
11 a=(0.4 / 0.05)^(1/(M-1));
12 gab=cell(2,2);
13 count=1;
14 
15 for m=1:M
16      for n=1:N
17          
18          W=a^m * 0.05;
19          sigmax=((a+1)*sqrt(2 * log(2))) / (2 * pi * a^m * (a-1) * 0.05);
20          sigmay1=((0.4 *0.4) / (2*log(2))) - (( 1 / (2 *pi* sigmax))^2); 
21          sigmay=1 / ((2* pi * tan(pi/(2*N)) * sqrt ( sigmay1)));
22          theta=(n*pi)/N ;
23 
24          for ij=1:2
25             for i=1:3
26               for j=1:3
27                     xb=a^(-m) * (i*cos(theta) + j*sin(theta));
28                     yb=a^(-m) * ((-i)*sin(theta) + j*cos(theta));
29                     phi1=(-1/2) * ((xb*xb)/(sigmax*sigmax) + (yb*yb)/(sigmay*sigmay));
30                      if ij==1
31                         prob=i;
32                     else
33                         prob=j;
34                     end
35                     phi=(1/(2*pi*sigmax*sigmay)) * exp(phi1) * exp(2*2*pi*W*prob);
36                     gab1(i,j)=phi* a^(-m);
37               end
38           end
39          gab{count,ij}=gab1;
40 
41         end
42 
43           count=count+1;
44       end
45 end

你可能感兴趣的:(gabor小波代码)