生成二維gabor濾波器的matlab程式碼
function hp=gbfilter2(sigmax,mu,mv)
% 函式功能:生成二維離散gabor函式模板hp。可能主要用於影象的紋理分析;
%輸入引數:sigmax——x方向的方差;
% mu——x方向中心頻率;mv——y方向中心頻率;
%輸出引數:hp——二維離散gabor模板;
%按照生理視覺的研究 y方向標準差為x方向標準差的1.5-2.0倍,此處取1.7
sigmay=sigmax*1.7;
%按照誤差原則,(-3sigama,3sigma)包含了97.4%的能量。N也為濾波器長度。
%通常在紋理分析前,需要用到模板長度N,此時可用N=fix(6*sigmax*1.7);這一語句求得。
N=fix(6*sigmay);
%該句主要防止被零除
if mu==0
mu=1e-12;
end
% theta角為紋理方向
theta=atan(mv/mu);
%取樣區間和間隔,此處為過取樣。臨界取樣並不可取。
kx=-(N-1)/2:(N-1)/2;
ky=kx;
%生成x,y座標。
[tpx,tpy]=meshgrid(kx,ky);
%計算gabor函式旋轉生成的新座標
x=tpx*cos(theta)+tpy*sin(theta);
y=-tpx*sin(theta)+tpy*cos(theta);
%計算gauss函式
z=1/(2*pi*sigmax*sigmay)*exp(-0.5*(( x/sigmax).^2+(y/sigmay).^2));
%計算調製因子
exptab=exp(-j2*pi*(tpx*mu+tpy*mv)/N);
%gauss函式被調製因子調製
hp=z.*exptab;
%矩陣轉置以生成與習慣相符的x,y軸
hp=hp';
end
第二個產生二維gabor濾波器的程式
function [hp,sigmax]=gbfilt2(ax,mu,mv,N)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 函式功能:生成用於影象濾波的gabor函式的模板
% 輸入引數: ax——關於x軸的sigma因子,ax=N/(2*sigma),3.5<=ax<=N/2;
% mu——x方向中心頻率,mu<=N/4;mv——y方向中心頻率;mv<=N/4;
% N——濾波器長度,與濾波器寬度相同;
% 輸出引數: hp——生成的gabor模板;sigmax對應x方向的sigama;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 定義sigmay=1.7*sigmax
ay=ax/1.7;
% 防止被零除
if mu==0
mu=1e-16;
end
% 計算gabor濾波器的方向
theta=atan(mv/mu);
% 定義x,y取值範圍為長度N
kx=-(N-1)/2:(N-1)/2;
ky=kx;
% 生成x,y座標
[tpx,tpy]=meshgrid(kx,ky);
% 旋轉theta角
x=tpx*cos(theta)+tpy*sin(theta);
y=-tpx*sin(theta)+tpy*cos(theta);
% gauss函式
z=2*ax*ay/(pi*N^2)*exp((-1/2)*((ax*x/(N/2)).^2+(ay*y/(N/2)).^2));
% 頻率調製因子
facmod=cos(2*pi*(tpx*mu+tpy*mv)/N);
% 返回模板
hp=(z.*facmod)';
% 返回sigmax
sigmax=N/(2*ax);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 2008-09-02
% 王澤華
% 青島科技大學數理學院
% email:[email protected]
% References:
% Harris, F.J. On the Use of Windows for Harmonic Analysis with the
% Discrete Fourier Transform.Proceedings of the IEEE. 1978,66(1):51-83。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
關於這個程式我不想多說了,這個基本按照標準生成的,具體標準可參閱下面列出的文獻,並且這篇文獻也可以在網上免費獲得,但前提是你的E文足夠好。
Harris,F.J.On the Use of Windows for Harmonic Analysis with the Discrete Fourier Transform.Proceedings of the IEEE,1978,66(1):51-83.
轉載地址:http://blog.csdn.net/dadaadao/article/details/6225411