### Highlights from 2D Gabor Filter(Ver1,2,3)

4.07792

4.1 | 79 ratings Rate this file 177 Downloads (last 30 days) File Size: 2.49 KB File ID: #5237

# 2D Gabor Filter(Ver1,2,3)

13 Jun 2004 (Updated )

To design 2D Gabor filter and apply it to image.

File Information
Description

Recent studies on Mathematical modeling of visual cortical cells [Kulikowski/Marcelja/Bishop:1982] suggest a tuned band pass filter bank structure. These filters are found to have Gaussian transfer functions in the frequency domain. Thus, taking the Inverse Fourier Transform of this transfer function we get a filter characteristics closely resembling to the Gabor filters. The Gabor filter is basically a Gaussian (with variances sx and sy along x and y-axes respectively) modulated by a complex sinusoid (with centre frequencies U and V along x and y-axes respectively).

Gabor filters are used mostly in shape detectin and feature extractin in image processing.

from 'gaborfilter1' with different f(Frequency) and theta(Angle).
for example

f:0,2,4,8,16,32
theta = 0,pi/3,pi/6,pi/2,3pi/4

then for any input image like(eg. stereo.jpg)

you have 6x5 = 30 filtered images.

You can choose your desired angles or frequencies.

You can put nominaly Sx & Sy = 2,4 or some one else.

For instance I tested above example on ('cameraman.tif')(in MATLAB pictures)

Acknowledgements

This file inspired Gabor Filter.

Required Products Filter Design Toolbox
Image Processing Toolbox
MATLAB release MATLAB 6.5 (R13)
08 Dec 2013
24 Oct 2013
15 Feb 2013

thanks

15 Feb 2013

thanks alot

10 Jul 2012
26 Apr 2012

Hi,
I also recognized the missing imaginary part:
In General:
r*e^(i*phi) == r*(cos(phi)+i*sin(phi))

If you simplify r*e^(i*phi) to r*cos(phi) the you leave out the imaginary part. For this reason you needn't use 'conv2(imag(image))', because it's zero anyway.

So either add the imaginary part or leave out the imaginary part convolution to improve computation costs.

Or do I misapply your code?

15 Mar 2012

hello i am new to Matlab and i need Gabor filter code for edge detection ??? i am not getting how to do ......anyone help me

08 Aug 2011

??? Undefined function or method 'gaborfilter' for input arguments of
type 'double'.
I am getting this error.
I tried with different input but cant fix it.
Anyone help me..

29 Jul 2011

Thank you!
I would like to ask you if there is anyway to plot the Gabor filter created with gabor1

02 May 2011

a good job!

04 Mar 2011

oru mannum velangala

15 Jan 2011

Hi all,
i have tried this gabor filter
I got the some error:
if isa(I,'double')~=1

i m working on gabor filter
will u please send me the details
n if possible the code for fingerprint image
enhancement using it
Thank you

09 Nov 2010
09 Nov 2010

thaks a lot

05 Oct 2010

does someone know how to implement this in c#? im kinda new to matlab so its difficult to know how this exactly loops over pixel arrays in bitmaps etc... if someone could convert this to c# or explain it would be great

18 Sep 2010

Thanks a lot! This is really helpful.

06 Sep 2010

It seems, you can't use clickable thumbnails here, so here are the proper links:

06 Sep 2010

Seemingly I was wrong, and after [G,gabout] = ... the filter is in G.
But this raises an other question (I hope someone can answer):

The parameters I used were the following:
Sx = 16;
Sy = 32;
theta = pi/2
I is a 100x100 matrix consisting of ones

For the parameter F, I used the following numbers: 0,2,4,32

And here are the pictures of the log amplitudos of the resulting G matrixes:

And no, I did not upload the same picture four times, they just look a lot alike, but I can't seem to find out why. Could anyone please help?

02 Sep 2010

The function seems useful.
I'd like to ask something, risking to look stupid: Is it correct to assume, that for getting the actual filter (to see how it looks, also I need to use the same filter on thousands of images), it is enough to choose I as a matrix consisting of ones?
Thanks in advance for the help.

10 Aug 2010

very good script

10 Aug 2010
08 Aug 2010

Can anyone help me to correct the gabor filter below to produce the response image in order to analyse the texture of the brain image.

%i is input image
%fourier transform of the input image
i2 = fft2(i);

