Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a Gabor filter by applying Gabor equation using matlab

I tried to create a Gabor Filter. We all know that this kind of filter is more complex than any other filters because it is characterized by more complex features such as having different scales and orientations. The equation of Gabor filter is:

enter image description here

To create such a Gabor filter with a specific scale and direction, the wikipedia gives to us a simple matlab code about that:

sigma_x = sigma;
sigma_y = sigma/gamma;

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);


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);

I want to know if this code is correct. I notice that the code above didn't respond exactly to the equation of Gabor filter. For example: in the code, we have :sigma_x=sigma and sigma_y=sigma/gamma ... and we have gb=exp(-.5*(x_theta.....)). I didn't understand what is the 5 in the equation..

Is the matlab code written above respond correctly to the equation of the Gabor filter?? please i need your opinion and if possible to optimize the code if it is not correct.

Any help will be appreciated.

like image 922
Christina Avatar asked Dec 19 '22 21:12

Christina


2 Answers

Replace below line in your code:

gb= exp(-.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+psi);

I replace the cos with sin in above matlab code.

like image 54
User1551892 Avatar answered Jan 01 '23 16:01

User1551892


You can now create a Gabor filter bank using the gabor function in the image processing toolbox, and you can apply it to an image using imgaborfilt.

like image 26
Dima Avatar answered Jan 01 '23 16:01

Dima