Gabor wavelets transform 【Gabor 小波变换】

 

18:22:14

一:定义
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中实现:

function gb=gabor_fn(sigma,theta,lambda,psi,gamma)

sigma_x = sigma;
sigma_y = sigma/gamma;

% Bounding box
nstds = 3;
xmax = max(abs(nstds*sigma_x*cos(theta)),abs(nstds*sigma_y*sin(theta)));
xmax = ceil(max(1,xmax));
ymax = max(abs(nstds*sigma_x*sin(theta)),abs(nstds*sigma_y*cos(theta)));
ymax = ceil(max(1,ymax));
xmin = -xmax; ymin = -ymax;
[x,y] = meshgrid(xmin:xmax,ymin:ymax);

% Rotation
x_theta=x*cos(theta)+y*sin(theta);
y_theta=-x*sin(theta)+y*cos(theta);

gb=exp(-.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+psi);

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

另外一个MATLAB实现函数:

function [gab]=gaborcreate(M,N)

%CREATION OF GABOR MASK
%Parameters -m=0,1,...M-1 scales ; n=0,1,...N-1 orientation

%CREATION OF GABOR MASK
%Parameters -m=0,1,...M-1 scales ; n=0,1,...N-1 orientation

M=4;
N=3;
a=(0.4 / 0.05)^(1/(M-1));
gab=cell(2,2);
count=1;

for m=1:M
     for n=1:N
        
         W=a^m * 0.05;
         sigmax=((a+1)*sqrt(2 * log(2))) / (2 * pi * a^m * (a-1) * 0.05);
         sigmay1=((0.4 *0.4) / (2*log(2))) - (( 1 / (2 *pi* sigmax))^2);
         sigmay=1 / ((2* pi * tan(pi/(2*N)) * sqrt ( sigmay1)));
         theta=(n*pi)/N ;

         for ij=1:2
            for i=1:3
              for j=1:3
                    xb=a^(-m) * (i*cos(theta) + j*sin(theta));
                    yb=a^(-m) * ((-i)*sin(theta) + j*cos(theta));
                    phi1=(-1/2) * ((xb*xb)/(sigmax*sigmax) + (yb*yb)/(sigmay*sigmay));
                     if ij==1
                        prob=i;
                    else
                        prob=j;
                    end
                    phi=(1/(2*pi*sigmax*sigmay)) * exp(phi1) * exp(2*2*pi*W*prob);
                    gab1(i,j)=phi* a^(-m);
              end
          end
         gab{count,ij}=gab1;

        end

          count=count+1;
      end
end

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Gabor滤波实现(1)

20071223日 星期日 10:04

最近忙着论文,需要Gabor滤波代码,可是网上总找不到合适的代码,于是就自己编了一个,不当之处请指点。参考论文为 L. WiskottJ. M. FellousN. KrugerC. v. d.Malsburg. Face Recognition by Elastic Bunch Graph MatchingIEEE Trans. On PAMIVol.19No.7pp775-7791997

首先实现滤波器:

function [bank] = do_createfilterbank(imsize,varargin)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
函数实现:创建Gabor 滤波组

%
%%%
必选参数:
%   imsize -
图像大小
%%%
可选参数:
%   freqnum —
频率数目
%   orientnum —
方向数目
%   f       —  
频率域中的采样步长
%   kmax    —  
最大的采样频率
%   sigma   —  
高斯窗的宽度与波向量长度的比率
%
%%%
返回结果:
%   bank
%           .freq        —    
滤波频率
%           .orient      —    
滤波方向
%           .filter      —     Gabor
滤波
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

conf = struct(...,
    'freqnum',3,...
    'orientnum',6,...
    'f',sqrt(2),...
    'kmax',(pi/2),...
    'sigma',(sqrt(2)*pi) ...
    );

conf = do_getargm(conf,varargin);

bank = cell(1,conf.freqnum*conf.orientnum);
for f0=1:conf.freqnum
    fprintf('
处理频率
%d /n', f0);
    for o0=1:conf.orientnum
        [filter_,freq_,orient_] = do_gabor(imsize,(f0-1),(o0-1),conf.kmax,conf.f,conf.sigma,conf.orientnum);
        bank{(f0-1)*conf.orientnum + o0}.freq = freq_; %
orient增序排列

        bank{(f0-1)*conf.orientnum + o0}.filter = filter_;
        bank{(f0-1)*conf.orientnum + o0}.orient = orient_;
    end
end

for ind = 1:length(bank)
    bank{ind}.filter=fftshift(bank{ind}.filter);
end

function [filter,Kv,Phiu] = do_gabor (imsize,nu,mu,Kmax,f,sigma,orientnum)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
函数实现: 创建Gabor滤波

%
%%%
参数:
%   imsize     :
滤波的大小(即图像大小)
%   nu         :
频率编号 [0 ...freqnum-1];
%   mu         :
方向编号
[0...orientnum-1]
%   Kmax      
最大的采样频率

%   f         
频率域中的采样步长
%   sigma      :
高斯窗的宽度与波向量长度的比率
%   orientnum :
方向总数
%
%%%
返回值:
%   filter :   
滤波
%   Kv    :   
频率大小
%   Phiu :   
方向大小
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

rows = imsize(1);
cols = imsize(2);
minrow = fix(-rows/2);
mincol = fix(-cols/2);
row = minrow + (0:rows-1);
col = mincol + (0:cols-1);
[X,Y] = meshgrid(col,row);

Kv = Kmax/f^nu;
Phiu = pi * mu /orientnum;
K = Kv * exp(i * Phiu);

F1 = (Kv ^ 2)/ (sigma^2) * exp(-Kv^2 * abs(X.^2 + Y.^2) / (2*sigma^2)) ;
F2 = exp(i * (real(K) * X + imag(K) * Y)) - exp(-sigma^2/2);
filter = F1.* F2;

 

非常感谢

Gabor 滤波实现(1)已经创建了Gabor滤波组,现在可以使用该滤波组对图像进行转换,得到振幅和相位。

function [result] = do_filterwithbank(im,bank)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
函数实现:对图像使用Gabor滤波组进行转换换

%
%%%
参数:
%   im       —
被转换的图像
%   bank        —
由函数do_createfilterbank得到的滤波组
%
%%%
返回:
%   result                     —
图像被转换后的结果
%       .amplitudes            —
不同像素点的振幅向量
%       .phases                —
不同像素点的相位向量
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[N1 N2] = size(im);
N3 = length(bank);
phases = zeros(N1,N2,N3);
amplitudes = zeros(N1,N2,N3);
imagefft = fft2(im);

for ind = 1:N3
    fprintf('
正在处理滤波
%d /n',ind);
     temp = ifft2(imagefft .* bank{ind}.filter);
     phases(:,:,ind) = angle(temp);
     amplitudes(:,:,ind) = abs(temp);
end
result.phases = phases;
result.amplitudes = amplitudes;

整个程序可以如下使用。 im = imread('image.jpg'); im = rgb2gray(im); bank = do_createfilterbank(size(im)); result = do_filterwithbank(im,bank);

 

你可能感兴趣的:(matlab,filter,parameters,function,generation,im)