灰度共生矩阵VC++实现
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//计灰uy double uy = 0.0; for(j=0; j<dim; j++) {
localtotal = 0.0; for(i=0; i<dim; i++) {
localtotal += pdMatrix[i*dim+j]; } uy += (double)j * localtotal; }
//计灰相相 FeatureCorrelation = 0.0; for(i=0; i<dim; i++) {
for(j=0; j<dim; j++)
3
{ FeatureCorrelation += (double)(i-ux) * (double)(j-uy) * pdMatrix[i*dim+j];
CGrayShow::CGrayShow() {
PMatrixRD = NULL; PMatrixLD = NULL; PMatrixV = NULL; PMatrixH = NULL; // ImageArray = NULL;
//45灰度度度度灰灰灰灰灰灰 //135灰度度度度灰灰灰灰灰灰
//90灰度度度度灰灰灰灰灰灰 //0灰度度度度灰灰灰灰灰灰 //原原度原原原原原原
void CGrayShow::ComputeFeature(double &FeatureEnergy, double &FeatureEntropy,
double &FeatureInertiaQuadrature, double &FeatureCorrelation,
double &FeatureLocalCalm, int* pMatrix, int dim)
//m_tOriPixelArray = NULL;//原原原原原原 //m_tResPixelArray = NULL;//参参原原原原
// m_dib = new CDib();
distance = 5;
FilterWindowWidth = 16; GrayLayerNum = 16; //初原初初初8个灰灰个,可可可可 //这这灰灰灰灰这初GrayLayerNum×GrayLayerNum
//计灰sigmay double sigmay = 0.0; for(j=0; j<dim; j++) {
localtotal = 0.0; for(i=0; i<dim; i++) {
localtotal += pdMatrix[i*dim+j]; } sigmay += (double)(j-uy) * (double)(j-uy) * localtotal; }
// void CGrayShow::LoadImage(CString &FilePathName)
// {
//
// }
// {
// int i,j; // //检检检检初检,不初检不不不不不不
// if(m_tOriPixelArray !=NULL)
// {
//
for(i=0; i<ImageHeight; i++)
//
FeatureCorrelation-相相
//
FeatureLocalCalm-局局局局
//
pMatrix-灰灰灰灰
//
dim-灰灰灰灰度共原
///////////////////////////////////////////////////////////////////////////////////
//
m_tOriPixelArray[i][j].rgbReserved = 0;
//
m_tResPixelArray[i][j]=m_tOriPixelArray[i][j];
//
ImageArray[i][j] = (BYTE)(((unsigned int)m_tOriPixelArray[i][j].rgbBlue
//
+(unsigned int)m_tOriPixelArray[i][j].rgbGreen
//
+(unsigned int)m_tOriPixelArray[i][j].rgbRed)/3);
//
count += byteBitCount-3;
//
}
//
count += (4-(ImageWidth*byteBitCount)%4)%4;
// ImageHeight = m_dib->GetHeight();
//
// BYTE *colorTable;
// colorTable = (BYTE *)m_dib->m_pDibBits;
// int byteBitCount = m_dib->GetBiBitCount()/8;
//
// m_tOriPixelArray = new RGBQUAD*[ImageHeight];
//计灰ux 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*dim+j]; } ux += (double)i * localtotal; }
for(j=0; j<ImageWidth; j++)
//
{
//
m_tOriPixelArray[i][j].rgbBlue =colorTable[count++];
//
m_tOriPixelArray[i][j].rgbGreen=colorTable[count++];
//
m_tOriPixelArray[i][j].rgbRed =colorTable[count++];
//计灰sigmax double sigmax = 0.0; for(i=0; i<dim; i++) {
localtotal = 0.0; for(j=0; j<dim; j++) {
localtotal += pdMatrix[i*dim+j]; } sigmax += (double)(i-ux) * (double)(i-ux) * localtotal; }
for(j=0; j<dim; j++) {
pdMatrix[i*dim + j] = (double)pMatrix[i*dim + j]/(double)total; } }
FeatureEnergy = 0.0; FeatureEntropy = 0.0;
2
FeatureInertiaQuadrature = 0.0; FeatureLocalCalm = 0.0;
#include "stdafx.h"
#include "GrayShow.h" #include "math.h"
#ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif
// }
//}
////////////////////////////////////////////////////////////////////////////////////
//函原功功:计灰计计计计
//参原:FeatureEnergy-功能
//
FeatureEntropy-熵
//
FeatureInertiaQuadrature-惯惯灰
// m_tResPixelArray = new RGBQUAD*[ImageHeight];
// ImageArray = new BYTE*[ImageHeight];
// for(int l=0 ; l<ImageHeight; l++)
// {
//
m_tOriPixelArray[l] = new RGBQUAD[ImageWidth];
//
PMatrixV[i] = new int[GrayLayerNum];
// }
}
CGrayShow::~CGrayShow() {
if(PMatrixRD)
delete []PMatrixRD ; if(PMatrixLD)
delete []PMatrixLD ; if(PMatrixV)
delete []PMatrixV ; if(PMatrixH)
//////////////////////////////////////////////////////////////////////
// GrayShow.cpp: implementation of the CGrayShow class. // 灰灰灰灰灰灰灰灰灰灰
//
//////////////////////////////////////////////////////////////////////
//
{
//
delete m_tOriPixelArray[i];
1
//
delete m_tResPixelArray[i];
//
delete ImageArray[i];
//
}
// }
//
// m_dib->Open(FilePathName);
// ImageWidth = m_dib->GetWidth();
////////////////////////////////////////////////////////////////////// // Construction/Destruction //////////////////////////////////////////////////////////////////////
//计灰功能、熵、惯惯灰、局局局局 for(i=0; i<dim; i++) {
for(j=0; j<dim; j++) {
//功能 FeatureEnergy += pdMatrix[i*dim+j]*pdMatrix[i*dim+j];
//熵 if(pdMatrix[i*dim+j]>1e-12) {
delete []PMatrixH; }
//135灰度度度度灰灰灰灰灰灰 //90灰度度度度灰灰灰灰灰灰
//////////////////////////////////////////////////////////////////// //功功:装装原原 //参原:FilePathName-原原图图图图图
{
int i,j;
double *pdMatrix;
pdMatrix = new double[dim*dim];
int total = 0; for(i=0; i<dim; i++) {
for(j=0; j<dim; j++) {
total += pMatrix[i*dim+j]; } }
for(i=0; i<dim; i++) {
FeatureEntropy -= pdMatrix[i*dim+j]*log(pdMatrix[i*dim+j]); }
//惯惯灰 FeatureInertiaQuadrature += (double)(i-j)*(double)(i-j)*pdMatrix[i*dim+j];
//局局局局 FeatureLocalCalm += pdMatrix[i*dim+j]/(1+(double)(i-j)*(double)(i-j)); } }
PMatrixH = new int[GrayLayerNum*GrayLayerNum];
PMatrixLD= new int[GrayLayerNum*GrayLayerNum];
PMatrixRD= new int[GrayLayerNum*GrayLayerNum];
PMatrixV = new int[GrayLayerNum*GrayLayerNum];
// for(i=0; i<GrayLayerNum; i++)
// {
//
PMatrixH[i] = new int[GrayLayerNum];
//
PMatrixLD[i]= new int[GrayLayerNum];
//
PMatrixRD[i]= new int[GrayLayerNum];
//
m_tResPixelArray[l] = new RGBQUAD[ImageWidth];
//
ImageArray[l] = new BYTE[ImageWidth];
// }
//
// int count = 0;
ห้องสมุดไป่ตู้
// for(i=ImageHeight-1; i>=0; i--)
// {
//
localtotal = 0.0; for(i=0; i<dim; i++) {
localtotal += pdMatrix[i*dim+j]; } uy += (double)j * localtotal; }
//计灰相相 FeatureCorrelation = 0.0; for(i=0; i<dim; i++) {
for(j=0; j<dim; j++)
3
{ FeatureCorrelation += (double)(i-ux) * (double)(j-uy) * pdMatrix[i*dim+j];
CGrayShow::CGrayShow() {
PMatrixRD = NULL; PMatrixLD = NULL; PMatrixV = NULL; PMatrixH = NULL; // ImageArray = NULL;
//45灰度度度度灰灰灰灰灰灰 //135灰度度度度灰灰灰灰灰灰
//90灰度度度度灰灰灰灰灰灰 //0灰度度度度灰灰灰灰灰灰 //原原度原原原原原原
void CGrayShow::ComputeFeature(double &FeatureEnergy, double &FeatureEntropy,
double &FeatureInertiaQuadrature, double &FeatureCorrelation,
double &FeatureLocalCalm, int* pMatrix, int dim)
//m_tOriPixelArray = NULL;//原原原原原原 //m_tResPixelArray = NULL;//参参原原原原
// m_dib = new CDib();
distance = 5;
FilterWindowWidth = 16; GrayLayerNum = 16; //初原初初初8个灰灰个,可可可可 //这这灰灰灰灰这初GrayLayerNum×GrayLayerNum
//计灰sigmay double sigmay = 0.0; for(j=0; j<dim; j++) {
localtotal = 0.0; for(i=0; i<dim; i++) {
localtotal += pdMatrix[i*dim+j]; } sigmay += (double)(j-uy) * (double)(j-uy) * localtotal; }
// void CGrayShow::LoadImage(CString &FilePathName)
// {
//
// }
// {
// int i,j; // //检检检检初检,不初检不不不不不不
// if(m_tOriPixelArray !=NULL)
// {
//
for(i=0; i<ImageHeight; i++)
//
FeatureCorrelation-相相
//
FeatureLocalCalm-局局局局
//
pMatrix-灰灰灰灰
//
dim-灰灰灰灰度共原
///////////////////////////////////////////////////////////////////////////////////
//
m_tOriPixelArray[i][j].rgbReserved = 0;
//
m_tResPixelArray[i][j]=m_tOriPixelArray[i][j];
//
ImageArray[i][j] = (BYTE)(((unsigned int)m_tOriPixelArray[i][j].rgbBlue
//
+(unsigned int)m_tOriPixelArray[i][j].rgbGreen
//
+(unsigned int)m_tOriPixelArray[i][j].rgbRed)/3);
//
count += byteBitCount-3;
//
}
//
count += (4-(ImageWidth*byteBitCount)%4)%4;
// ImageHeight = m_dib->GetHeight();
//
// BYTE *colorTable;
// colorTable = (BYTE *)m_dib->m_pDibBits;
// int byteBitCount = m_dib->GetBiBitCount()/8;
//
// m_tOriPixelArray = new RGBQUAD*[ImageHeight];
//计灰ux 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*dim+j]; } ux += (double)i * localtotal; }
for(j=0; j<ImageWidth; j++)
//
{
//
m_tOriPixelArray[i][j].rgbBlue =colorTable[count++];
//
m_tOriPixelArray[i][j].rgbGreen=colorTable[count++];
//
m_tOriPixelArray[i][j].rgbRed =colorTable[count++];
//计灰sigmax double sigmax = 0.0; for(i=0; i<dim; i++) {
localtotal = 0.0; for(j=0; j<dim; j++) {
localtotal += pdMatrix[i*dim+j]; } sigmax += (double)(i-ux) * (double)(i-ux) * localtotal; }
for(j=0; j<dim; j++) {
pdMatrix[i*dim + j] = (double)pMatrix[i*dim + j]/(double)total; } }
FeatureEnergy = 0.0; FeatureEntropy = 0.0;
2
FeatureInertiaQuadrature = 0.0; FeatureLocalCalm = 0.0;
#include "stdafx.h"
#include "GrayShow.h" #include "math.h"
#ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif
// }
//}
////////////////////////////////////////////////////////////////////////////////////
//函原功功:计灰计计计计
//参原:FeatureEnergy-功能
//
FeatureEntropy-熵
//
FeatureInertiaQuadrature-惯惯灰
// m_tResPixelArray = new RGBQUAD*[ImageHeight];
// ImageArray = new BYTE*[ImageHeight];
// for(int l=0 ; l<ImageHeight; l++)
// {
//
m_tOriPixelArray[l] = new RGBQUAD[ImageWidth];
//
PMatrixV[i] = new int[GrayLayerNum];
// }
}
CGrayShow::~CGrayShow() {
if(PMatrixRD)
delete []PMatrixRD ; if(PMatrixLD)
delete []PMatrixLD ; if(PMatrixV)
delete []PMatrixV ; if(PMatrixH)
//////////////////////////////////////////////////////////////////////
// GrayShow.cpp: implementation of the CGrayShow class. // 灰灰灰灰灰灰灰灰灰灰
//
//////////////////////////////////////////////////////////////////////
//
{
//
delete m_tOriPixelArray[i];
1
//
delete m_tResPixelArray[i];
//
delete ImageArray[i];
//
}
// }
//
// m_dib->Open(FilePathName);
// ImageWidth = m_dib->GetWidth();
////////////////////////////////////////////////////////////////////// // Construction/Destruction //////////////////////////////////////////////////////////////////////
//计灰功能、熵、惯惯灰、局局局局 for(i=0; i<dim; i++) {
for(j=0; j<dim; j++) {
//功能 FeatureEnergy += pdMatrix[i*dim+j]*pdMatrix[i*dim+j];
//熵 if(pdMatrix[i*dim+j]>1e-12) {
delete []PMatrixH; }
//135灰度度度度灰灰灰灰灰灰 //90灰度度度度灰灰灰灰灰灰
//////////////////////////////////////////////////////////////////// //功功:装装原原 //参原:FilePathName-原原图图图图图
{
int i,j;
double *pdMatrix;
pdMatrix = new double[dim*dim];
int total = 0; for(i=0; i<dim; i++) {
for(j=0; j<dim; j++) {
total += pMatrix[i*dim+j]; } }
for(i=0; i<dim; i++) {
FeatureEntropy -= pdMatrix[i*dim+j]*log(pdMatrix[i*dim+j]); }
//惯惯灰 FeatureInertiaQuadrature += (double)(i-j)*(double)(i-j)*pdMatrix[i*dim+j];
//局局局局 FeatureLocalCalm += pdMatrix[i*dim+j]/(1+(double)(i-j)*(double)(i-j)); } }
PMatrixH = new int[GrayLayerNum*GrayLayerNum];
PMatrixLD= new int[GrayLayerNum*GrayLayerNum];
PMatrixRD= new int[GrayLayerNum*GrayLayerNum];
PMatrixV = new int[GrayLayerNum*GrayLayerNum];
// for(i=0; i<GrayLayerNum; i++)
// {
//
PMatrixH[i] = new int[GrayLayerNum];
//
PMatrixLD[i]= new int[GrayLayerNum];
//
PMatrixRD[i]= new int[GrayLayerNum];
//
m_tResPixelArray[l] = new RGBQUAD[ImageWidth];
//
ImageArray[l] = new BYTE[ImageWidth];
// }
//
// int count = 0;
ห้องสมุดไป่ตู้
// for(i=ImageHeight-1; i>=0; i--)
// {
//