C++ 如何将gabor过滤器应用于opencv中的图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23077105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to apply gabor filter to images in opencv?
提问by richard
I've got some wavelets with the gabor filter code, it's something like this..
我有一些带有 gabor 滤波器代码的小波,就像这样..
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!
但我不知道如何在我的图像上使用它?我知道matlab有一些方法,即matlab方式。但我正在使用opencv
,而且我对这个领域很matlab
陌生,我不知道如何从 matlab 代码中编写 opencv 代码,所以,我应该用它来做opencv
什么?非常感谢!
****Update****
I've tried @berak's way, and this is the original image
****更新****
我试过@berak 的方法,这是原图
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?
我的设置有问题吗?
回答by berak
basically, you convert your img to float,
基本上,您将 img 转换为浮动,
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:
并用 filter2D 应用它:
cv::filter2D(src_f, dest, CV_32F, kernel);
[edit]
[编辑]
** i'm not sure, but you'll probably need a 1channel image as input.
** 我不确定,但您可能需要 1 通道图像作为输入。
** imshow sees, your image is float, and just saturates anything beyond 1.0, so you get an all white image.
** imshow 看到,您的图像是浮动的,并且只会使超过 1.0 的任何内容饱和,因此您将获得全白图像。
(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();
回答by sandeep
change sigma=3 lambda=36 theta=116 psi=274
改变西格玛=3 λ=36 θ=116 psi=274