www.pudn.com > MyImageDB(imageobject).rar > MyColorFeature.cpp
// MyColorFeature.cpp: implementation of the MyColorFeature class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "myimagedb.h" #include "MyColorFeature.h" #include "mycolorspace.h" #include#ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// MyColorFeature::MyColorFeature() { } MyColorFeature::~MyColorFeature() { } D1ColorBin* MyColorFeature::CalcuHisD1(BYTE* rgbData, INT width, INT height) //计算一维直方图,来自RemoteDemo; //输入参数无需预分配内存; { unsigned long imglen = width*height; MyHSV* myhsvbuf = new MyHSV[imglen]; HsvBelongTo* imgd1data = new HsvBelongTo[imglen]; int i,j; unsigned long pos; myColorSpace.RgbtoHsv(rgbData, width, height, myhsvbuf); for(i=0;i 0.1 ); for (k=0; k bincount = CBDIM; toreturn->binunits = newcolorbook; return toreturn; } DOUBLE MyColorFeature::GetHisD1Distance(D1ColorBin* myhisd1, D1ColorBin* myhisd2) //计算直方图距离; { //来自RemoteDemo; DOUBLE hisd1dis = 0; DOUBLE test1 = 0; DOUBLE test2 = 0; INT count = myhisd1->bincount; INT i; //测试直方图; for (i=0; i binunits[i].count; test2 += myhisd2->binunits[i].count; } if (fabs(test1)>1.000001 || fabs(test2)>1.000001) { MessageBox(NULL,"","直方图数据有误",MB_OK); } //计算距离 for( i=0; i binunits[i].count - myhisd2->binunits[i].count; hisd1dis += pow(sum, 2.0); } hisd1dis = sqrt(hisd1dis); hisd1dis = hisd1dis / sqrt(2.0); return hisd1dis; }