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

2

0

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.

Kenrick answered 18/11, 2015 at 13:35 Comment(0)
L
1

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

Ludicrous answered 18/11, 2015 at 14:12 Comment(3)
Got it. Thank you so much!Kenrick
dear @Ludicrous would you please take a look at my question #49218736Rory
@Ludicrous >>Dear Miki no one has answered my question yet, I appreciate if you have the time now to take a look.Rory
H
1

Actually the difference between cos and sin is and offset of 90 degrees or PI/2. So you can get the real and imaginary Gabor Kernels by making the PSI as 0 for real and PI/2 for imaginary.

Mat kernelReal = getGaborKernel(ksize, sigma, theta, lambda, gamma, 0, 0, CV_32F); Mat kernelImag = getGaborKernel(ksize, sigma, theta, lambda, gamma,0, PI/2, CV_32F);

Heiner answered 9/8, 2017 at 11:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.