Gabor filter


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.

Screen Shot 2014-03-10 at 10.31.51 Screen Shot 2014-03-10 at 10.31.53

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:

Screen Shot 2014-03-10 at 10.36.54

You can read more about Gabor filter on its Wikipedia page

The example python code for this gabor filter can be found here:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s