implement the filtering of Gabor filter
Image textures are suitable for aerial remote sensing images, fabric patterns, complex natural landscapes, and flora and fauna. Here I use remote sensing images, fabric patterns and steel surfaces to make a comparison with canny pictures.
Compared to the canny algorithm (or adaptive canny) of the remote sensing image braid, Gabor does have an advantage over the overall feature display, especially in places where light and shade change. The next step is how to use the image recognition stitching and image classification, and we need to continue studying. With code, according to open source code to make changes, welcome to point out problems and shortcomings, fromOpencv-gabor-filter-master. //gaborfilterhelper Modified according to Opencv-gabor-filter-master#include"StdAfx.h"#include <opencv2/core/core.hpp>#include<opencv2/imgproc/imgproc.hpp>#include<opencv2/highgui/highgui.hpp>#include<math.h>
//define initial coefficients
//Create Gabor CoreCv::mat Mkkernel (int KS,DoubleSig,Doubleth,DoubleLM,DoublePS){ intHKS = (ks-1)/2; Double theta = th*cv_pi/180; Doublepsi = ps*cv_pi/180; Doubledel = 2.0/(ks-1); Doublelmbd = LM; Doublesigma = Sig/ks; DoubleX_theta; DoubleY_theta;Cv::mat Kernel (ks,ks, cv_32f); for(inty=-hks, y<=hks; y++) { for(intx=-hks; x<=hks; x + +) {X_theta = X*del*cos (theta) +y*del*sin (theta);Y_theta =-x*del*sin (theta) +y*del*cos (theta);kernel.at<float> (hks+y,hks+x) = (float) exp ( -0.5* (POW (x_theta,2) +pow (y_theta,2))/pow (sigma,2)) * cos (2*CV_PI*X_THETA/LMBD + psi); } } returnkernel;}
//Get Gabor images, it seems to me that Gabor is a texture enhancer, similar to cannyMat Getgabor (Mat src, DoubleSig,DoubleLM,Doubleth,DoublePS,intkernel_size){ Mat dest;Mat Src_f; if(!kernel_size%2) {kernel_size+=1; }Src.convertto (Src_f, cv_32f, 1.0/255, 0); //Create convolutional coresCv::mat kernel = Mkkernel (kernel_size, Sig, Th, LM, PS); //Convolutioncv::filter2d (Src_f, dest, cv_32f, kernel);Cv::mat Lkernel (kernel_size*20, kernel_size*20, cv_32f);cv::resize (Lkernel, Lkernel, Lkernel.size ());Lkernel/= 2.;Lkernel + = 0.5;Cv::mat mag;CV::p ow (dest, 2.0, mag); returnmag;}
//int Main (int argc, char** argv)//{//Cv::mat image = Cv::imread ("DataSet/Training Picture/1.jpg", 1);//Cv::imshow ("SRC", image);//Cv::mat src;//Cv::cvtcolor (image, SRC, cv_bgr2gray);//Src.convertto (Src_f, cv_32f, 1.0/255, 0);//if (!kernel_size%2)// {//kernel_size+=1;// }//Cv::namedwindow ("Process window", 1);//Cv::createtrackbar ("Sigma", "Process window", &pos_sigma, kernel_size, process);//Cv::createtrackbar ("Lambda", "Process window", &POS_LM, +, process);//Cv::createtrackbar ("Theta", "Process window", &pos_th, and "process");//Cv::createtrackbar ("Psi", "Process window", &POS_PSI, and "process");//Process (0,0);//Cv::waitkey (0);//return 0;//}
From for notes (Wiz)
To implement the filtering of Gabor filter