Halcom 发表于 2016-12-25 20:57:30

Gabor滤波器

close all;clear all;clc;
G = cell(5,8);
for s = 1:5
    for j = 1:8
      G{s,j}=zeros(32,32);
    end
end
for s = 1:5
    for j = 1:8
      G{s,9-j} = gabor(,(s-1),j-1,pi,sqrt(2),pi);
    end
end

figure;
for s = 1:5
    for j = 1:8      
      subplot(5,8,(s-1)*8+j);      
      imshow(real(G{s,j}),[]);
    end
end

for s = 1:5
    for j = 1:8      
      G{s,j}=fft2(G{s,j});
    end
end
save gabor G

function Psi = gabor (w,nu,mu,Kmax,f,sig)
% w: Window
% nu : Scale ;
% mu : Orientation
% 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 = ;
      Psi(x,y) = (sig^(-2))*exp((-.5)*NK*(Z(1)^2+Z(2)^2)/(sig^2))*...
                   (exp(i**Z)-exp(-(sig^2)/2));
    end
end

Halcom 发表于 2016-12-25 21:22:43

Gabor图像滤波器设计如下:
function = gabor_filter(I,Sx,Sy,U,V)
% 函数输入:
%          I : 输入的二维图像
%          Sx & Sy : 方差 along x and y-axes respectively
%          U & V : 中心频率along x and y-axes respectively
% 函数输出:
%          G : G(x,y)
%          gabout : Gabor滤波图像
% G(x,y)表达式如下:
%               1                -1   x^    y^
%%% G(x,y) = ---------- * exp ([----{(----) 2+(----) 2}+2*pi*i*(Ux+Vy)])
%            2*pi*sx*sy         2    sx       sy

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)); % 输出滤波图像具体参考书籍:
余胜威,丁建明,吴婷,魏健蓝 . MATLAB图像滤波去噪分析及其应用. 北京:北京航空航天大学出版社,2015.
页: [1]
查看完整版本: Gabor滤波器