C++ OPENCV 灰度共生矩阵的生成和利用

#include <string>
#include<fstream>
#include<iostream>
#include <vector>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
typedef struct _GLCMFeatures
{
   
    _GLCMFeatures()
        : energy(0.0)
        , entropy(0.0)
        , contrast(0.0)
        , idMoment(0.0)
    {
   
        //this->energy = 0.0;
    }
    double energy;      // 能量 
    double entropy;     // 熵
    double contrast;    // 对比度
    double idMoment;    // 逆差分矩, inverse difference moment
} GLCMFeatures;

enum ANGLE
{
   
    GLCM_HORIZATION = 0,        // 水平
    GLCM_VERTICAL = 1,          // 垂直
    GLCM_ANGLE45 = 2,           // 45度角
    GLCM_ANGLE135 = 3           // 135度角
};

// 能量 
double energy;
// 熵
double entropy;
// 对比度
double contrast;
// 逆差分矩, inverse difference moment
double idMoment;
// 将灰度共生矩阵划分为 grayLevel 个等级
int m_grayLevel = 16;
// 计算灰度共生矩阵
void calGLCM(Mat inputImg, vector<vector<int>>& vecGLCM, int angle);
// 计算特征值
void getGLCMFeatures(vector<vector<int>>& vecGLCM, GLCMFeatures& features);
// 初始化灰度共生矩阵
void initGLCM(vector<vector<int>>& vecGLCM, int size = 16);
// 计算水平灰度共生矩阵
void getHorisonGLCM(vector<vector<int>>& src, vector<vector<int>>& dst, int imgWidth, int imgHeight);
// 计算垂直灰度共生矩阵
void getVertialGLCM(vector<vector<int>>& src, vector<vector<int>>& dst, int imgWidth, int imgHeight);
// 计算 45 度灰度共生矩阵
void getGLCM45(vector<vector<int>>& src, vector<vector<int>>& dst, int imgWidth, int imgHeight);
// 计算 135 度灰度共生矩阵
void getGLCM135(vector<vector<int>>& src, vector<vector<int>>& dst, int imgWidth, int imgHeight);
int main()
{
   
    for (size_t i = 1; i < 4; i++)
    {
   
        string s = "test" + to_string(i) + ".jpg";
        Mat img = imread(s, 0);
        vector<vector<int>>vec;
        GLCMFeatures features;
        initGLCM(vec
  • 2
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值