http://www.cnblogs.com/skyseraph/archive/2011/08/27/2155776.html
【圖像算法】圖像特征:GLCM
SkySeraph Aug 27th 2011 HQU
Email:[email protected] 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特征:
-------------------------------------------------------------------------------------------------------------------------------
三 源碼
類頭文件:
View Code // FeatureDetect.h: interface for the FeatureDetect class. // /////////////////////////////////////////////////////////////////////////////////////// /* Author: skyseraph/zhaobo 2011/4 [email protected] */ /////////////////////////////////////////////////////////////////////////////////////// #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; };
View Code ////////////////////////////////////////////////////////////////////// // 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; } }
View Code 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:計算共生矩陣
View Code 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; } }
View Code 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; }
View Code 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實現》等書,此類為本文作者原創,可直接調用,轉載/引用請注明出處。
-------------------------------------------------------------------------------------------------------------------------------