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.
Asked
Active
Viewed 1,631 times
0

ztypl
- 13
- 3
2 Answers
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

Miki
- 40,887
- 13
- 123
- 202
-
Got it. Thank you so much! – ztypl Nov 19 '15 at 16:09
-
dear @Miki would you please take a look at my question https://stackoverflow.com/questions/49218236/cluster-texture-based-on-features-extracted-from-gabor – Amir Mar 14 '18 at 11:38
-
@Miki >>Dear Miki no one has answered my question yet, I appreciate if you have the time now to take a look. – Amir Mar 30 '18 at 14:27
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);

Túlio Pires
- 11
- 1