Python This is an example implementation in
Python: import numpy as np def gabor(sigma, theta, Lambda, psi, gamma): """Gabor feature extraction.""" sigma_x = sigma sigma_y = float(sigma) / gamma # Bounding box nstds = 3 # Number of standard deviation sigma xmax = max( abs(nstds * sigma_x * np.cos(theta)), abs(nstds * sigma_y * np.sin(theta)) ) xmax = np.ceil(max(1, xmax)) ymax = max( abs(nstds * sigma_x * np.sin(theta)), abs(nstds * sigma_y * np.cos(theta)) ) ymax = np.ceil(max(1, ymax)) xmin = -xmax ymin = -ymax (y, x) = np.meshgrid(np.arange(ymin, ymax + 1), np.arange(xmin, xmax + 1)) # Rotation x_theta = x * np.cos(theta) + y * np.sin(theta) y_theta = -x * np.sin(theta) + y * np.cos(theta) gb = np.exp( -0.5 * (x_theta**2 / sigma_x**2 + y_theta**2 / sigma_y**2) ) * np.cos(2 * np.pi / Lambda * x_theta + psi) return gb For an implementation on images, see
MATLAB This is an example implementation in
MATLAB/
Octave: function gb = gabor_fn(sigma, theta, lambda, psi, gamma) sigma_x = sigma; sigma_y = sigma / gamma; % Bounding box nstds = 3; xmax = max(abs(nstds * sigma_x * cos(theta)), abs(nstds * sigma_y * sin(theta))); xmax = ceil(max(1, xmax)); ymax = max(abs(nstds * sigma_x * sin(theta)), abs(nstds * sigma_y * cos(theta))); ymax = ceil(max(1, ymax)); xmin = -xmax; ymin = -ymax; [x,y = meshgrid(xmin:xmax, ymin:ymax); % Rotation x_theta = x * cos(theta) + y * sin(theta); y_theta = -x * sin(theta) + y * cos(theta); gb = exp(-.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+psi); Code for Gabor feature extraction from images in
MATLAB can be found at http://www.mathworks.com/matlabcentral/fileexchange/44630.
Haskell This is another example implementation in
Haskell: import Data.Complex gabor λ θ ψ σ γ x y = exp(-(x'^2 + γ^2 * y'^2) / (2*σ^2)) * exp(i * (2*pi*x'/λ + ψ)) where x' = x * cos θ + y * sin θ y' = -x * sin θ + y * cos θ i = 0 :+ 1 == See also ==