Gabor filter is an interesting image filter. It’s modelled after human’s visual system. Its sensitivity towards frequency and orientation, makes it a good filter when it comes to extracting features from textures.
Gabor filter itself is actually quite straightforward, it’s a multiplication of a sinusoidal component, and a gaussian component. Below shows how gabor kernels look like under different 2 different orientations (i.e. theta = 0 and 15 degrees), it also shows the gaussian and sinusoidal parts.
Creating the gabor kernel itself is quite straightforward, as the following code shows.
def gabor( size, sigma, theta, lambd, gamma, psi=0.5*pi ): xmax, ymax = size / 2, size / 2 x, y = meshgrid( linspace(-xmax, xmax, size ), linspace(-ymax, ymax, size ) ) x_theta = x * cos(theta) + y * sin(theta) y_theta = -x * sin(theta) + y * cos(theta) gauss = exp( - ( x_theta**2 + gamma**2 * y_theta **2 ) / (2. * sigma**2) ) grating = cos( (2 * pi / lambd) * x_theta + psi ) return -gauss * grating
And here’s an example of the result of convolving gabor kernel with an image:
The example python code for this gabor filter can be found here: https://github.com/subokita/Sandbox/blob/master/gabor.py