2D-Gabor Matlab实现

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




  • 0
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值