-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathglcm.h
More file actions
95 lines (77 loc) · 2.76 KB
/
glcm.h
File metadata and controls
95 lines (77 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef GLCM_H
#define GLCM_H
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <math.h>
using namespace std;
using namespace cv;
using namespace cv;
using namespace std;
// 灰度等级
// Gray Level (Choose in 4/8/16)
enum GrayLevel
{
GRAY_4,
GRAY_8,
GRAY_16
};
// 灰度统计方向
// Gray Value Statistical Direction
// (Choose in 0°, 45°, 90°, 135°)
enum GrayDirection
{
DIR_0,
DIR_45,
DIR_90,
DIR_135
};
// 彩色图中的指定通道
// Point out R, G, B Channel of a Image
enum RGBChannel
{
CHANNEL_R,
CHANNEL_G,
CHANNEL_B
};
// 纹理特征值结构体
// struct including Texture Eigenvalues
struct TextureEValues
{
// 能量
float energy;
// 对比度
float contrast;
// 相关度
float homogenity;
// 熵
float entropy;
};
class GLCM
{
public:
// 从彩色通道中提取一个通道
// Extract a channel from RGB Image
void getOneChannel(Mat src, Mat& dstChannel, RGBChannel channel = CHANNEL_R);
// 将灰度图中的所有像素值量级化,可以被量化为4/8/16个等级
// Magnitude all pixels of Gray Image, and Magnitude Level can be chosen in 4/8/16;
void GrayMagnitude(Mat src, Mat& dst, GrayLevel level = GRAY_8);
// 计算一个矩阵窗口中,按照某个方向统计的灰度共生矩阵
// Calculate the GLCM of one Mat Window according to one Statistical Direction.
void CalcuOneGLCM(Mat src, Mat &dst, int src_i, int src_j, int size, GrayLevel level = GRAY_8, GrayDirection direct = DIR_0);
// 矩阵的归一化,将矩阵所有元素与矩阵中所有元素之和作除运算,得到概率矩阵
// Normalize the Martix, make all pixels of Mat divided by the sum of all pixels of Mat, then get Probability Matrix.
void NormalizeMat(Mat src, Mat& dst);
// 计算单个窗口矩阵的图像纹理特征值,包括能量、对比度、相关度、熵
// Calculate Texture Eigenvalues of One Window Mat, which is including Energy, Contrast, Homogenity, Entropy.
void CalcuOneTextureEValue(Mat src, TextureEValues& EValue, bool ToCheckMat = false);
// 计算全图的图像纹理特征值,包括能量、对比度、相关度、熵
// Calculate Texture Eigenvalues of One Window Mat, which is including Energy, Contrast, Homogenity, Entropy.
void CalcuTextureEValue(Mat src, TextureEValues& EValue,
int size = 5, GrayLevel level = GRAY_8);
// 计算整幅图像的纹理特征
void CalcuTextureImages(Mat src, Mat& imgEnergy, Mat& imgContrast, Mat& imgHomogenity, Mat& imgEntropy,
int size = 5, GrayLevel level = GRAY_8, bool ToAdjustImg = false);
};
#endif // GLCM_H