matlab实现gabor filter 多种方式汇总

方式一:

 

function result = gaborKernel2d( lambda, theta, phi, gamma, bandwidth)
% GABORKERNEL2D 
% Version: 2012/8/17 by watkins.song
% Version: 1.0
%   Fills a (2N+1)*(2N+1) matrix with the values of a 2D Gabor function. 
%   N is computed from SIGMA.
%
%   LAMBDA - preferred wavelength (period of the cosine factor) [in pixels]
%   SIGMA - standard deviation of the Gaussian factor [in pixels]
%   THETA - preferred orientation [in radians]
%   PHI   - phase offset [in radians] of the cosine factor
%   GAMMA - spatial aspect ratio (of the x- and y-axis of the Gaussian elipse)
%   BANDWIDTH - spatial frequency bandwidth at half response,
%       *******************************************************************
%      
%       BANDWIDTH, SIGMA and LAMBDA are interdependent. To use BANDWIDTH, 
%       the input value of one of SIGMA or LAMBDA must be 0. Otherwise BANDWIDTH is ignored.
%       The actual value of the parameter whose input value is 0 is computed inside the 
%       function from the input vallues of BANDWIDTH and the other parameter.
% 
%                           pi               -1    x'^2+gamma^2*y'^2             
%   G(x,y,theta,f) =  --------------- *exp ([----{-------------------}])*cos(2*pi*f*x'+phi);
%                      2*sigma*sigma          2         sigma^2
%
%%% x' = x*cos(theta)+y*sin(theta);
%%% y' = y*cos(theta)-x*sin(theta);
%
% Author: watkins.song
% Email: watkins.song@gmail.com

% calculation of the ratio sigma/lambda from BANDWIDTH 
% according to Kruizinga and Petkov, 1999 IEEE Trans on Image Processing 8 (10) p.1396
% note that in Matlab log means ln  
slratio = (1/pi) * sqrt( (log(2)/2) ) * ( (2^bandwidth + 1) / (2^bandwidth - 1) );

% calcuate sigma
sigma = slratio * lambda;

% compute the size of the 2n+1 x 2n+1 matrix to be filled with the values of a Gabor function
% this size depends on sigma and gamma
if (gamma <= 1 && gamma > 0)
	n = ceil(2.5*sigma/gamma);
else
	n = ceil(2.5*sigma);
end

% creation of two (2n+1) x (2n+1) matrices x and y that contain the x- and y-coordinates of
% a square 2D-mesh; the rows of x and the columns of y are copies of the vector -n:n
[x,y] = meshgrid(-n:n);

% change direction of y-axis (In Matlab the vertical axis corresponds to the row index
% of a matrix. If the y-coordinates run from -n to n, the lowest value (-n) comes
% in the top row of the matrix ycoords and the highest value (n) in the
% lowest row. This is oposite to the customary rendering
  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值