opencvimage-processingiris-recognition

How to get the real and imaginary parts of a gabor kernel matrix in OpenCV


A OpenCV beginner and bad math. My job is to apply the Gabor filter to a normalized image. And I only know that OpenCV has a getGaborKernel function, and i want to know the return Matrix of this function is the real part or the imaginary part of the kernel. If I can't use this function, then how can I generate those kernel? Using Java API, but C++ code is fine.


Solution

  • You can see in gabor.cpp at line 87 that it's computing the real part (according to wikipedia).

    double v = scale*std::exp(ex*xr*xr + ey*yr*yr)*cos(cscale*xr + psi);
    

    You can get the imaginary part modifying this line to (as reported also here)

    double v = scale*std::exp(ex*xr*xr + ey*yr*yr)*sin(cscale*xr + psi);
                                                   ^^^
    

    Once you have your kernel, you can use it with the function filter2d