%gabor filter in polar coordinates
%sinusoidal carrier
[M, N] = size(i2);
F0 = 64*sqrt(2); %spatial frequency of sinusoidal carrier
w0 = 135; %direction of sinusoidal carrier
P = 0; %phase of sinusoidal carrier

%gaussian envelop
x0 = N/2; %peak of the function
y0 = M/2; %peak of the function
a = 1/128; %axis of the gaussian envelop
b = 1/128; %axis of the gaussian envelop
theta = 135; %orientation of gaussian envelop
K = 2*pi*(1/a*b);

%complex gabor function
carrier = zeros(size(i));
envelop = zeros(size(i));
gabor = zeros(size(i));
gtransform = zeros(size(i));

for y = 1:M
for x = 1:N
%carrier
carrier(y,x) = exp(1i*(2*pi*F0*((x*cosd(w0))+(y*sind(w0))) + P));

%envelop
x1 = (x-x0)*cosd(theta) + (y-y0)*sind(theta);
y1 = -(x-x0)*sind(theta) + (y-y0)*cosd(theta);
envelop(y,x) = K*exp(-pi*((a^2*x1^2)+(b^2*y1^2)));

%gabor filter
gabor(y,x) = conv2(carrier(y,x),envelop(y,x));

%convolution between gabor n input (filtered image)
gtransform(y,x) = conv2(gabor(y,x),i2(y,x));
end
end

%response image
i3 = ifft2(gtransform);

29 Jul 2010

thanks a lot

12 May 2010

When The Filter is created in the Frequency Domain why it is converted into spatial domain For Convolving with the Image .Is It essential or can we perform convolution in frequency domain

25 Jan 2010

it is very useful thanks

29 Sep 2009
07 Apr 2009
02 Mar 2009

can u just brief me on the parameters of the filter?On what basis do i select the parameter values??

27 Jan 2009

By looking over the code and the description, it seems the filters are being crated in the frequency domain and then applied in the spatial domain. Please correct me if I am wrong but this is WRONG. There are two RIGHT approaches. The first is that one needs to take the inverse FT of the filter and then convolve it with the image. The second it that one needs to convert the image into the frequency domain, multiply the spectra and then take the inverse of the result.

11 Nov 2008

nice

16 Oct 2008

i m working on gabor filter
will u please send me the details
n if possible the code for fingerprint image
enhancement using it

15 Oct 2008

@Geovanny Giorgana: the filter works only for a 2-D immage. Try checking the size of the input image.

14 Oct 2008
14 Oct 2008
13 Oct 2008

Hi all, I got the same error: Function 'conv2' is not defined for values of class 'double' and attributes 'full 3d real'.

Can someone explain me how to solve it. Thank you.

14 Sep 2008

it is efficiently working

22 Jul 2008

Very efficient

09 Jul 2008

good job

28 May 2008

Ican't fix "Undefined function or method 'conv2' for input arguments of type 'double' and attributes 'full 3d real'." Please somebody tell how fix it by "reshape". Thanks

13 May 2008

12 May 2008

Aslamo alekm
are you hove this code using IDL programming

12 Mar 2008

27 Feb 2008
22 Feb 2008

good

18 Feb 2008

Muy buen Codigo !

04 Feb 2008

Its very good.

12 Dec 2007

very good!

16 Nov 2007
30 Oct 2007

A few images with corresponding parameters would have helped understand this better.

23 Oct 2007

Gabor filter is a very interesting topic in wavelets.

17 Oct 2007

Why I have this error?
Function 'conv2' is not defined for values of class 'double' and attributes 'full 3d real'.

15 Jul 2007

thx

13 May 2007

The discrepancy between the results obtained by filtering with this implementation and the with the one on the matlabserver.cs.rug.nl is, I think, related to the size of the filter, G, instead of fix(Sx) (and fix(Sy)), try something like fix(3*Sx) etc.-i.e.enlarge the size of the filter- and the code works just fine (in corformity with matlabserver.cs.rug.nl), nothing wrong with the code.

10 May 2007
05 May 2007
23 Feb 2007
31 Jan 2007

The formula used in this code doesn't have parameters like aspect ratio and phase. so it is not fair to compare the results with some other code. All depends on the parameters you set.

19 Jan 2007

I don't know if there is a mistake in this code. In fact the imaginary part is always null but it is normal if we look the formula used. In the formula there is not the imaginary part.
The general gabor formula has an imaginary part, but usually , when I read article, there is not this imaginary part and I don't know why.
Is there someone to answer ???

