Gabor滤波器的特征提取C++实现

本文介绍了如何使用OpenCV库在C++中实现Gabor滤波器的特征提取。项目应用了5个尺度、8个方向的40个卷积核,处理36*48大小的图像,得到4400维特征。为解决高维问题,可以考虑使用PCA或LDA进行降维,但具体实现未在文中详述。
摘要由CSDN通过智能技术生成

自己项目中用到了Gabor滤波器,于是自己借助Opencv图像库,实现了Gabor滤波器的特征提取,用类的形式将其封装,希望对大家有用>0<。

Gabor参数主要是5个尺度,8个方向,共40个卷积核。本人图片大小为36*48大小。下采样为10*11,故特征维数为:10*11*5*40=4400维。针对特征维数过大,可以采用PCA或LDA降维,这里就不展现了。

Gabor.h

#ifndef _GABOR_H
#define _GABOR_H

#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>

using namespace cv;
using namespace std;

#define Gabor_num    40
#define U   8
#define V   5

class Gabor
{
public:
    Gabor():m_kmax(CV_PI/2),m_f(sqrt(2.0)),m_sigma(CV_PI),ds_w(10),ds_h(11),ke_w(31),ke_h(31),raT(0.9){};

    void  MakeAllGaborKernal();

    void  MakeGaborKernal(int ke_h,int ke_w,int u,int v,Mat &GaborReal,Mat &GaborImg);

    Mat  Gabor_T_Fast1(Mat &src,int ds_h,int ds_w,Mat kel_GR[Gabor_num],Mat kel_GI[Gabor_num]);

    int  Gabor_T_Fast2(Mat &src,int ds_h,int ds_w,Mat kel_GR[Gabor_num],Mat kel_GI[Gabor_num],double* feature);

    Mat  Create_GaborF(Mat& src);

    int  getGaborMeanAndVarianceFeature(Mat &src,double* feature);

private:
    double m_kmax;
    double m_f;   
    double m_sigma; 
    int ds_w;
    int ds_h;
    int ke_w;
    int ke_h;
    double raT;
    Mat  GaborReal[Gabor_num];
    Mat  GaborImg[Gabor_num];

};

#endif


Gabor.cpp

#include "Gabor.h"

enum convtype 
{ 
    full, 
    same,
    valid
};


/*
*@函数名: conv2
*@功能:   卷积运算
*@参数:   const Mat &img    原图片    
           const Mat ikernel 卷积核
           convtype type     卷积类型

*@返回值: Mat               矩阵卷积后的结果
*@作者:   WiseClown
*@日期:   2016-1-7

*---------------------------------------
*时间      修改人         修改者
*---------------------------------------

**/

Mat conv2(const Mat &img, const Mat ikernel, convtype type) 
{
    Mat dest;
    Mat kernel;
    flip(ikernel,kernel,-1);
    Mat source = img;

    if(type 
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值