⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gabor_wavelet1.m

📁 matlab的一个人脸识别系统 包括gabor
💻 M
字号:
function [G,gabout] = Gabor_wavelet1(I,sigma,f,theta,width)
% %function Gabor_wavelet(m,n)
% % m指定滤波器的尺度
% % n指定滤波器的方向
% 
% width=6;
% [x,y]=meshgrid(-width:width,-width:width);
% 
% M=5;   % M表示总共有5个尺度
% N=6;   % N表示总共有6个方向
% 
% for m=5:M
%     for n=6:N
% Uh=0.4;
% Ul=0.05;
% % a=(Uh/Ul).^(-1/(M-1));
% sigma_x=(a+1)*sqrt(2*log(2))/(2*pi*a.^m*(a-1)*Ul);
% sigma_y=1/(2*pi*tan(pi/2*N)*sqrt(Uh.^2/2*log(2)-(1/2*pi*sigma_x).^2));
% % W=a.^m*Ul;
% 
% % Uh=pi/0.2;
% % Ul=Uh/8;
% a=(Uh/Ul).^(-1/(M-1));
% % sigma_u=(a-1)*Uh/((a+1)*sqrt(2*log(2)));
% % sigma_v=tan(pi/(2*N))*(Uh-2*log(2)*sigma_u.^2/Uh)*(2*log(2)-(2*log(2)).^2*sigma_u.^2/Uh.^2).^(-1/2);
% 
% sigma_u=1/(2*pi*sigma_x);
% sigma_v=1/(2*pi*sigma_y);
% W=Uh;
% 
% theta=n*pi/N; % 指定滤波器的方向
% 
% xx=a.^(-m)*(x*cos(theta)+y*sin(theta));
% yy=a.^(-m)*(-x*sin(theta)+y*cos(theta));
% 
% %gabor=a.^(-m)/(2*pi*sigma_x*sigma_y)*exp(-(xx.^2/sigma_x.^2+yy.^2/sigma_y.^2)/2)*exp(2*pi*sqrt(-1)*W*xx);
%  gabor=a.^(-m)*exp((-1/2)*((xx-W).^2/sigma_u.^2+yy.^2/sigma_v.^2));
% 
% figure
% imshow(real(gabor),[]);
% end
% end



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%———————————————— VERSION 1 ————————————————
%%ANOTHER DESCRIBTION OF GABOR FILTER

%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     x' ^     y'  ^             
%%% G(x,y,theta,f) =  exp ([----{(----) 2+(----) 2}])*cos(2*pi*f*x');
%                             2    sx'       sy'
%%% x' = x*cos(theta)+y*sin(theta);
%%% y' = y*cos(theta)-x*sin(theta);

%% Describtion :

%% I : Input image
%% Sx & Sy : Variances along x and y-axes respectively
%% f : The frequency of the sinusoidal function
%% theta : The orientation of Gabor filter

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

%% Author: Perky
%         E-mail: mshgirl1981@sina.com
%         Texture Lab     Ocean University of China
%         2006.8.9 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 这个Gabor滤波器与正弦函数的频率有关,也与方向有关

% I=rgb2gray(imread('image.bmp'));
% sigma=pi/2;
% theta=2*pi/3;
% f=pi/1.4;
% width=5;


Sx=width;
Sy=width;

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

for x = -fix(Sx):fix(Sx)
    for y = -fix(Sy):fix(Sy)
        xPrime = x * cos(theta) + y * sin(theta);
        yPrime = y * cos(theta) - x * sin(theta);
        G(fix(Sx)+x+1,fix(Sy)+y+1) = exp(-.5*(xPrime^2+yPrime^2)/sigma.^2)*cos(2*pi*f*xPrime);
    end
end

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

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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -