标签:
【图像算法】图像特征:GLCM
SkySeraph Aug 27th 2011 HQU
Email:zgzhaobo@gmail.com QQ:452728574
Latest Modified Date:Aug 27th 2011 HQU
-------------------------------------------------------------------------------------------------------------------------------
一 原理
1 概念:GLCM,即灰度共生矩阵,GLCM是一个L*L方阵,L为源图像的灰度级
2 含义:描述的是具有某种空间位置关系的两个像素的联合分布,可看成两个像素灰度对的联合直方图,是一种二阶统计
3 常用的空间位置关系:有四种,垂直、水平、正负45°
4 常用的GLCM特征特征:
(1)能量: 是灰度共生矩阵元素值的平方和,所以也称能量,反映了图像灰度分布均匀程度和纹理粗细度。
如果共生矩阵的所有值均相等,则ASM值小;相反,如果其中一些值大而其它值小,则ASM值大。
当共生矩阵中元素集中分布时,此时ASM值大。ASM值大表明一种较均一和规则变化的纹理模式。
(2)对比度:反映了图像的清晰度和纹理沟纹深浅的程度。纹理沟纹越深,其对比度越大,视觉效果越清晰;
反之,对比度小,则沟纹浅,效果模糊。灰度差即对比度大的象素对越多,这个值越大。
灰度公生矩阵中远离对角线的元素值越大,CON越大。
(3)相关: 它度量空间灰度共生矩阵元素在行或列方向上的相似程度,因此,相关值大小反映了图像中局部灰度相关性。
当矩阵元素值均匀相等时,相关值就大;相反,如果矩阵像元值相差很大则相关值小。如果图像中有水平方向纹理,
则水平方向矩阵的COR大于其余矩阵的COR值。
(4)熵: 是图像所具有的信息量的度量,纹理信息也属于图像的信息,是一个随机性的度量,当共生矩阵中所有元素有最大的随机性、
空间共生矩阵中所有值几乎相等时,共生矩阵中元素分散分布时,熵较大。它表示了图像中纹理的非均匀程度或复杂程度。
(5)逆差距:反映图像纹理的同质性,度量图像纹理局部变化的多少。其值大则说明图像纹理的不同区域间缺少变化,局部非常均匀。
5 原理理解:
假设衣服图像的纹理矩阵P如下:
P = [ 0 1 2 0 1 2
1 2 0 1 2 0
2 0 1 2 0 1
0 1 2 0 1 2
1 2 0 1 2 0
2 0 1 2 0 1
]
①相距为1(第一个参数),位置方向为0°第二个参数)的GLCM矩阵如下:
[ 0 10 10
10 0 10
10 10 0
]
//解析:因为P中灰度级为3,故GLCM为3*3方阵
②相距为1(第一个参数),位置方向为正负45°第二个参数)的GLCM矩阵如下:
[ 16 0 0
0 16 0
0 0 18
]
-------------------------------------------------------------------------------------------------------------------------------
二 结果
图像(lenna):
另附:关于lenna,风靡图像界这张图像,源原轶事:http://www.cs.cmu.edu/~chuck/lennapg/ ^_^
单个 GLCM以及4个方向的均值、方差GLCM特征:
-------------------------------------------------------------------------------------------------------------------------------
三 源码
类头文件:
// FeatureDetect.h: interface for the FeatureDetect class. // /////////////////////////////////////////////////////////////////////////////////////// /* Author: skyseraph/zhaobo 2011/4 zgzhaobo@gmal.com */ /////////////////////////////////////////////////////////////////////////////////////// #include <math.h> #include "windows.h" #include "iostream" usingnamespace std; typedef struct glcmFeature { double dCorrelation; double dEnergy; double dEntropy; double dInertiaQuadrature; double dLocalCalm; }glcmFeature; typedef struct glcmFeatureVar { double dAveCorrelation; double dAveEnergy; double dAveEntropy; double dAveInertiaQuadrature; double dAveLocalCalm; double dVarCorrelation; double dVarEnergy; double dVarEntropy; double dVarInertiaQuadrature; double dVarLocalCalm; }glcmFeatureVar; class ZBGLCM { public: ZBGLCM(); ~ZBGLCM(); void ComputeMatrix(BYTE **LocalImage, int LocalImageWidth); void ComputeFeature(double&FeatureEnergy, double&FeatureEntropy, double&FeatureInertiaQuadrature, double&FeatureCorrelation, double&FeatureLocalCalm, int** pMatrix, int dim); glcmFeature pGLCMF; glcmFeatureVar pGLCMFVar; glcmFeature GLCMFeature(BYTE* ImageArray,long ImageWidth,long ImageHeight,int FilterWindowWidth,int dir); glcmFeatureVar GLCMFeatureVar(BYTE* ImageArray,long ImageWidth,long ImageHeight,int FilterWindowWidth); public: double FeatureLocalCalmRD; double FeatureLocalCalmLD; double FeatureLocalCalmV; double FeatureLocalCalmH; double FeatureCorrelationRD; double FeatureCorrelationLD; double FeatureCorrelationV; double FeatureCorrelationH; double FeatureInertiaQuadratureRD; double FeatureInertiaQuadratureLD; double FeatureInertiaQuadratureV; double FeatureInertiaQuadratureH; double FeatureEntropyRD; double FeatureEntropyLD; double FeatureEntropyV; double FeatureEntropyH; double FeatureEnergyRD; double FeatureEnergyLD; double FeatureEnergyV; double FeatureEnergyH; int FilterWindowWidth; int distance; int GrayLayerNum; int L; int** PMatrixRD; int** PMatrixLD; int** PMatrixV; int** PMatrixH; };
类源文件-1:初始化和资源释放
////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// ZBGLCM::ZBGLCM() { PMatrixRD = NULL; PMatrixLD = NULL; PMatrixV = NULL; PMatrixH = NULL; distance =5; FilterWindowWidth =16; GrayLayerNum =8; L=8; int i; PMatrixH =newint*[GrayLayerNum]; PMatrixLD=newint*[GrayLayerNum]; PMatrixRD=newint*[GrayLayerNum]; PMatrixV =newint*[GrayLayerNum]; for(i=0; i<GrayLayerNum; i++) { PMatrixH[i] =newint[GrayLayerNum]; PMatrixLD[i]=newint[GrayLayerNum]; PMatrixRD[i]=newint[GrayLayerNum]; PMatrixV[i] =newint[GrayLayerNum]; } } ZBGLCM::~ZBGLCM() { if(PMatrixH !=NULL) { for(int i=0; i<GrayLayerNum; i++) { delete [] PMatrixH[i]; PMatrixH[i] = NULL; //已析构了,后不再加 } delete [] PMatrixH; PMatrixH = NULL; } if(PMatrixLD !=NULL) { for(int i=0; i<GrayLayerNum; i++) { delete[] PMatrixLD[i]; } delete [] PMatrixLD; } if(PMatrixRD !=NULL) { for(int i=0; i<GrayLayerNum; i++) delete [] PMatrixRD[i]; delete [] PMatrixRD; } if(PMatrixV !=NULL) { for(int i=0; i<GrayLayerNum; i++) delete [] PMatrixV[i]; delete [] PMatrixV; } }
类源文件-2:计算纹理特征
void ZBGLCM::ComputeFeature(double&FeatureEnergy, double&FeatureEntropy, double&FeatureInertiaQuadrature, double&FeatureCorrelation, double&FeatureLocalCalm, int** pMatrix, int dim) { int i,j; double**pdMatrix; pdMatrix =newdouble*[dim]; for(i=0; i<dim; i++) pdMatrix[i] =newdouble[dim]; int total =0; for(i=0; i<dim; i++) { for(j=0; j<dim; j++) { total += pMatrix[i][j]; } } for(i=0; i<dim; i++) { for(j=0; j<dim; j++) { pdMatrix[i][j] = (double)pMatrix[i][j]/(double)total; } } FeatureEnergy =0.0; FeatureEntropy =0.0; FeatureInertiaQuadrature =0.0; FeatureLocalCalm =0.0; for(i=0; i<dim; i++) { for(j=0; j<dim; j++) { FeatureEnergy += pdMatrix[i][j]*pdMatrix[i][j]; if(pdMatrix[i][j]>1e-12) { FeatureEntropy -= pdMatrix[i][j]*log(pdMatrix[i][j]); } FeatureInertiaQuadrature += (double)(i-j)*(double)(i-j)*pdMatrix[i][j]; FeatureLocalCalm += pdMatrix[i][j]/(1+(double)(i-j)*(double)(i-j)); } } double ux =0.0; double localtotal =0.0; for(i=0; i<dim; i++) { localtotal =0.0; for(j=0; j<dim; j++) { localtotal += pdMatrix[i][j]; } ux += (double)i * localtotal; } double uy =0.0; for(j=0; j<dim; j++) { localtotal =0.0; for(i=0; i<dim; i++) { localtotal += pdMatrix[i][j]; } uy += (double)j * localtotal; } double sigmax =0.0; for(i=0; i<dim; i++) { localtotal =0.0; for(j=0; j<dim; j++) { localtotal += pdMatrix[i][j]; } sigmax += (double)(i-ux) * (double)(i-ux) * localtotal; } double sigmay =0.0; for(j=0; j<dim; j++) { localtotal =0.0; for(i=0; i<dim; i++) { localtotal += pdMatrix[i][j]; } sigmay += (double)(j-uy) * (double)(j-uy) * localtotal; } FeatureCorrelation =0.0; for(i=0; i<dim; i++) { for(j=0; j<dim; j++) { FeatureCorrelation += (double)(i-ux) * (double)(j-uy) * pdMatrix[i][j]; } } if(sigmax !=0&& sigmay !=0) { FeatureCorrelation /= sigmax; FeatureCorrelation /= sigmay; } else FeatureCorrelation =8; if(pdMatrix !=NULL) { for(i=0; i<dim; i++) { delete [] pdMatrix[i]; pdMatrix[i] = NULL; } delete [] pdMatrix; pdMatrix = NULL; } }
类源文件-3:计算共生矩阵
void ZBGLCM::ComputeMatrix(BYTE **LocalImage, int LocalImageWidth) { int i,j; BYTE **NewImage; NewImage =new BYTE*[LocalImageWidth]; if(NewImage==NULL) return; for(i=0; i<LocalImageWidth; i++) { NewImage[i] =new BYTE[LocalImageWidth]; if(NewImage[i]==NULL) return; } for(i=0; i<LocalImageWidth; i++) { for(j=0; j<LocalImageWidth; j++) { NewImage[i][j] = LocalImage[i][j] / (256/GrayLayerNum); } } for(i=0; i<GrayLayerNum; i++) { for(j=0; j<GrayLayerNum; j++) { PMatrixH[i][j] =0; PMatrixLD[i][j] =0; PMatrixRD[i][j] =0; PMatrixV[i][j] =0; } } for(i=0; i<LocalImageWidth; i++) { for(j=0; j<LocalImageWidth-distance; j++) { PMatrixH[(unsigned int)NewImage[i][j]][(unsigned int)NewImage[i][j+distance]] +=1; PMatrixH[(unsigned int)NewImage[i][j+distance]][(unsigned int)NewImage[i][j]] +=1; } } for(i=0; i<LocalImageWidth-distance; i++) { for(j=0; j<LocalImageWidth; j++) { PMatrixV[(unsigned int)NewImage[i][j]][(unsigned int)NewImage[i+distance][j]] +=1; PMatrixV[(unsigned int)NewImage[i+distance][j]][(unsigned int)NewImage[i][j]] +=1; } } for(i=0; i<LocalImageWidth-distance; i++) { for(j=0; j<LocalImageWidth-distance; j++) { int newi, newj; newi = i+distance; newj = j+distance; PMatrixLD[(unsigned int)NewImage[i][j]][(unsigned int)NewImage[newi][newj]] +=1; PMatrixLD[(unsigned int)NewImage[newi][newj]][(unsigned int)NewImage[i][j]] +=1; } } for(i=distance; i<LocalImageWidth; i++) { for(j=0; j<LocalImageWidth-distance; j++) { int newi, newj; newi = i-distance; newj = j+distance; PMatrixRD[(unsigned int)NewImage[i][j]][(unsigned int)NewImage[newi][newj]] +=1; PMatrixRD[(unsigned int)NewImage[newi][newj]][(unsigned int)NewImage[i][j]] +=1; } } if(NewImage !=NULL) { for(i=0; i<LocalImageWidth; i++) { delete [] NewImage[i]; NewImage[i] = NULL; } delete [] NewImage; NewImage = NULL; } }
类源文件-4:计算GLCM特征
glcmFeature ZBGLCM::GLCMFeature(BYTE* ImageArray,long ImageWidth,long ImageHeight,int FilterWindowWidth,int dir) { assert(ImageHeight>FilterWindowWidth && ImageWidth > FilterWindowWidth); double dEnergy =0.0; double dEntropy =0.0; double dInertiaQuadrature =0.0; double dLocalCalm =0.0; double dCorrelation =0.0; double dEnergy1 =0.0; double dEntropy1 =0.0; double dInertiaQuadrature1=0.0; double dLocalCalm1 =0.0; double dCorrelation1 =0.0; int rolltimeH = ImageHeight/FilterWindowWidth; int rolltimeW = ImageWidth /FilterWindowWidth; int i,j; int p,q; unsigned char** arLocalImage; arLocalImage=(unsigned char**)calloc((unsigned)FilterWindowWidth,sizeof(unsigned char*)); for( i=0;i<FilterWindowWidth;i++) { arLocalImage[i]=(unsigned char*)calloc((unsigned)FilterWindowWidth,sizeof(unsigned char)); } for(i=0; i< rolltimeH; i++) { for(j=0; j<rolltimeW; j++) { for(p=0; p<FilterWindowWidth; p++) { for(q=0; q<FilterWindowWidth; q++) { arLocalImage[p][q] =*((char*)ImageArray+(ImageHeight-1-(i*FilterWindowWidth+p))*ImageWidth+j*FilterWindowWidth+q); } } ComputeMatrix(arLocalImage, FilterWindowWidth); switch (dir) { case0: ComputeFeature(dEnergy1, dEntropy1, dInertiaQuadrature1, dCorrelation1, dLocalCalm1, PMatrixH, GrayLayerNum); break; case1: ComputeFeature(dEnergy1, dEntropy1, dInertiaQuadrature1, dCorrelation1, dLocalCalm1, PMatrixRD, GrayLayerNum); break; case2: ComputeFeature(dEnergy1, dEntropy1, dInertiaQuadrature1, dCorrelation1, dLocalCalm1, PMatrixV, GrayLayerNum); break; case3: ComputeFeature(dEnergy1, dEntropy1, dInertiaQuadrature1, dCorrelation1, dLocalCalm1, PMatrixLD, GrayLayerNum); break; default: ComputeFeature(dEnergy1, dEntropy1, dInertiaQuadrature1, dCorrelation1, dLocalCalm1, PMatrixH, GrayLayerNum); break; } dEnergy += dEnergy1; dEntropy += dEntropy1; dInertiaQuadrature += dInertiaQuadrature1; dCorrelation += dCorrelation1; dLocalCalm += dLocalCalm1; } } dEnergy /= (rolltimeH*rolltimeW); dEntropy /= (rolltimeH*rolltimeW); dInertiaQuadrature /= (rolltimeH*rolltimeW); dCorrelation /= (rolltimeH*rolltimeW); dLocalCalm /= (rolltimeH*rolltimeW); pGLCMF.dEnergy = dEnergy ; pGLCMF.dEntropy = dEntropy; pGLCMF.dInertiaQuadrature = dInertiaQuadrature; pGLCMF.dCorrelation = dCorrelation; pGLCMF.dLocalCalm = dLocalCalm; for(i=0; i<FilterWindowWidth; i++) { free(arLocalImage[i]) ; arLocalImage[i] = NULL; } free(arLocalImage); arLocalImage = NULL; return pGLCMF; }
类源文件-5:计算GLCM特征均值和方差
glcmFeatureVar ZBGLCM::GLCMFeatureVar(BYTE* ImageArray,long ImageWidth,long ImageHeight,int FilterWindowWidth) { assert(ImageHeight>FilterWindowWidth && ImageWidth > FilterWindowWidth); double dEnergy =0.0; double dEntropy =0.0; double dInertiaQuadrature =0.0; double dLocalCalm =0.0; double dCorrelation =0.0; double dEnergy1 =0.0; double dEntropy1 =0.0; double dInertiaQuadrature1=0.0; double dLocalCalm1 =0.0; double dCorrelation1 =0.0; double dEnergy2 =0.0; double dEntropy2 =0.0; double dInertiaQuadrature2=0.0; double dLocalCalm2 =0.0; double dCorrelation2 =0.0; double dEnergy3 =0.0; double dEntropy3 =0.0; double dInertiaQuadrature3=0.0; double dLocalCalm3 =0.0; double dCorrelation3 =0.0; double dEnergy4 =0.0; double dEntropy4 =0.0; double dInertiaQuadrature4=0.0; double dLocalCalm4 =0.0; double dCorrelation4 =0.0; double dEnergy11 =0.0; double dEntropy11 =0.0; double dInertiaQuadrature11=0.0; double dLocalCalm11 =0.0; double dCorrelation11 =0.0; double dEnergy22 =0.0; double dEntropy22 =0.0; double dInertiaQuadrature22=0.0; double dLocalCalm22 =0.0; double dCorrelation22 =0.0; double dEnergy33 =0.0; double dEntropy33 =0.0; double dInertiaQuadrature33=0.0; double dLocalCalm33 =0.0; double dCorrelation33 =0.0; double dEnergy44 =0.0; double dEntropy44 =0.0; double dInertiaQuadrature44=0.0; double dLocalCalm44 =0.0; double dCorrelation44 =0.0; int rolltimeH = ImageHeight/FilterWindowWidth; int rolltimeW = ImageWidth /FilterWindowWidth; int i,j; int p,q; unsigned char** arLocalImage; arLocalImage=(unsigned char**)calloc((unsigned)FilterWindowWidth,sizeof(unsigned char*)); for( i=0;i<FilterWindowWidth;i++) { arLocalImage[i]=(unsigned char*)calloc((unsigned)FilterWindowWidth,sizeof(unsigned char)); } for(i=0; i< rolltimeH; i++) { for(j=0; j<rolltimeW; j++) { for(p=0; p<FilterWindowWidth; p++) { for(q=0; q<FilterWindowWidth; q++) { arLocalImage[p][q] =*((char*)ImageArray+(ImageHeight-1-(i*FilterWindowWidth+p))*ImageWidth+j*FilterWindowWidth+q); } } ComputeMatrix(arLocalImage, FilterWindowWidth); ComputeFeature(dEnergy1, dEntropy1, dInertiaQuadrature1, dCorrelation1, dLocalCalm1, PMatrixH, GrayLayerNum); dEnergy += dEnergy1; dEntropy += dEntropy1; dInertiaQuadrature += dInertiaQuadrature1; dCorrelation += dCorrelation1; dLocalCalm += dLocalCalm1; dEnergy11 += dEnergy1; dEntropy11 += dEntropy1; dInertiaQuadrature11 += dInertiaQuadrature1; dCorrelation11 += dCorrelation1; dLocalCalm11 += dLocalCalm1; ComputeMatrix(arLocalImage, FilterWindowWidth); ComputeFeature(dEnergy2, dEntropy2, dInertiaQuadrature2, dCorrelation2, dLocalCalm2, PMatrixRD, GrayLayerNum); dEnergy += dEnergy2; dEntropy += dEntropy2; dInertiaQuadrature += dInertiaQuadrature2; dCorrelation += dCorrelation2; dLocalCalm += dLocalCalm2; dEnergy22 += dEnergy2; dEntropy22 += dEntropy2; dInertiaQuadrature22 += dInertiaQuadrature2; dCorrelation22 += dCorrelation2; dLocalCalm22 += dLocalCalm2; ComputeMatrix(arLocalImage, FilterWindowWidth); ComputeFeature(dEnergy3, dEntropy3, dInertiaQuadrature3, dCorrelation3, dLocalCalm3, PMatrixV, GrayLayerNum); dEnergy += dEnergy3; dEntropy += dEntropy3; dInertiaQuadrature += dInertiaQuadrature3; dCorrelation += dCorrelation3; dLocalCalm += dLocalCalm3; dEnergy33 += dEnergy3; dEntropy33 += dEntropy3; dInertiaQuadrature33 += dInertiaQuadrature3; dCorrelation33 += dCorrelation3; dLocalCalm33 += dLocalCalm3; ComputeMatrix(arLocalImage, FilterWindowWidth); ComputeFeature(dEnergy4, dEntropy4, dInertiaQuadrature4, dCorrelation4, dLocalCalm4, PMatrixLD, GrayLayerNum); dEnergy += dEnergy4; dEntropy += dEntropy4; dInertiaQuadrature += dInertiaQuadrature4; dCorrelation += dCorrelation4; dLocalCalm += dLocalCalm4; dEnergy44 += dEnergy4; dEntropy44 += dEntropy4; dInertiaQuadrature44 += dInertiaQuadrature4; dCorrelation44 += dCorrelation4; dLocalCalm44 += dLocalCalm4; } } dEnergy /= (rolltimeH*rolltimeW); dEntropy /= (rolltimeH*rolltimeW); dInertiaQuadrature /= (rolltimeH*rolltimeW); dCorrelation /= (rolltimeH*rolltimeW); dLocalCalm /= (rolltimeH*rolltimeW); dEnergy11 /= (rolltimeH*rolltimeW); dEntropy11 /= (rolltimeH*rolltimeW); dInertiaQuadrature11 /= (rolltimeH*rolltimeW); dCorrelation11 /= (rolltimeH*rolltimeW); dLocalCalm11 /= (rolltimeH*rolltimeW); dEnergy22 /= (rolltimeH*rolltimeW); dEntropy22 /= (rolltimeH*rolltimeW); dInertiaQuadrature22 /= (rolltimeH*rolltimeW); dCorrelation22 /= (rolltimeH*rolltimeW); dLocalCalm22 /= (rolltimeH*rolltimeW); dEnergy33 /= (rolltimeH*rolltimeW); dEntropy33 /= (rolltimeH*rolltimeW); dInertiaQuadrature33 /= (rolltimeH*rolltimeW); dCorrelation33 /= (rolltimeH*rolltimeW); dLocalCalm33 /= (rolltimeH*rolltimeW); dEnergy44 /= (rolltimeH*rolltimeW); dEntropy44 /= (rolltimeH*rolltimeW); dInertiaQuadrature44 /= (rolltimeH*rolltimeW); dCorrelation44 /= (rolltimeH*rolltimeW); dLocalCalm44 /= (rolltimeH*rolltimeW); pGLCMFVar.dAveEnergy = dEnergy/4 ; pGLCMFVar.dAveEntropy = dEntropy/4; pGLCMFVar.dAveInertiaQuadrature = dInertiaQuadrature/4; pGLCMFVar.dAveCorrelation = dCorrelation/4; pGLCMFVar.dAveLocalCalm = dLocalCalm/4; pGLCMFVar.dVarEnergy=((dEnergy11-pGLCMFVar.dAveEnergy)*(dEnergy11-pGLCMFVar.dAveEnergy) +(dEnergy22-pGLCMFVar.dAveEnergy)*(dEnergy22-pGLCMFVar.dAveEnergy) +(dEnergy33-pGLCMFVar.dAveEnergy)*(dEnergy33-pGLCMFVar.dAveEnergy) +(dEnergy44-pGLCMFVar.dAveEnergy)*(dEnergy44-pGLCMFVar.dAveEnergy))/4; pGLCMFVar.dVarEntropy=((dEntropy11-pGLCMFVar.dAveEntropy)*(dEntropy11-pGLCMFVar.dAveEntropy) +(dEntropy22-pGLCMFVar.dAveEntropy)*(dEntropy22-pGLCMFVar.dAveEntropy) +(dEntropy33-pGLCMFVar.dAveEntropy)*(dEntropy33-pGLCMFVar.dAveEntropy) +(dEntropy44-pGLCMFVar.dAveEntropy)*(dEntropy44-pGLCMFVar.dAveEntropy))/4; pGLCMFVar.dVarInertiaQuadrature=((dInertiaQuadrature11-pGLCMFVar.dAveInertiaQuadrature)*(dInertiaQuadrature11-pGLCMFVar.dAveInertiaQuadrature) +(dInertiaQuadrature22-pGLCMFVar.dAveInertiaQuadrature)*(dInertiaQuadrature22-pGLCMFVar.dAveInertiaQuadrature) +(dInertiaQuadrature33-pGLCMFVar.dAveInertiaQuadrature)*(dInertiaQuadrature33-pGLCMFVar.dAveInertiaQuadrature) +(dInertiaQuadrature44-pGLCMFVar.dAveInertiaQuadrature)*(dInertiaQuadrature44-pGLCMFVar.dAveInertiaQuadrature))/4; pGLCMFVar.dVarCorrelation=((dCorrelation11-pGLCMFVar.dAveCorrelation)*(dCorrelation11-pGLCMFVar.dAveCorrelation) +(dCorrelation22-pGLCMFVar.dAveCorrelation)*(dCorrelation22-pGLCMFVar.dAveCorrelation) +(dCorrelation33-pGLCMFVar.dAveCorrelation)*(dCorrelation33-pGLCMFVar.dAveCorrelation) +(dCorrelation44-pGLCMFVar.dAveCorrelation)*(dCorrelation44-pGLCMFVar.dAveCorrelation))/4; pGLCMFVar.dVarLocalCalm=((dLocalCalm11-pGLCMFVar.dAveLocalCalm)*(dLocalCalm11-pGLCMFVar.dAveLocalCalm) +(dLocalCalm22-pGLCMFVar.dAveLocalCalm)*(dLocalCalm22-pGLCMFVar.dAveLocalCalm) +(dLocalCalm33-pGLCMFVar.dAveLocalCalm)*(dLocalCalm33-pGLCMFVar.dAveLocalCalm) +(dLocalCalm44-pGLCMFVar.dAveLocalCalm)*(dLocalCalm44-pGLCMFVar.dAveLocalCalm))/4; for(i=0; i<FilterWindowWidth; i++) { free(arLocalImage[i]) ; arLocalImage[i] = NULL; } free(arLocalImage); arLocalImage = NULL; return pGLCMFVar; }
说明:
参考了 《VisualC++数字图像模式识别技术详解》、《数字图像处理与机器视觉-VisualC++与Matlab实现》等书,此类为本文作者原创,可直接调用,转载/引用请注明出处。
-------------------------------------------------------------------------------------------------------------------------------
四 参考资料
提取共生矩阵特征 - wqvbjhc的专栏 - CSDN博客
基于灰度共生矩阵的纹理特征提取 - docin.com豆丁网
一个使用GLCM的例子.(修改了CvTexture的bug)
《VisualC++数字图像模式识别技术详解》
《数字图像处理与机器视觉-VisualC++与Matlab实现》
------------------------------------------------------------------------------------------------------------------------------
Author: SKySeraph
Email/GTalk: zgzhaobo@gmail.com QQ:452728574
From: http://www.cnblogs.com/skyseraph/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
-----------------------------------------------------------------------------------------------------------------------------
标签:
原文地址:http://www.cnblogs.com/GarfieldEr007/p/5459523.html