I implement gabor with the imaginary part and when I try with this link http://matlabserver.cs.rug.nl/edgedetectionweb/web/index.html I don't find the same things. But the result depends how we set parameters.

29 Dec 2006

i think there is a mistake in this code. because the results shown in this link http://matlabserver.cs.rug.nl/edgedetectionweb/web/index.html are obtained by using the equation in this link, http://matlabserver.cs.rug.nl/edgedetectionweb/web/edgedetection_params.html

but unfortunately, these results are not as same as yours.

isn't it???

please, tell me if i'm wrong.
thanks a lot..

07 Dec 2006

The output seems to be the modulus of the complex response to your filter. In many cases, the interesting part is the real component, and not the modulus, which is a non-linear operation !

29 Nov 2006
28 Oct 2006

I am reading the gaborfilter1.m (version2), and I think there is a mistake.
In the source codes, there is a code line to retrive imaginary parts of filters as imag(G).
However, the math equation of G is originally calculating only real responses (cos). There is no jsin or exp(j...).
Don't you need imaginary responses?

10 Oct 2006

very nice

28 Sep 2006

Functionality is good, but code does not depends on any toolbox and documentation is not in standard matlab format.

25 Aug 2006

Thanks, I have been searching for it.

08 Aug 2006
21 Jul 2006
18 Jul 2006

Cool

01 Jun 2006

Great

28 May 2006

Excellent. Has some one tried recursive Gabor filtering & its usefulness? Can some one share?

28 May 2006

Cool

16 May 2006
03 May 2006

great work

02 May 2006
30 Apr 2006

cool

29 Apr 2006
16 Apr 2006

very good,I once program a c++ version about gabor filters. now I find this code and use it to verify mine. It is very convenient and thanks for u.

02 Apr 2006

good!

23 Mar 2006

Cn anyone tell me how to calculate optimal sx,sy,theta and f for an image.so that this function cn be used irrespective of any image.How to implement it i mean how to use the output G and gabout.Thx in advance.urgetntly in need of reply

20 Mar 2006
13 Mar 2006
08 Mar 2006

This helps me a lot!

05 Mar 2006

I found this little description very useful. Wee bit'o more info about the cortical cell study .. or maybe where I can find it would be useful. And yeah im working on fingerprints and would like to get more info in that regard

02 Mar 2006
17 Feb 2006

"Gabor filters are used mostly in shape detectin and feature extractin in image processing"

Can somebody give me some help on how to use gabor filter for fingerprint image feature extraction?

thanks..

05 Jan 2006

It is very good and suit for new researchers!
Thank you !

09 Dec 2005

A Good Job done

01 Dec 2005

Q1. What is the difference between GaborFilter,
GaborFilter1 and GaborFilter2 ?

Q2. Is R13 realease same as MATLAB version 7.0 ?

I tried the files.They work fine.

09 Nov 2005
27 Sep 2005
23 Sep 2005

i want to process the image of fingerprints,i hope this can help me to enhance the image.

01 Sep 2005

The mask matrix is excellent in approximation to the Gaussian envelope.

31 Aug 2005
08 Aug 2005
11 Jul 2005
03 Jul 2005

after I tried, I think it's great...!!!

27 Jun 2005

les deux filtre ne sont pas symetrique.
pour verifier tu fais sum(G1(:)) tu va trouver que ce n'est pas tjr symetrique;

20 May 2005

It doesn't work when using pi/2

28 Apr 2005

Excellent work. In order to improve filtering performances a Recursive Gabor filtering for 1D and 2D signals is required.

http://utenti.lycos.it/matlab/gabor.htm

21 Apr 2005

thank you:)

04 Dec 2004

The normalization doesn't work. The repsonse jumps out of bounds at pi/2

09 Nov 2004

It is good

02 Aug 2004

Usually 2D design of Gabor filters require DESIGN in 2D Frequency ( because it can easily get out of boounds!). This is related to several issues:
a) not obeying the Nyquist criteria
b) phase distortions
c) not forming a '' frame'' see 10 lectures on wavelets
d) mack up in 2D frequencies

05 Jul 2004
05 Jul 2004

very powerfull!

02 Jul 2004

thnka

21 Jun 2004

I need this for my project very very much.You do it well:))

19 Jun 2004

thx,very complete!!