You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.5 KiB

function gabor=gabor2D(sigma,orient,aspect,wavel,phase,pxsize,x0,y0)
%function gabor=gabor2D(sigma,orient,aspect,wavel,phase,pxsize,x0,y0)
% This function produces a numerical approximation to 2D Gabor function.
% Parameters:
% sigma = standard deviation of Gaussian envelope, this in-turn controls the
% size of the result (pixels)
% orient = orientation of the Gabor clockwise from the vertical (degrees)
% aspect = aspect ratio of Gaussian envelope (0 = no "width" to envelope,
% 1 = circular symmetric envelope)
% wavel = the wavelength of the sin wave (pixels)
% phase = the phase of the sin wave (degrees)
% pxsize = the size of the filter.
% Optional, if not specified size is 5*sigma.
% x0,y0 = location of the centre of the gabor.
% Optional, if not specified gabor is centred in the middle of image.
%convert degrees to radians
if nargin<6, pxsize=odd(5*sigma); end
if nargin<7, x0=0; y0=0; end
[x y]=meshgrid(-fix(pxsize/2):fix(pxsize/2),fix(-pxsize/2):fix(pxsize/2));
% Rotation
gabor=exp(-0.5.*( ((x_theta.^2)/(sigma^2)) ...
+ ((y_theta.^2)/((aspect*sigma)^2)) )) ...
.* (cos(freq*y_theta+phase) - cos(phase).*exp(-0.25.*((sigma*freq).^2)));
%if abs(sum(sum(gabor)))./sum(sum(abs(gabor)))>0.01
% disp('WARNING unbalanced Gabor');
% abs(sum(sum(gabor)))./sum(sum(abs(gabor)))