6

I've got some wavelets with the gabor filter code, it's something like this..wavelets

but i don't know how to use it on my image? i know there are some ways with matlab,i.e matlab way. but I'm using opencv, and I'm very new to this field and matlab, I don't know how to write the opencv code from the matlab code, so , waht am I supposed to do this with opencv? thanks very much!

****Update****
I've tried @berak's way, and this is the original image

and this is after I applied the filter enter image description here just all white and nothing left,below is my params,

int kernel_size = 31;
double sig = 1, th = 0, lm = 1.0, gm = 0.02, ps = 0;
cv::Mat kernel = cv::getGaborKernel(cv::Size(kernel_size, kernel_size), sig, th, lm, gm, ps);
cv::filter2D(src_f, dest, CV_32F, kernel);

is there anything wrong with my setting?

Community
  • 1
  • 1
richard
  • 742
  • 2
  • 9
  • 21

2 Answers2

11

basically, you convert your img to float,

then construct a kernel:

cv::Mat kernel = cv::getGaborKernel(cv::Size(kernel_size,kernel_size), sig, th, lm, gm, ps);

and apply it with filter2D:

cv::filter2D(src_f, dest, CV_32F, kernel);

[edit]

** i'm not sure, but you'll probably need a 1channel image as input.

** imshow sees, your image is float, and just saturates anything beyond 1.0, so you get an all white image.

(this is just a visualization problem, needs a bit of conversion/scaling to cure it)

Mat in = imread("XfNal.jpg",0);          // load grayscale
Mat dest;
Mat src_f;
in.convertTo(src_f,CV_32F);

int kernel_size = 31;
double sig = 1, th = 0, lm = 1.0, gm = 0.02, ps = 0;
cv::Mat kernel = cv::getGaborKernel(cv::Size(kernel_size,kernel_size), sig, th, lm, gm, ps);
cv::filter2D(src_f, dest, CV_32F, kernel);

cerr << dest(Rect(30,30,10,10)) << endl; // peek into the data

Mat viz;
dest.convertTo(viz,CV_8U,1.0/255.0);     // move to proper[0..255] range to show it
imshow("k",kernel);
imshow("d",viz);
waitKey();

clip_gabor

berak
  • 39,159
  • 9
  • 91
  • 89
  • I don't get it, I use the code that I get from the web to generate the wavelets, and you mean I don't need it and just use these two lines and can apply gabor filter on my image? or can you please provide more details? – richard Apr 15 '14 at 07:53
  • 1
    the 1st line constructs one wavelet, the 2nd applies it to the image. imho, that's all you ever need in opencv – berak Apr 15 '14 at 07:59
  • I've tried but still don't get what I want. could you please see my update? – richard Apr 15 '14 at 08:59
  • better now ? feel free to complain if not. – berak Apr 15 '14 at 09:37
  • It works now, though the effect is not good enough,but it's another problem, maybe I should ask another question. – richard Apr 15 '14 at 10:18
  • yes. good idea. then please refine, what 'good enough' would mean exactly. the current wavelet you're applying is just doing a vertical 1pixel blur, usually you got something more advanced there. try playng with the params, and applying several filter2d passes with different wavelets, aka a "filterbank" – berak Apr 15 '14 at 10:23
-6

change sigma=3 lambda=36 theta=116 psi=274

sandeep
  • 1
  • 1
  • 6
    Why? What's your rationale behind these parameters? How did you come up with these? – rayryeng Jan 05 '15 at 00:47
  • See the definition and especially psi. Imho your params incorrect. CV_EXPORTS_W Mat getGaborKernel( Size ksize, double sigma, double theta, double lambd, double gamma, double psi = CV_PI*0.5, int ktype = CV_64F ); – Cynichniy Bandera Feb 10 '16 at 12:42