Search code examples
c#image-processinggabor-filter

Understanding Gabor filter


In Accord.net framework, two classes are used to construct a Gabor filter:

There are various implementations of Gabor filter elsewhere:

but, the source codes in Accord.net look very strange to me. They discuss 3 types of kernels:

  • Real
  • Imaginary
  • Magnitude
  • SquaredMagnitude

Can anyone either explain the latter 3 (Real is self-explanatory) types or refer me to some materials where I can study them?


Solution

  • The Gabor kernel g(t) is complex-valued. It is a quadrature filter, meaning that, in the frequency domain (G(f)), it has no negative frequencies. Thus, the even and odd parts of this frequency response are related by even(G(f)) = odd(G(f)) * sign(f). That is, the even and odd parts have the same values for positive frequencies, but inverse values for negative frequencies. Adding up the even and odd part leads thus to the negative frequencies canceling out, and the positive frequencies reinforcing each other.

    The even part of the (real-valued) frequency response corresponds to an even and real-valued kernel. The odd part corresponds to an odd and imaginary-valued kernel. The even kernel is a windowed cosine, the odd kernel is a windowed sine.

    The Gabor filer is applied by convolving the image with these two components, then taking the magnitude of the result.

    The magnitude of the filter itself is just a Gaussian smoothing kernel (it's the window over the sine and cosine). Note that cos^2+sin^2=1, so the magnitude doesn't show the wave component of the kernel. The code you linked that computes the magnitude of the Gabor kernel does a whole lot of pointless computations... :)