问题
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.
回答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
回答2:
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);
来源:https://stackoverflow.com/questions/33781502/how-to-get-the-real-and-imaginary-parts-of-a-gabor-kernel-matrix-in-opencv