这是gabor的代码
im=imread('G:\pictureROI\why1.jpg');
A=[];B=[];%A,B是空矩阵,初始化,清零。
scale=5; % denote the scale of the gabor wavelet表示gabor小波的尺度
orientation=4; % denote the orientation of the gabor wavelet表示gabor小波的方向
kmax=pi/2; % the highest frequency with the smallest kernel size具有最小内核大小的最高频率,即频率上限。
sigma=pi*2; % the parameter :theta 参数θ
mask_size=128; % for every kernel the size is 128*128% this is the size of Gabor mask对于每个内核,大小是128*128%,这是Gabor掩码的大小
f=sqrt(2); % f is the spacing factor% f是间隔间距因子
sig=sigma*sigma; % the squre of theta %θ的平方
offset=mask_size/2;%偏置/补偿/抵消=每个内核大小的一半。
for v=0:(scale-1) %设置循环,外循环5个尺度
for u=0:(orientation-1) %设置循环,内循环4个方向
kv=kmax/f^v; %开始创建gabor核函数
phiu=u*pi/4;
kv_mag=kv*kv;
gabor_kel=zeros(128,128);
for x=0:(mask_size-1)
for y=0:(mask_size-1)
i=x-offset;
j=y-offset;
mag=i*i+j*j;
gabor_kel(x+1,y+1)=kv_mag/sig*exp(-0.5*kv_mag*mag/sig)*(exp(sqrt(-1)*kv*(i*cos(phiu)+j*sin(phiu))-exp(-1.0*sig/2.0)));
end %the gabor kernel gabor核
end
result=abs(fftshift(ifft2((fft2(im)).*fft2(gabor_kel)))); % 与输入图像相卷积得到Gabopalm
result_sample=result(1:4:128,1:4:128); %对得到的结果进行下采样,采样因子ρ为4
m=mean(result_sample(1:end)); %平均值
s=std(result_sample(1:end)); %标准偏差
result_norm=(result_sample-m)/s; % 对得到的特征向量进行归一化,下采样每个值减平均值再除标准偏差得到均值为0方差为1的标准化数据
result_norm=result_norm(1:end); % 变为1*1024的行向量
A=[A result_norm']; % 变为1024*20的gaborface,将result_norm转置与A拼接。
end
end
output=A; %1024*20的gaborface