简体   繁体   中英

How to apply gabor filter to images in opencv?

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

but i don't know how to use it on my image? i know there are some ways with matlab,ie 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 在此输入图像描述 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?

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

改变sigma = 3 lambda = 36 theta = 116 psi = 274

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM