// DLMSimilarity.C # include "nsl_include.h" # include "DLMwin.h" # include "DLMSimilarity.h" # include "DLM.h" int maxGallerySize = -1; // actual maximal simulated gallery size ; // in order to avoid multiple mem allocation ; #ifdef NSL_PC static const double PI = 3.14159; static const double M_PI = 1.0/PI; #endif DLMSimilarity::DLMSimilarity(nsl_string str,NslModule* parent) : NslModule(str,parent), // S21("S21",this), showS21("showS21",this), ObjectSelectionMode("ObjectSelectionMode",this), preferredObject("preferredObject",this), alpha_S("alpha_S",this) { nsl_string _str; for (int i=0; i statement above. */ float DLMSimilarity::similarity(float *trafoData1, float *trafoData2) { int kLevel, kIndex, kIndex2; float k0x, k0y, deltaPhase; float dispX=0, dispY=0, confidence, meanError=0; float PhiX=0, PhiY=0, GammaXX=0, GammaXY=0, GammaYY=0; for (kLevel=kLevels-1; kLevel>=0; kLevel--) { for (kIndex=kLevel*kDirections; kIndex<(kLevel+1)*kDirections; kIndex++) { kIndex2 = kIndex*2; confidence = trafoData1[kIndex2]*trafoData2[kIndex2]; confidenceBak[kIndex] = confidence; if (confidence!=0) { k0x = kxArr[kIndex]; k0y = kyArr[kIndex]; deltaPhase = (trafoData1[kIndex2+1]-trafoData2[kIndex2+1]); while (deltaPhase< dispX*k0x+dispY*k0y-M_PI) { deltaPhase += 2*M_PI; } while (deltaPhase>=dispX*k0x+dispY*k0y+M_PI) { deltaPhase -= 2*M_PI; } deltaPhaseBak[kIndex] = deltaPhase; PhiX += confidence*k0x*deltaPhase; PhiY += confidence*k0y*deltaPhase; GammaXX += confidence*k0x*k0x; GammaXY += confidence*k0x*k0y; GammaYY += confidence*k0y*k0y; } } dispX = (+PhiX*GammaYY-PhiY*GammaXY)/(GammaXX*GammaYY-GammaXY*GammaXY); dispY = (-PhiX*GammaXY+PhiY*GammaXX)/(GammaXX*GammaYY-GammaXY*GammaXY); } for (kIndex=0; kIndex> DLMObjectPath >> objects; // ---- check whether the preferred object index is valid ; if ((preferredObject.elem()<=0)||(preferredObject.elem()>objects)) { cout <<"\nWARNING : preferredObject (" << preferredObject.elem() <<") out of range (1-" <objects)) { cerr << "\nERROR: selected object (" << selectedObject << ") out of range [1,...," << objects <<"] !\n"; exit(1); } // ---- read object name ; for (object=0; object> DLMObjectName >> Oi1offset >> Oj1offset; if (!DLMObjects.good()) { cerr <<"\nERROR : Could not read DLMObjectName, Oi1offset, and Oj1offset from DLMObjects !!\n"; exit(1); } DLMObjects.close(); cout << "\n Object :\n " << DLMObjectName; // ---- check whether the object name has changed since the last init ; if (strcmp(DLMObjectName,objectName)!=0) { for (model=0; model<=gallerySize.elem(); model++) strcpy(modelName[model],"nobody"); strcpy(objectName,DLMObjectName); }; // ---- open object graph file and read basic parameters ; sprintf(tmpStr,"%s%s",DLMObjectPath,objectName); DLMGraph.open(tmpStr,ios::in); if (!DLMGraph.good()) { cerr << "\nERROR : Cannot open file "<> floatDummy >> floatDummy>> Sj1max >> floatDummy >> floatDummy>> Si1max; // ---- determine offsets ; Si1offset = Oi1offset - (i1max-2*frame-10)/2; if (Si1offset<0) Si1offset = 0; if (Si1offset>Si1max-i1max+2*frame) Si1offset=Si1max-i1max+2*frame; if (Si1offset<0) { cerr <<"\nERROR : object graph has less columns ("<Sj1max-j1max+2*frame) Sj1offset=Sj1max-j1max+2*frame; if (Sj1offset<0) { cerr <<"\nERROR : object graph has less rows ("<> kLevelsTmp >> kDirectionsTmp >> kMaximumTmp >> kFactorTmp >> sigmaTmp; if (kLevels!=kLevelsTmp) cerr << "\nERROR: kLevels (" << kLevelsTmp << ") in object graph != " << kLevels <<" !!\n"; if (kDirections!=kDirectionsTmp) cerr << "\nERROR: kDirections (" << kDirectionsTmp << ") in object graph != " << kDirections <<" !!\n"; if (kMaximum!=kMaximumTmp) cerr << "\nERROR: kMaximum (" << kMaximumTmp << ") in object graph != " << kMaximum <<" !!\n"; if (kFactor!=kFactorTmp) cerr << "\nERROR: kFactor (" << kFactorTmp << ") in object graph != " << kFactor <<" !!\n"; if (sigma!=sigmaTmp) cerr << "\nERROR: sigma (" << sigmaTmp << ") in object graph != " << sigma <<" !!\n"; // ---- read in jets of object graph ; // float *DLMGImage = new float[i1max*j1max*kLevels*kDirections*2]; NslFloat1 DLMGImage(i1max*j1max*kLevels*kDirections*2); float ImageNormFloat; // float ImageNormChar[i1max*j1max]; // float* ImageNormChar = new float[i1max*j1max]; NslFloat2 ImageNormChar(i1max,j1max); for (Sj1=0, j1=-Sj1offset+frame; Sj1=0; Si1--, i1--) { // ij1 = ij1Index(i1,j1,j1max); // check whether the node belongs to the selected subgraph ; char tmpChar=' '; if ((i1=i1max-frame)||(j1=j1max-frame)) { DLMGraph >> Norm >> Norm; tmpChar=' '; while (tmpChar!='\n') DLMGraph.get(tmpChar); for (k=0; k> ImageNormFloat >> ImageNormChar[i1][j1]; normCharFactor = 1/ImageNormChar[i1][j1]; tmpChar=' '; while (tmpChar!='\n') DLMGraph.get(tmpChar); for (k=0; k=0; Si1--) ; DLMGraph.close(); // ---- read in models and compute similarity matrices ----------------- ; // ---- variables ; int modelInGal; // float *DLMGModel = new float[i1max*j1max*kLevels*kDirections*2]; NslFloat1 DLMGModel(i1max*j1max*kLevels*kDirections*2); // float ModelNormFloat[i2max][j2max]; // float ModelNormChar[i2max][j2max]; // float* ModelNormFloat = new float[i2max*j2max]; // float* ModelNormChar = new float[i2max*j2max]; NslFloat2 ModelNormFloat(i2max,j2max); NslFloat2 ModelNormChar(i2max,j2max); // ---- open file of model names and read basic parameters ; ifstream DLMModels; DLMModels.open(modelsFileName,ios::in); if (!DLMModels.good()) { cerr << "\nERROR: Cannot open file "<> DLMModelPath >> models; // ---- check whether enough models are in DLMModels ; if (models> DLMModelName; if (strncmp(DLMModelName,objectName,strlen(objectName)-1)==0) break; }; if (modelInGal>models) cerr <<"\nERROR : person "<< objectName <<" not in DLMModels !!\n"; // ---- model loop ; cout << "\n\n Gallery : "; for (model=1; model<=gallerySize.elem(); model++) { // ---- read name of next model ; if (model!=1) { modelInGal++; if (modelInGal>models) { DLMModels.close(); DLMModels.open(modelsFileName,ios::in); if (!DLMModels.good()) { cerr << "\nERROR: Cannot open file "<> dummyString >> dummyInt; modelInGal=1; }; DLMModels >> DLMModelName; }; cout <<"\n "<> floatDummy>> floatDummy >> Sj2max >> floatDummy>> floatDummy >> Si2max; // ---- determine offsets ; Si2offset = (Si2max-i2max)/2; if (Si2offset<0) cerr <<"\nERROR : model graph has less columns ("<> kLevelsTmp >> kDirectionsTmp >> kMaximumTmp >> kFactorTmp >> sigmaTmp; if (kLevels!=kLevelsTmp) cerr << "\nERROR: kLevels (" << kLevelsTmp << ") in model graph != " << kLevels <<" !!\n"; if (kDirections!=kDirectionsTmp) cerr << "\nERROR: kDirections (" << kDirectionsTmp << ") in model graph != " << kDirections <<" !!\n"; if (kMaximum!=kMaximumTmp) cerr << "\nERROR: kMaximum (" << kMaximumTmp << ") in model graph != " << kMaximum <<" !!\n"; if (kFactor!=kFactorTmp) cerr << "\nERROR: kFactor (" << kFactorTmp << ") in model graph != " << kFactor <<" !!\n"; if (sigma!=sigmaTmp) cerr << "\nERROR: sigma (" << sigmaTmp << ") in model graph != " << sigma <<" !!\n"; // ---- read jets of model graph ; for (Sj2=0, j2=-Sj2offset; Sj2=0; Si2--, i2--) { // ij2 = ij2Index(i2,j2,j2max); // check whether the node belongs to the selected subgraph ; char tmpChar; if ((i2<0)||(i2>=i2max)||(j2<0)||(j2>=j2max)) { DLMGraph >> Norm >> Norm; tmpChar=' '; while (tmpChar!='\n') DLMGraph.get(tmpChar); for (k=0; k> ModelNormFloat[i2][j2] >> ModelNormChar[i2][j2]; normCharFactor = 1/ModelNormChar[i2][j2]; tmpChar=' '; while (tmpChar!='\n') DLMGraph.get(tmpChar); for (k=0; k=0; Si2--) ; DLMGraph.close(); // ---- compute similarity matrix ; for (i2=0; i20) showS21 = S21[int(showLayer.elem())]; // ---- free memory ; // delete[] DLMGModel; // delete[] DLMGImage; // ---- close file of model names ; DLMModels.close(); // S21.send(); } void DLMSimilarity::initRunTemp(NslFloat0& gallerySize) { if (gallerySize.elem()>0) { float S; if (gallerySize.elem()>0) for (int i2=0; i2