matlab实现gabor filter (4)

源代码:

%%%%%%%VERSION 1

%The Gabor filter is basically a Gaussian (with variances sx and sy along x and y-axes respectively)
%modulated by a complex sinusoid (with centre frequencies U and V along x and y-axes respectively) 
%described by the following equation
%%
%               1                -1     x  ^    y  ^
%%% G(x,y) = ---------- * exp ([----{(----) 2+(----) 2}+2*pi*i*(Ux+Vy)])
%            2*pi*sx*sy           2    sx       sy

%% Describtion :

%% I : Input image
%% Sx & Sy : Variances along x and y-axes respectively
%% U & V : Centre frequencies  along x and y-axes respectively

%% G : The output filter as described above
%% gabout : The output filtered image

%%  Author : Ahmad poursaberi  e-mail : a.poursaberi@ece.ut.ac.ir
%%          Faulty of Engineering, Electrical&Computer Department,Tehran
%%          University,Iran,June 2004

function [G,gabout] = gaborfilter(I,Sx,Sy,U,V)

if isa(I,'double')~=1 
    I = double(I);
end

for x = -fix(Sx):fix(Sx)
    for y = -fix(Sy):fix(Sy)
        G(fix(Sx)+x+1,fix(Sy)+y+1) = (1/(2*pi*Sx*Sy))*exp(-.5*((x/Sx)^2+(y/Sy)^2)+2*pi*i*(U*x+V*y));
    end
end

Imgabout = conv2(I,double(imag(G)),'same');
Regabout = conv2(I,double(real(G)),'same');

gabout = uint8(sqrt(Imgabout.*Imgabout + Regabout.*Regabout));


调用代码:

close all;
clear all;
clc;

% 读入图像
image=imread('C:\Users\watkins\Pictures\cartoon.jpg');
grayImage=rgb2gray(image);
grayImage=im2double(grayImage);
% 显示读入图像
imshow(grayImage);

sx=32;
sy=32;
theta=[0 pi/4 2*pi/4 3*pi/4 4*pi/4 5*pi/4 6*pi/4 7*pi/4];
gamma=1;
psi=0;
sigma=6; % 也可以为12
lambda=[5 6 7 8 9];

V=[4 5 6 7 8];
U=[0 pi/4 2*pi/4 3*pi/4 4*pi/4 5*pi/4 6*pi/4 7*pi];
%U=[1 2 3 4 5 6 7 8];

% Creating 40 Gabor Filters
G = cell(5,8);
for i = 1:5
    for j = 1:8
        G{i,j}=zeros(65,65);
    end
end
for i = 1:5
    for j = 1:8
        [T,gabout] = gaborfilter(grayImage,sx,sy,U(j),V(i));
        G{i,j} = T; 
    end
end

% Showing Gabor Filters
figure;
for s = 1:5
    for j = 1:8        
        subplot(5,8,(s-1)*8+j);        
        %imshow(real(G{s,j})/2-0.5,[]);
        imshow(real(G{s,j}),[]);
    end
end


滤波器组图片:

不明白为什么滤波器组的图片是这样,还希望哪位大侠帮忙指点一下?

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值