matlab实现gabor filter (8) 效果很好

gabor 滤波器函数:

 

function gb=gabor_fn(bw,gamma,psi,lambda,theta)
% bw    = bandwidth, (1)
% gamma = aspect ratio, (0.5)
% psi   = phase shift, (0)
% lambda= wave length, (>=2)
% theta = angle in rad, [0 pi)
 
sigma = lambda/pi*sqrt(log(2)/2)*(2^bw+1)/(2^bw-1);
sigma_x = sigma;
sigma_y = sigma/gamma;

sz=fix(8*max(sigma_y,sigma_x));
if mod(sz,2)==0, sz=sz+1;end

% alternatively, use a fixed size
% sz = 60;
 
[x y]=meshgrid(-fix(sz/2):fix(sz/2),fix(sz/2):-1:fix(-sz/2));
% x (right +)
% y (up +)

% Rotation 
x_theta=x*cos(theta)+y*sin(theta);
y_theta=-x*sin(theta)+y*cos(theta);
 
gb=exp(-0.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+psi);
%figure;
%imshow(gb/2+0.5);
%imshow(gb); %直接显示的gabor filter非常难看
%title('gabor filter');


调用代码:

 

clear all;
close all;

% 测试用程序
theta = [0 pi/4 2*pi/4 3*pi/4 4*pi/4 5*pi/4 6*pi/4 7*pi/4];
lambda = [4 5 6 7 8];
psi = 0;
gamma = 1;
bw = 0.5;



%{
% 初始化用来存放gabor filter组的cell
G=cell(5,8);
for i = 1:5
    for j = 1:8
        G{i,j}=zeros(GaborH,GaborW);
    end
end
%}

% 计算每个滤波器
figure;
for i = 1:5
    for j = 1:8
        gaborFilter=gabor_fn(bw,gamma,psi,lambda(i),theta(j));
        subplot(5,8,(i-1)*8+j);
        imshow(real(gaborFilter),[]);
    end
end

%{
% 绘制滤波器组
figure;
for i = 1:5
    for j = 1:8
        subplot(5,8,(i-1)*8+j);        
        %imshow(real(G{s,j})/2-0.5,[]);
        imshow(real(G{i,j}),[]);
    end
end
%}


生成的滤波器组图片:

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值