我是OpenCV和gabor过滤器的新手,只想获取gabor小波,如下所示:
我在Java中使用以下OpenCV代码:
double sigma_bar = 40;
double theta_bar = 0.5;
double lambda_bar = 11;
double gamma_bar = 100;
double psi_bar = 90;
double kernel_size = 150;
Mat intermediate = new Mat(150, 150,CvType.CV_8U);
Mat output = Mat.zeros(150, 150, CvType.CV_32F);
Mat gabor_mat = Imgproc.getGaborKernel(new Size(kernel_size, kernel_size),sigma_bar / 10., theta_bar / 180. * Math.PI,lambda_bar, gamma_bar / 100., psi_bar / 180. * Math.PI, CvType.CV_32F);
Imgproc.filter2D(intermediate, output, -1, gabor_mat);
Bitmap temp = Bitmap.createBitmap(intermediate.cols(), intermediate.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(output, temp);
ImageView gabor = (ImageView) findViewById(R.id.gabor);
gabor.setImageBitmap(temp);
并获得以下输出:
我想我不需要应用
Imgproc.filter2D
,但是没有它,我的应用程序会因为CvTypes
而崩溃,当我尝试通过转换类型来解决该问题时,我得到了白屏。谁能帮我得到这个gabor小波?
最佳答案
您只需要:
NORM_MINMAX
的gabor过滤器,以便值适合[0,255]
的范围CV_8U
(从CV_64F
)我不能给您Java代码来执行此操作,但是我认为该C++代码段仍然有用,因为基本上存在对Java的1对1转换。然后,您需要给
getGaborKernel
参数以获取所需的形状。这是我得到的结果:
码:
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat kernel = getGaborKernel(Size(151, 151), 10, 0.1, 10, 1, CV_PI/2.0);
// kernel is of type CV_64F
Mat normalized;
normalize(kernel, normalized, 0, 255, NORM_MINMAX);
// normalized is of type CV_64F, but with values in [0, 255]
Mat converted;
normalized.convertTo(converted, CV_8U, 1, 0);
// converted is of type CV_8U
imshow("Gabor", converted);
waitKey();
return(0);
}
关于android - Gabor滤波器(小波),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33789130/