close all;
clear all;
clc;
m = 8;
n = 8;
G = cell(5,8);
for s = 1:5
for j = 1:8
G{s,j}=zeros(m,n);
end
end
for s = 1:5
for j = 1:8
G{s,9-j} = gabor([m n],(s-1),j-1,4*pi/5,sqrt(2),3*pi/2);
end
end
%%{
figure(1);
%title(['real Gabor_' num2str(n) 'x' num2str(m)]);
for s = 1:5
for j = 1:8
subplot(5,8,(s-1)*8+j);
imshow(real(G{s,j}),[]);
end
end
figure(2);
%title(['imag Gabor_' num2str(n) 'x' num2str(m)]);
for s = 1:5
for j = 1:8
subplot(5,8,(s-1)*8+j);
imshow(imag(G{s,j}),[]);
end
end
%}
for s = 1:5
for j = 1:8
G_fft{s,j}=fft2(G{s,j});
end
end
%%{
figure(3);
%title(['real Gabor_fft_' num2str(n) 'x' num2str(m)]);
for s = 1:5
for j = 1:8
subplot(5,8,(s-1)*8+j);
imshow(real(G_fft{s,j}),[]);
end
end
figure(4);
%title(['imag Gabor_fft_' num2str(n) 'x' num2str(m)]);
for s = 1:5
for j = 1:8
subplot(5,8,(s-1)*8+j);
imshow(imag(G_fft{s,j}),[]);
end
end
%}
%save gabor_8x8 G G_fft
下面是gabor()的函数(copy的。)
function Psi = gabor (w,nu,mu,Kmax,f,sig)
% w : Window [128 128]
% nu : Scale [0 ...4];
% mu : Orientation [0...7]
% kmax = pi/2
% f = sqrt(2)
% sig = 2*pi
m = w(1);
n = w(2);
K = Kmax/f^nu * exp(i*mu*pi/8);
Kreal = real(K);
Kimag = imag(K);
NK = Kreal^2+Kimag^2;
Psi = zeros(m,n);
for x = 1:m
for y = 1:n
Z = [x-m/2;y-n/2];
Psi(x,y) = (sig^(-2))*exp((-.5)*NK*(Z(1)^2+Z(2)^2)/(sig^2))*...
(exp(i*[Kreal Kimag]*Z)-exp(-(sig^2)/2));
end
end
运行效果图
1.gabor_8x8_real
2.gabor_8x8_imag
3.gabor_8x8_fft_real
4.gabor_8x8_fft_imag