3
$\begingroup$

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$

enter image description here

$\lambda = \pi/2$

enter image description here

$\lambda = \pi/4$

enter image description here

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(ymax - y, xmax - x) = (float)v;             else                 kernel.at(ymax - y, xmax - x) = v;         }      return kernel; } 
  • 0
    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'$?2012-08-06
  • 0
    @LeonidKovalev added them. I have forgotten an important detail :)2012-08-06
  • 0
    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, Satish2012-12-16
  • 0
    Try this link, here they briefly explained about what is gabor filter and its parameters http://www.cs.rug.nl/~imaging/simplecell.html2014-04-05

1 Answers 1

1

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.

  • 0
    Thanks! I am still trying to understand the second graph. Which *is* created with the same function - I generated it myself - with the parameters from above. It may be something similar to diffraction patterns - alternate sine functions accumulate or subtract at different points in space2012-08-06
  • 1
    @vasile Maybe it's a numerical artifact (unlikely) or you made a typo in your code. Can you post the code?2012-08-06
  • 1
    @LeonidKovalev: in this [applet](http://www.cs.rug.nl/~imaging/simplecell.html) they specify : "The wavelength is given in pixels. Valid values are real numbers between 2 and 256". This could explain the nature of the artifact!2012-08-06
  • 0
    I've updated the question with the code, and a specific line got into my attention: `double cscale = CV_PI*2/lambd;`. The cscale parameter is used further. What happens here?2012-08-06
  • 1
    @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$)...2012-08-06
  • 1
    @RaymondManzoni Thanks for providing the context. Then the 1st and 3rd graphs must also be interference patterns, which happen to resemble what should have actually happened, but on a different scale. A note to vasile: [label the axes](http://xkcd.com/833/)2012-08-06
  • 0
    Thanks guys! Great info! I'd love to upvote both of you, but so far only Leonid takes the votes :). The axis labels are a good reminder indeed2012-08-06