# How to intuitively interpret Gabor lambda param?

I have troubles understanding in an intuitive way (not by writing complicated math formulas) what is the meaning of the lambda parameter in the Gabor functions. (I have basic math understanding, grad level, but this look a bit too much for me)

Is it a parameter that controls the sinusoidal part of the function? Or the gaussian part of it? And why those funny effects at $\pi/2$ ?

Here is the formula, from Wiki (real part of the equation): $$g(x, y; \lambda, \theta, \psi, \sigma, \gamma) = \exp \left(- \frac{x'^2 + \gamma^2 y'^2}{2 \sigma^2} \right) \cos \left( 2\pi \frac{x'}{\lambda} + \psi \right)$$

Were

$x' = x \cos \theta + y \sin \theta$

and

$y' = -x \sin \theta + y \cos \theta$

And here are some pictures, where I varied lambda:

$\lambda = \pi$

$\lambda = \pi/2$

$\lambda = \pi/4$

The other parameters are as follows: $$\sigma = 3 \\ \theta = -\pi/4 \\ \gamma = 1 \\ \psi = \pi$$

Edit The code I use is below (taken from OpenCV)

cv::Mat cv::getGaborKernel( Size ksize, double sigma, double theta,
double lambd, double gamma, double psi, int ktype )
{
double sigma_x = sigma;
double sigma_y = sigma/gamma;
int nstds = 3;
int xmin, xmax, ymin, ymax;
double c = cos(theta), s = sin(theta);

if( ksize.width > 0 )
xmax = ksize.width/2;
else
xmax = cvRound(std::max(fabs(nstds*sigma_x*c), fabs(nstds*sigma_y*s)));

if( ksize.height > 0 )
ymax = ksize.height/2;
else
ymax = cvRound(std::max(fabs(nstds*sigma_x*s), fabs(nstds*sigma_y*c)));

xmin = -xmax;
ymin = -ymax;

CV_Assert( ktype == CV_32F || ktype == CV_64F );

Mat kernel(ymax - ymin + 1, xmax - xmin + 1, ktype);
double scale = 1/(2*CV_PI*sigma_x*sigma_y);
double ex = -0.5/(sigma_x*sigma_x);
double ey = -0.5/(sigma_y*sigma_y);
double cscale = CV_PI*2/lambd; // Here is the interesting part. What happens here?

for( int y = ymin; y <= ymax; y++ )
for( int x = xmin; x <= xmax; x++ )
{
double xr = x*c + y*s;
double yr = -x*s + y*c;

double v = scale*exp(ex*xr*xr + ey*yr*yr)*cos(cscale*xr + psi);
if( ktype == CV_32F )
kernel.at<float>(ymax - y, xmax - x) = (float)v;
else
kernel.at<double>(ymax - y, xmax - x) = v;
}

return kernel;
}

-
The arguments of $g$ are $x,y,\dots$ but the formula you gave has $x',y'$. What is the relation between $x,y$ and $x',y'$? –  user31373 Aug 6 '12 at 15:44
@LeonidKovalev added them. I have forgotten an important detail :) –  vasile Aug 6 '12 at 16:26
hello i am also in same problem can i get small help from your side about gabor filter bank ? If you can then can i get your personal email details :) Thanks, Satish –  relstudiosnx Dec 16 '12 at 19:21
Try this link, here they briefly explained about what is gabor filter and its parameters cs.rug.nl/~imaging/simplecell.html –  user140563 Apr 5 '14 at 7:02

The term $$\cos \left( 2\pi \frac{x'}{\lambda} + \psi \right)$$ describes a wave of wavelength $\lambda$, because adding $\lambda$ to $x'$ does not change the value of this function. if you had $x$ instead of $x'$ there, the waves would be "flowing left to right" on the picture, more precisely each wavefront would be vertical. The transformation from $x,y$ to $x',y'$ rotates the picture by $\pi/4$, so we see wavefronts (colored stripes) along the NW-SE line.
The other factor $$\exp \left(- \frac{x'^2 + \gamma^2 y'^2}{2 \sigma^2} \right)$$ decreases the amplitude away from the origin. This is why the stripes become less distinct toward the edges of each picture.
The above explains everything I see on the 1st and 3rd graph. It does not explain the 2nd graph, where we see another oscillating pattern in the $y'$ direction. I think the 2nd graph shows a different function.
@vasile: In details: this is merely $2\pi/\lambda$ i.e. an optimization. I think that the real problem is that $x$ and $y$ are integers (and incremented by $1$). When $\lambda <2$ you'll get strong variations of values inside the $\cos$ and you'll get visual artifacts because of this. I think that $\lambda$ should be larger than $2$ or the sampling smaller or the whole thing should be rescaled (if you insist on using these too small $\lambda$)... –  Raymond Manzoni Aug 6 '12 at 18:14