File Exchange

image thumbnail

Gabor filter

version 1.3 (65.4 KB) by

Generates Gabor filters using bandwidth, aspect ratio, phase, wavelength and angle as parameters.

19 Ratings



View License

#5237 implements a Gabor filter for image processing. From the comments and through my own use, the implementation seems to have limited freedom, and also the variances are defined in the original x,y instead of the rotated x', y' directions.

The code is a modified version based on following the conventions and parameters used in

The function accepts scalar inputs only, and each call generates one filter. The filter generated is always real. Should you wish to build a complex Gabor filter, you may use (0 phase) + j(pi/2 phase). Filtering can be performed using conv2( ) or imfilter( ).

An example file is included, which mimics the behavior of at default settings with Lena.jpg image as input. Note that the scaling of numbers is different from the web-app, but consistent with the formulae in

Update 18-Nov-2010: Thanks to Rachel (see comment below), I have corrected a mistake in the example file. The results are unchanged though. Also, the website seems offline.

Comments and Ratings (30)

Andrea Gigli


Hi, Thanks for your code, I am using your code and I want to refer your work in my references, Could you tell me what I should refer?

thank for your sharing code


Malee (view profile)

Hi, Thanks for your code, I am using it for blood vessel segmentation. Can you explain more about these variables :
lambda, theta, psi, gamma, bw, N

how they are influencing img_out?


Steve (view profile)

kanwal preet

i would like to ask a question,for scale factor which value you used.

Jack Jones

I would like to ask the following question. I have used this filter with an image of all ones (imgin = ones(100,100)).

I get an image that consists entirely of ones, although my original image has no edges. Could you please explain what am I doing wrong or is this the normal behaviour of this filter?


Solana (view profile)

I am ver new to matlab and image processing, can someone please explain to me the mathematical and theoretical reasoning behind the following lines:
gb = gabor_fn(bw,gamma,psi(1),lambda,theta)...
+ 1i * gabor_fn(bw,gamma,psi(2),lambda,theta);

and the line
img_out_disp = sum(abs(img_out).^2, 3).^0.5;
% default superposition method, L2-norm

what is this superposition method? is that the standard formula for it?


vidya (view profile)


vidya (view profile)

can this filter be used for speech processing


Gabor Filter


Scott (view profile)

Best Gabor Filter I've seen


thong (view profile)


wang (view profile)


wang (view profile)


Jason (view profile)

Great one, thanks a lot. By the way, may I know, what does the size denote? Also, I can't seem to understand how the meshgrid in your code works.


shuai (view profile)


Marc (view profile)

Can someone explain me why when a bandwidth >1 is used the result differs from

using a bandwith of 10 I had to replace

img_out_disp = sum(abs(img_out).^2, 3).^0.5;
img_out_disp = sum(imag(img_out).^2, 3).^0.5;

in order to have the same results as

but don't know why. I believe this come from the ratio sigma to lamda < 0.5. Any mathematical explanation?


Rachel (view profile)

Very good implementation. And good job normalizing it! What I do notice is: you seem to do (a+b).^2 to get the modulus of the result. I thought for a complex number a+bj, you are supposed to do a.^2+b.^2 for the modulus. Lucky enough for this case, the cross term 2ab is simply zero because we are summing some trigonometric functions from 0 to 2pi.

Thanks I see now you are using just the real component

I superficially looked at the code and this looks like a gaussian filter with polar rotation of coordinates only 1/2 of the answer. Can you please advise.

My thoughts were:
2D gaussian = g(x,y) = 1/(2*PI*Theta(x)*Theta(y)) * exp(-0.5*[(x/theta(x)).^2 +(y/theta(y)).^2])

gabor = h(x, y) = g(x, y)* exp[j*2*pi*(U*x+V*y)]

James Kelly

hey, do you have any idea how to convert this to c#? I want to convert it but have no idea on how this loops trough pixels on the source image and how it produces the output image...

If you can write c#/c++/java/c code or at least explain to me as in what happens to the pixels that would be great, thanks. :)


Mario (view profile)

Please, someone can add some usage example of this code to an image to reproduce "exactly" the same results of the matlab's website ?

David Conger

David Conger (view profile)



Corrected procedures in the example file. Results are the same but the principle is more generally applicable.


Added an example file to mimic the behavior of a known web-app and to demonstrate the usage of the function.

MATLAB Release
MATLAB 7.4 (R2007a)

Inspired: 2D and 3D Gabor Filter Creators

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video