00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #include "VFAT/featureClusterVision.H"
00050
00051 #include "Image/Conversions.H"
00052 #include "Image/Kernels.H"
00053 #include "Image/MatrixOps.H"
00054 #include "Util/Assert.H"
00055 #include "Util/Timer.H"
00056 #include "VFAT/VFATOpts.H"
00057 #include "VFAT/covEstimate.H"
00058 #include "VFAT/featureClusterFilters.H"
00059
00060 #define OVER 5
00061 #define COVSIZE 605
00062 #define COVHOLDER 10
00063 #define DATABOUND 10000
00064 #define VEC_RESIZE 100
00065 #define FOOANDSTUFF 2
00066 #define DUMPNP false
00067 #define STUPIDMASKOFFSET 133
00068
00069 namespace
00070 {
00071
00072
00073
00074
00075 template <class T>
00076 void getColor(const Image<T>& A, Image<PixRGB<T> >& B)
00077 {
00078 B.resize(A.getWidth(),A.getHeight());
00079 typename Image<T>::const_iterator BWptr = A.begin();
00080 typename Image<PixRGB<T> >::iterator COLptr = B.beginw();
00081
00082 while(BWptr != A.end())
00083 {
00084 *COLptr = PixRGB<T>(PixRGB<double>(PixHSV<double>(0,0,*BWptr*255.0F)));
00085 ++BWptr; ++COLptr;
00086 }
00087 }
00088
00089 template <class T>
00090 void getGrey(const Image<PixRGB<float> >& A,Image<T>& B)
00091 {
00092 B.resize(A.getWidth(),A.getHeight());
00093 typename Image<T>::iterator BWptr = B.beginw();
00094 typename Image<PixRGB<float> >::const_iterator COLptr = A.begin();
00095 float h,s,v;
00096 while(BWptr != B.endw())
00097 {
00098 PixRGB<float> pix = *COLptr;
00099 PixHSV<float>(pix).getHSV(h,s,v);
00100 *BWptr = (T)(v/255.0F);
00101 ++BWptr; ++COLptr;
00102 }
00103 }
00104 }
00105
00106
00107
00108 template <class FLOAT>
00109 featureClusterVision<FLOAT>::
00110 featureClusterVision(OptionManager& mgr,
00111 const std::string& descrName,
00112 const std::string& tagName,
00113 nub::soft_ref<StdBrain>& _brain,
00114 nub::soft_ref<InputFrameSeries>& _ifs,
00115 const std::string& extraArg0)
00116 :
00117 ModelComponent(mgr, descrName, tagName)
00118 {
00119 fCV_NULLstring = "NULL";
00120 std::cerr << "(0) GETTING shared pointers and MM devices\n";
00121 fCV_brain = _brain;
00122 fCV_useBrain = true;
00123 fCVsetUpfCV(mgr,descrName,tagName,_ifs,extraArg0);
00124 }
00125
00126 template <class FLOAT>
00127 featureClusterVision<FLOAT>::
00128 featureClusterVision(OptionManager& mgr,
00129 const std::string& descrName,
00130 const std::string& tagName,
00131 Image<FLOAT> *salMap,
00132 std::vector<Image<FLOAT> > *cmaps,
00133 nub::soft_ref<InputFrameSeries>& _ifs,
00134 const std::string& extraArg0)
00135 :
00136 ModelComponent(mgr, descrName, tagName)
00137 {
00138 fCV_NULLstring = "NULL";
00139 fCV_cmaps = cmaps;
00140 fCV_noBrainSalmap = salMap;
00141 std::cerr << "(0) GETTING shared pointers and MM devices\n";
00142 fCV_useBrain = false;
00143 fCVsetUpfCV(mgr,descrName,tagName,_ifs,extraArg0);
00144 }
00145
00146 template <class FLOAT>
00147 void featureClusterVision<FLOAT>::
00148 fCVsetUpfCV(OptionManager& mgr,
00149 const std::string& descrName,
00150 const std::string& tagName,
00151 nub::soft_ref<InputFrameSeries>& _ifs,
00152 const std::string& extraArg0)
00153 {
00154 fCV_iframes = _ifs;
00155 Image<PixRGB<byte> > fuck = Raster::ReadRGB(extraArg0, RASFMT_PNM);
00156 std::string NPconf = getManager().getOptionValString(&OPT_NPconfig);
00157 std::cerr << "NP config file\t" << NPconf << "\n";
00158 std::string Pconf = getManager().getOptionValString(&OPT_Polyconfig);
00159 std::cerr << "Poly config file\t" << Pconf << "\n";
00160 std::string Lconf = getManager().getOptionValString(&OPT_localconfig);
00161 std::cerr << "Local config file\t" << Lconf << "\n";
00162 std::string Mat = getManager().getOptionValString(&OPT_icamatrix);
00163 std::cerr << "ICA Matrix file\t" << Mat << "\n";
00164
00165
00166 std::cerr << "(1) SETTING readConfig Objects";
00167 readConfig NPConfig(25);
00168
00169 std::cerr << ".";
00170 readConfig localConfig(25);
00171
00172 std::cerr << ".\n";
00173 readConfig KernelConfig(25);
00174
00175 std::cerr << "(2) READING readConfig Files\n";
00176
00177 NPConfig.openFile((char*)NPconf.c_str());
00178 localConfig.openFile((char*)Lconf.c_str());
00179 KernelConfig.openFile((char*)Pconf.c_str());
00180
00181 std::cerr << "(3) SETTING up NP classifier\n";
00182
00183 fCV_NP.NPsetup(NPConfig,KernelConfig,false);
00184
00185 Point2D<int> tempPoint(0,0);
00186 std::cerr << "(4) SETTING local variables\n";
00187 fCV_channelNumbers = (int)localConfig.getItemValueF("channelNumbers");
00188 fCV_totalFeatures = (int)localConfig.getItemValueF("totalFeatures");
00189 fCV_totalPotFeatures = (int)localConfig.getItemValueF("totalPotFeatures");
00190 fCV_featuresPerChannel = (int)localConfig.getItemValueF("featuresPerChannel");
00191
00192 int secretVariable = (fCV_totalPotFeatures/fCV_featuresPerChannel)+16;
00193 fCV_printOutFeatures = localConfig.getItemValueB("printOutFeatures");
00194 fCV_printOutClusters = localConfig.getItemValueB("printOutClusters");
00195 fCV_maxOriVal = localConfig.getItemValueF("maxOriVal");
00196 fCV_maxMotVal = localConfig.getItemValueF("maxMotVal");
00197
00198 fCV_sizeX = fuck.getWidth();
00199 fCV_sizeY = fuck.getHeight();
00200 fCV_reducedFeatureCount =
00201 (int)localConfig.getItemValueF("reducedFeatureCount");
00202 fCV_sparcePoints = (int)localConfig.getItemValueF("sparcePoints");
00203
00204 std::cerr << "(5) RESIZING local vectors and Images\n";
00205 std::cerr << "... cmap resize........\t" << (fCV_sizeX*fCV_sizeY) << "\n";
00206 fCV_cmap.resize(fCV_sizeX*fCV_sizeY,tempPoint);
00207 fCV_cmapOld.resize(fCV_sizeX*fCV_sizeY,tempPoint);
00208 fCV_keepParticle.resize(fCV_sizeX*fCV_sizeY,false);
00209
00210 std::cerr << "... rmap resize........\t" << (fCV_sizeX*fCV_sizeY) << "\n";
00211
00212
00213 Point2D<int> *temppPoint = 0;
00214 fCV_rmap.resize(fCV_sizeX*fCV_sizeY,temppPoint);
00215
00216 fCVresizeMaps1(fCV_sparcePoints);
00217
00218 int fpc = fCV_reducedFeatureCount/fCV_channelNumbers;
00219
00220 std::cerr << "... dub resize.........\t" << fCV_sizeX << " x "
00221 << fCV_sizeY << "\n";
00222 Image<FLOAT> dub;
00223 dub.resize(fCV_sizeX,fCV_sizeY);
00224 std::cerr << "... ICAunmix resize....\t" << secretVariable << "\n";
00225 fCV_ICAunmix.resize(secretVariable,dub);
00226
00227 std::cerr << "... Unmixed resize.....\t" << secretVariable << "\n";
00228 fCV_Unmixed.resize(secretVariable,dub);
00229
00230 std::cerr << "... featureMatrixSizes.\t" << secretVariable << "\n";
00231 fCV_featureMatrixSizes.resize(secretVariable,fpc);
00232
00233 std::cerr << "(6) OPENING and reading ICA Matrix\n";
00234
00235 Image<FLOAT> ttemp;
00236
00237 for(int i = 0; i < secretVariable; i++)
00238 {
00239 std::cerr << "--\n";
00240 char str[100];
00241 sprintf(str,"%s.%d.dat",Mat.c_str(),(i+1));
00242 readMatrix rm(str);
00243 rm.echoMatrix();
00244 fCV_ICAunmix[i] = rm.returnMatrixAsImage();
00245
00246
00247 }
00248 std::cerr << "\n";
00249 fCV_currentCovHolder = 0;
00250 bool tbool = false;
00251 FLOAT tFLOAT = 0.0F;
00252 int tint = 0;
00253 std::cerr << "(7) resizing map for features and weights\n";
00254 fCV_featureOn.resize(secretVariable,&tbool);
00255 fCV_featureName.resize(secretVariable,"Undefined");
00256 fCV_weights.resize(secretVariable,&tFLOAT);
00257 fCV_featureNormConst.resize(secretVariable,1.0F);
00258 fCV_featureTransConst.resize(secretVariable,1.0F);
00259 fCV_ICAfeaturesPerChannel.resize(secretVariable,&tint);
00260 std::string temp = "groovy";
00261
00262
00263
00264
00265 std::cerr << "(8) loading feature activation bools\n";
00266 fCV_blueYellowOn = localConfig.getItemValueB("blueYellowOn");
00267 fCV_featureOn[0] = &fCV_blueYellowOn;
00268 fCV_featureName[0] = "BlueYellow";
00269 fCV_redGreenOn = localConfig.getItemValueB("redGreenOn");
00270 fCV_featureOn[1] = &fCV_redGreenOn;
00271 fCV_featureName[1] = "RedGreen";
00272 fCV_flickerOn = localConfig.getItemValueB("flickerOn");
00273 fCV_featureOn[2] = &fCV_flickerOn;
00274 fCV_featureName[2] = "Flicker";
00275 fCV_lumOn = localConfig.getItemValueB("lumOn");
00276 fCV_featureOn[3] = &fCV_lumOn;
00277 fCV_featureName[3] = "Luminance";
00278 fCV_oriOn = localConfig.getItemValueB("oriOn");
00279 fCV_featureOn[4] = &fCV_oriOn;
00280 fCV_featureName[4] = "Orientation1";
00281 fCV_featureOn[5] = &fCV_oriOn;
00282 fCV_featureName[5] = "Orientation2";
00283 fCV_featureOn[6] = &fCV_oriOn;
00284 fCV_featureName[6] = "Orientation3";
00285 fCV_featureOn[7] = &fCV_oriOn;
00286 fCV_featureName[7] = "Orientation4";
00287 fCV_motionOn = localConfig.getItemValueB("motionOn");
00288 fCV_featureOn[8] = &fCV_motionOn;
00289 fCV_featureName[8] = "Motion1";
00290 fCV_featureOn[9] = &fCV_motionOn;
00291 fCV_featureName[9] = "Motion2";
00292 fCV_featureOn[10] = &fCV_motionOn;
00293 fCV_featureName[10] = "Motion3";
00294 fCV_featureOn[11] = &fCV_motionOn;
00295 fCV_featureName[11] = "Motion4";
00296 fCV_spatialOn = localConfig.getItemValueB("spatialOn");
00297 fCV_featureOn[12] = &fCV_spatialOn;
00298 fCV_featureName[12] = "SpatialXY";
00299 fCV_mixAlphaOn = localConfig.getItemValueB("mixAlphaOn");
00300 fCV_featureOn[13] = &fCV_mixAlphaOn;
00301 fCV_featureName[13] = "MixedAlpha";
00302 fCV_mixBetaOn = localConfig.getItemValueB("mixBetaOn");
00303 fCV_featureOn[14] = &fCV_mixBetaOn;
00304 fCV_featureName[14] = "MixedBeta";
00305 fCV_mixGammaOn = localConfig.getItemValueB("mixGammaOn");
00306 fCV_featureOn[15] = &fCV_mixGammaOn;
00307 fCV_featureName[15] = "MixedGamma";
00308
00309 fCV_motionCombinedOn = localConfig.getItemValueB("motionCombinedOn");
00310 fCV_featureOn[16] = &fCV_motionCombinedOn;
00311 fCV_featureName[16] = "MotionCombined";
00312
00313 fCV_redOn = localConfig.getItemValueB("redOn");
00314 fCV_featureOn[17] = &fCV_redOn;
00315 fCV_featureName[17] = "ColorRed";
00316 fCV_greenOn = localConfig.getItemValueB("greenOn");
00317 fCV_featureOn[18] = &fCV_greenOn;
00318 fCV_featureName[18] = "ColorGreen";
00319 fCV_blueOn = localConfig.getItemValueB("blueOn");
00320 fCV_featureOn[19] = &fCV_blueOn;
00321 fCV_featureName[19] = "ColorBlue";
00322 fCV_yellowOn = localConfig.getItemValueB("yellowOn");
00323 fCV_featureOn[20] = &fCV_yellowOn;
00324 fCV_featureName[20] = "ColorYellow";
00325 fCV_hueOn = localConfig.getItemValueB("hueOn");
00326 fCV_featureOn[21] = &fCV_hueOn;
00327 fCV_featureName[21] = "ColorHue";
00328 fCV_satOn = localConfig.getItemValueB("satOn");
00329 fCV_featureOn[22] = &fCV_satOn;
00330 fCV_featureName[22] = "ColorSaturation";
00331 fCV_valOn = localConfig.getItemValueB("valOn");
00332 fCV_featureOn[23] = &fCV_valOn;
00333 fCV_featureName[23] = "ColorValue";
00334 fCV_hue1On = localConfig.getItemValueB("hue1On");
00335 fCV_featureOn[24] = &fCV_hue1On;
00336 fCV_featureName[24] = "ColorHue1";
00337 fCV_hue2On = localConfig.getItemValueB("hue2On");
00338 fCV_featureOn[25] = &fCV_hue2On;
00339 fCV_featureName[25] = "ColorHue2";
00340
00341
00342
00343 std::cerr << "(9) loading feature weights for clustering\n";
00344 fCV_blueYellowWeight = localConfig.getItemValueF("blueYellowWeight");
00345 fCV_weights[0] = &fCV_blueYellowWeight;
00346 fCV_featureNormConst[0] = localConfig.getItemValueF("blueYellowNorm");
00347 fCV_featureTransConst[0] = localConfig.getItemValueF("blueYellowTrans");
00348 fCV_redGreenWeight = localConfig.getItemValueF("redGreenWeight");
00349 fCV_weights[1] = &fCV_redGreenWeight;
00350 fCV_featureNormConst[1] = localConfig.getItemValueF("redGreenNorm");
00351 fCV_featureTransConst[1] = localConfig.getItemValueF("redGreenTrans");
00352 fCV_flickerWeight = localConfig.getItemValueF("flickerWeight");
00353 fCV_weights[2] = &fCV_flickerWeight;
00354 fCV_featureNormConst[2] = localConfig.getItemValueF("flickerNorm");
00355 fCV_featureTransConst[2] = localConfig.getItemValueF("flickerTrans");
00356 fCV_lumWeight = localConfig.getItemValueF("lumWeight");
00357 fCV_weights[3] = &fCV_lumWeight;
00358 fCV_featureNormConst[3] = localConfig.getItemValueF("lumNorm");
00359 fCV_featureTransConst[3] = localConfig.getItemValueF("lumTrans");
00360 fCV_oriWeight = localConfig.getItemValueF("oriWeight");
00361 fCV_oriOffset = 4;
00362 fCV_weights[4] = &fCV_oriWeight;
00363 fCV_featureNormConst[4] = localConfig.getItemValueF("oriNorm");
00364 fCV_featureTransConst[4] = localConfig.getItemValueF("oriTrans");
00365 fCV_weights[5] = &fCV_oriWeight;
00366 fCV_featureNormConst[5] = localConfig.getItemValueF("oriNorm");
00367 fCV_featureTransConst[5] = localConfig.getItemValueF("oriTrans");
00368 fCV_weights[6] = &fCV_oriWeight;
00369 fCV_featureNormConst[6] = localConfig.getItemValueF("oriNorm");
00370 fCV_featureTransConst[6] = localConfig.getItemValueF("oriTrans");
00371 fCV_weights[7] = &fCV_oriWeight;
00372 fCV_featureNormConst[7] = localConfig.getItemValueF("oriNorm");
00373 fCV_featureTransConst[7] = localConfig.getItemValueF("oriTrans");
00374 fCV_motionWeight = localConfig.getItemValueF("motionWeight");
00375 fCV_motOffset = 8;
00376 fCV_weights[8] = &fCV_motionWeight;
00377 fCV_featureNormConst[8] = localConfig.getItemValueF("motionNorm");
00378 fCV_featureTransConst[8] = localConfig.getItemValueF("motionTrans");
00379 fCV_weights[9] = &fCV_motionWeight;
00380 fCV_featureNormConst[9] = localConfig.getItemValueF("motionNorm");
00381 fCV_featureTransConst[9] = localConfig.getItemValueF("motionTrans");
00382 fCV_weights[10] = &fCV_motionWeight;
00383 fCV_featureNormConst[10] = localConfig.getItemValueF("motionNorm");
00384 fCV_featureTransConst[10] = localConfig.getItemValueF("motionTrans");
00385 fCV_weights[11] = &fCV_motionWeight;
00386 fCV_featureNormConst[11] = localConfig.getItemValueF("motionNorm");
00387 fCV_featureTransConst[11] = localConfig.getItemValueF("motionTrans");
00388 fCV_spatOffset = 12;
00389 fCV_spatialWeight = localConfig.getItemValueF("spatialWeight");
00390 fCV_weights[12] = &fCV_spatialWeight;
00391 fCV_featureNormConst[12] = localConfig.getItemValueF("spatialNorm");
00392 fCV_featureTransConst[12] = localConfig.getItemValueF("spatialTrans");
00393 fCV_mixOffset = 12;
00394 fCV_mixAlphaWeight = localConfig.getItemValueF("mixAlphaWeight");
00395 fCV_weights[13] = &fCV_mixAlphaWeight;
00396 fCV_featureNormConst[13] = localConfig.getItemValueF("alphaNorm");
00397 fCV_featureTransConst[13] = localConfig.getItemValueF("alphaTrans");
00398 fCV_mixBetaWeight = localConfig.getItemValueF("mixBetaWeight");
00399 fCV_weights[14] = &fCV_mixBetaWeight;
00400 fCV_featureNormConst[14] = localConfig.getItemValueF("betaNorm");
00401 fCV_featureTransConst[14] = localConfig.getItemValueF("betaTrans");
00402 fCV_mixGammaWeight = localConfig.getItemValueF("mixGammaWeight");
00403 fCV_weights[15] = &fCV_mixGammaWeight;
00404 fCV_featureNormConst[15] = localConfig.getItemValueF("gammaNorm");
00405 fCV_featureTransConst[15] = localConfig.getItemValueF("gammaTrans");
00406
00407 fCV_motionCombinedOffset = 16;
00408 fCV_motionCombinedWeight = localConfig.getItemValueF("motionCombinedWeight");
00409 fCV_weights[16] = &fCV_motionCombinedWeight;
00410 fCV_featureNormConst[16] = localConfig.getItemValueF("motionCombinedNorm");
00411 fCV_featureTransConst[16] = localConfig.getItemValueF("motionCombinedTrans");
00412
00413 fCV_colorOffset = 17;
00414 fCV_redWeight = localConfig.getItemValueF("redWeight");
00415 fCV_weights[17] = &fCV_redWeight;
00416 fCV_featureNormConst[17] = localConfig.getItemValueF("redNorm");
00417 fCV_featureTransConst[17] = localConfig.getItemValueF("redTrans");
00418 fCV_redNorm = &fCV_featureNormConst[17];
00419 fCV_redTrans = &fCV_featureTransConst[17];
00420 fCV_greenWeight = localConfig.getItemValueF("greenWeight");
00421 fCV_weights[18] = &fCV_greenWeight;
00422 fCV_featureNormConst[18] = localConfig.getItemValueF("greenNorm");
00423 fCV_featureTransConst[18] = localConfig.getItemValueF("greenTrans");
00424 fCV_greenNorm = &fCV_featureNormConst[18];
00425 fCV_greenTrans = &fCV_featureTransConst[18];
00426 fCV_blueWeight = localConfig.getItemValueF("blueWeight");
00427 fCV_weights[19] = &fCV_blueWeight;
00428 fCV_featureNormConst[19] = localConfig.getItemValueF("blueNorm");
00429 fCV_featureTransConst[19] = localConfig.getItemValueF("blueTrans");
00430 fCV_blueNorm = &fCV_featureNormConst[19];
00431 fCV_blueTrans = &fCV_featureTransConst[19];
00432 fCV_yellowWeight = localConfig.getItemValueF("yellowWeight");
00433 fCV_weights[20] = &fCV_yellowWeight;
00434 fCV_featureNormConst[20] = localConfig.getItemValueF("yellowNorm");
00435 fCV_featureTransConst[20] = localConfig.getItemValueF("yellowTrans");
00436 fCV_yellowNorm = &fCV_featureNormConst[20];
00437 fCV_yellowTrans = &fCV_featureTransConst[20];
00438 fCV_hueWeight = localConfig.getItemValueF("hueWeight");
00439 fCV_weights[21] = &fCV_hueWeight;
00440 fCV_featureNormConst[21] = localConfig.getItemValueF("hueNorm");
00441 fCV_featureTransConst[21] = localConfig.getItemValueF("hueTrans");
00442 fCV_hueNorm = &fCV_featureNormConst[21];
00443 fCV_hueTrans = &fCV_featureTransConst[21];
00444 fCV_satWeight = localConfig.getItemValueF("satWeight");
00445 fCV_weights[22] = &fCV_satWeight;
00446 fCV_featureNormConst[22] = localConfig.getItemValueF("satNorm");
00447 fCV_featureTransConst[22] = localConfig.getItemValueF("satTrans");
00448 fCV_satNorm = &fCV_featureNormConst[22];
00449 fCV_satTrans = &fCV_featureTransConst[22];
00450 fCV_valWeight = localConfig.getItemValueF("valWeight");
00451 fCV_weights[23] = &fCV_valWeight;
00452 fCV_featureNormConst[23] = localConfig.getItemValueF("valNorm");
00453 fCV_featureTransConst[23] = localConfig.getItemValueF("valTrans");
00454 fCV_valNorm = &fCV_featureNormConst[23];
00455 fCV_valTrans = &fCV_featureTransConst[23];
00456 fCV_hue1Weight = localConfig.getItemValueF("hue1Weight");
00457 fCV_weights[24] = &fCV_hue1Weight;
00458 fCV_featureNormConst[24] = localConfig.getItemValueF("hue1Norm");
00459 fCV_featureTransConst[24] = localConfig.getItemValueF("hue1Trans");
00460 fCV_hue1Norm = &fCV_featureNormConst[24];
00461 fCV_hue1Trans = &fCV_featureTransConst[21];
00462 fCV_hue2Weight = localConfig.getItemValueF("hue2Weight");
00463 fCV_weights[25] = &fCV_hue2Weight;
00464 fCV_featureNormConst[25] = localConfig.getItemValueF("hue2Norm");
00465 fCV_featureTransConst[25] = localConfig.getItemValueF("hue2Trans");
00466 fCV_hue2Norm = &fCV_featureNormConst[25];
00467 fCV_hue2Trans = &fCV_featureTransConst[21];
00468
00469 std::cerr << "(10) loading feature ICA PCA reduced sizes\n";
00470 fCV_ICAfeaturesRedGreen =
00471 (int)localConfig.getItemValueF("ICAfeaturesRedGreen");
00472 fCV_ICAfeaturesPerChannel[0] = &fCV_ICAfeaturesRedGreen;
00473 fCV_ICAfeaturesBlueYellow =
00474 (int)localConfig.getItemValueF("ICAfeaturesBlueYellow");
00475 fCV_ICAfeaturesPerChannel[1] = &fCV_ICAfeaturesBlueYellow;
00476 fCV_ICAfeaturesFlicker =
00477 (int)localConfig.getItemValueF("ICAfeaturesFlicker");
00478 fCV_ICAfeaturesPerChannel[2] = &fCV_ICAfeaturesFlicker;
00479 fCV_ICAfeaturesLum =
00480 (int)localConfig.getItemValueF("ICAfeaturesLum");
00481 fCV_ICAfeaturesPerChannel[3] = &fCV_ICAfeaturesLum;
00482 fCV_ICAfeaturesOri =
00483 (int)localConfig.getItemValueF("ICAfeaturesOri");
00484 fCV_ICAfeaturesPerChannel[4] = &fCV_ICAfeaturesOri;
00485 fCV_ICAfeaturesPerChannel[5] = &fCV_ICAfeaturesOri;
00486 fCV_ICAfeaturesPerChannel[6] = &fCV_ICAfeaturesOri;
00487 fCV_ICAfeaturesPerChannel[7] = &fCV_ICAfeaturesOri;
00488 fCV_ICAfeaturesMotion =
00489 (int)localConfig.getItemValueF("ICAfeaturesMotion");
00490 fCV_ICAfeaturesPerChannel[8] = &fCV_ICAfeaturesMotion;
00491 fCV_ICAfeaturesPerChannel[9] = &fCV_ICAfeaturesMotion;
00492 fCV_ICAfeaturesPerChannel[10] = &fCV_ICAfeaturesMotion;
00493 fCV_ICAfeaturesPerChannel[11] = &fCV_ICAfeaturesMotion;
00494 fCV_ICAfeaturesSpatial =
00495 (int)localConfig.getItemValueF("ICAfeaturesSpatial");
00496 fCV_ICAfeaturesPerChannel[12] = &fCV_ICAfeaturesSpatial;
00497 fCV_ICAfeaturesAlpha =
00498 (int)localConfig.getItemValueF("ICAfeaturesAlpha");
00499 fCV_ICAfeaturesPerChannel[13] = &fCV_ICAfeaturesAlpha;
00500 fCV_ICAfeaturesBeta =
00501 (int)localConfig.getItemValueF("ICAfeaturesBeta");
00502 fCV_ICAfeaturesPerChannel[14] = &fCV_ICAfeaturesBeta;
00503 fCV_ICAfeaturesGamma =
00504 (int)localConfig.getItemValueF("ICAfeaturesGamma");
00505 fCV_ICAfeaturesPerChannel[15] = &fCV_ICAfeaturesGamma;
00506
00507 fCV_ICAfeaturesMotionCombined =
00508 (int)localConfig.getItemValueF("ICAfeaturesMotionCombined");
00509 fCV_ICAfeaturesPerChannel[16] = &fCV_ICAfeaturesMotionCombined;
00510
00511 fCV_ICAfeaturesRed = (int)localConfig.getItemValueF("ICAfeaturesRed");
00512 fCV_ICAfeaturesPerChannel[17] = &fCV_ICAfeaturesRed;
00513 fCV_ICAfeaturesGreen = (int)localConfig.getItemValueF("ICAfeaturesGreen");
00514 fCV_ICAfeaturesPerChannel[18] = &fCV_ICAfeaturesGreen;
00515 fCV_ICAfeaturesBlue = (int)localConfig.getItemValueF("ICAfeaturesBlue");
00516 fCV_ICAfeaturesPerChannel[19] = &fCV_ICAfeaturesBlue;
00517 fCV_ICAfeaturesYellow = (int)localConfig.getItemValueF("ICAfeaturesYellow");
00518 fCV_ICAfeaturesPerChannel[20] = &fCV_ICAfeaturesYellow;
00519 fCV_ICAfeaturesHue = (int)localConfig.getItemValueF("ICAfeaturesHue");
00520 fCV_ICAfeaturesPerChannel[21] = &fCV_ICAfeaturesHue;
00521 fCV_ICAfeaturesSat = (int)localConfig.getItemValueF("ICAfeaturesSat");
00522 fCV_ICAfeaturesPerChannel[22] = &fCV_ICAfeaturesSat;
00523 fCV_ICAfeaturesVal = (int)localConfig.getItemValueF("ICAfeaturesVal");
00524 fCV_ICAfeaturesPerChannel[23] = &fCV_ICAfeaturesVal;
00525 fCV_ICAfeaturesHue1 = (int)localConfig.getItemValueF("ICAfeaturesHue1");
00526 fCV_ICAfeaturesPerChannel[24] = &fCV_ICAfeaturesHue1;
00527 fCV_ICAfeaturesHue2 = (int)localConfig.getItemValueF("ICAfeaturesHue2");
00528 fCV_ICAfeaturesPerChannel[25] = &fCV_ICAfeaturesHue2;
00529 std::cerr << "(10) Resizing space for cluster\n";
00530 std::vector<bool*>::iterator featureOn_itr;
00531
00532 int fCount = 0;
00533 int c = 0;
00534 for(featureOn_itr = fCV_featureOn.begin();
00535 featureOn_itr != fCV_featureOn.end();
00536 ++featureOn_itr)
00537 {
00538 if(**featureOn_itr == true)
00539 {
00540 fCount = fCount + *fCV_ICAfeaturesPerChannel[c];
00541 std::cerr << "FEATURES " << *fCV_ICAfeaturesPerChannel[c] << "\n";
00542 }
00543 c++;
00544 }
00545
00546 fCV_newMatSize = fCount;
00547 fCV_featureNameICA.resize(secretVariable,&fCV_NULLstring);
00548
00549 fCVresizeMaps2(fCV_sparcePoints,fCV_newMatSize);
00550 fCV_NPtemporalBias = localConfig.getItemValueF("NPtemporalBias");
00551 fCV_doNPbias = false;
00552 fCV_saliencyExp = localConfig.getItemValueF("saliencyExp");
00553 fCV_lowPassType = (int)localConfig.getItemValueF("lowPassType");
00554 fCV_densityBias = localConfig.getItemValueF("densityBias");
00555 fCV_useTimerFile = localConfig.getItemValueB("useTimerFile");
00556 fCV_salmapLowPassTemporalBias =
00557 localConfig.getItemValueF("salmapLowPassTemporalBias");
00558
00559 fCV_doMatchSelf = true;
00560 fCV_doSLPTB = false;
00561
00562
00563 fCV_lowPassKernelName = localConfig.getItemValueS("lowPassKernelName");
00564 readMatrix kernelMat(fCV_lowPassKernelName.c_str());
00565 fCV_lowPassKernel = kernelMat.returnMatrixAsImage();
00566
00567 fCV_gaborStandardDev = localConfig.getItemValueF("gaborStandardDev");
00568 fCV_gaborPeriod = localConfig.getItemValueF("gaborPeriod");
00569 fCV_gaborScales = (unsigned int)localConfig.getItemValueF("gaborScales");
00570 fCV_gaborUseQuarter = localConfig.getItemValueB("gaborUseQuarter");
00571 fCVcreateGaborFilters();
00572 }
00573
00574
00575 template <class FLOAT>
00576 featureClusterVision<FLOAT>::~featureClusterVision()
00577 {}
00578
00579
00580 template <class FLOAT>
00581 void featureClusterVision<FLOAT>::fCVresizeMaps1(int sparcePoints)
00582 {
00583 FLOAT ZERO = 0.0F;
00584 std::cerr << "MAP RESIZE " << sparcePoints << "\n";
00585 std::cerr << "... fmap resize........\t" << fCV_totalFeatures << " x "
00586 << (sparcePoints+OVER) << "\n";
00587
00588 std::vector<FLOAT> tempVecD2(0,0.0F);
00589 fCV_fmap.resize(sparcePoints+OVER,tempVecD2);
00590
00591 std::cerr << "... unMixedMap resize..\t" << (sparcePoints+OVER) << " x "
00592 << fCV_totalFeatures << "\n";
00593 std::vector<FLOAT*> tempVecPP(sparcePoints+OVER,(&ZERO));
00594 fCV_unmixedMap.resize(fCV_totalFeatures,tempVecPP);
00595 PixRGB<FLOAT> pixey;
00596 fCV_lowPassVector.resize(sparcePoints,pixey);
00597
00598 }
00599
00600
00601 template <class FLOAT>
00602 void featureClusterVision<FLOAT>::fCVresizeMaps2(int sparcePoints, int newMatSize)
00603 {
00604 FLOAT ZERO = 0.0F;
00605 std::cerr << "... space resize.......\t" << newMatSize << " x "
00606 << (sparcePoints+OVER) << "\n";
00607 typename std::vector<FLOAT> tempVecD(newMatSize,0.0F);
00608 fCV_space.resize(sparcePoints+OVER,tempVecD);
00609 std::cerr << "(X) feature Cluster Vision Object Ready!\n";
00610 fCV_NP.NPresizeSpace((sparcePoints+OVER),newMatSize);
00611 fCV_CV.resize(newMatSize,sparcePoints+OVER,0.0F);
00612
00613 typename std::vector<FLOAT> tempMix(sparcePoints+OVER,0.0F);
00614 fCV_mixedRotation.resize(3*fCV_featuresPerChannel,tempMix);
00615 fCV_mixedMotion.resize(3*fCV_featuresPerChannel,tempMix);
00616 std::cerr << "... sortedSpace resize.\t" << newMatSize << " x "
00617 << (sparcePoints+OVER) << " x "
00618 << (sparcePoints+OVER) << "\n";
00619 typename std::vector<FLOAT*> tempred2((sparcePoints+OVER),&ZERO);
00620 typename std::vector<std::vector<FLOAT*> >
00621 ntempred2(newMatSize,tempred2);
00622 fCV_sortedSpace.resize(sparcePoints+OVER,ntempred2);
00623 fCV_tcov.resize(newMatSize,sparcePoints+OVER,0.0F);
00624 fCV_tcov.baseID = 0;
00625 fCV_tcov.sortID = 0;
00626 fCV_tcov.matchID = 0;
00627 fCV_tcov.isMatched = false;
00628 fCV_tcov.isLarge = false;
00629
00630
00631 LINFO("Setting up all tcov");
00632 int j = 0;
00633 for(unsigned int i = 0; i < fCV_weights.size(); i++)
00634 {
00635 if(*fCV_featureOn[i] == true)
00636 {
00637 if((signed)i != fCV_spatOffset)
00638 for(int k = 0; k < *fCV_ICAfeaturesPerChannel[i]; k++)
00639 {
00640 fCV_tcov.bias[j] = *fCV_weights[i];
00641 fCV_tcov.norm[j] = fCV_featureNormConst[i];
00642 fCV_tcov.trans[j] = fCV_featureTransConst[i];
00643 fCV_tcov.featureName[j] = fCV_featureName[i];
00644 j++;
00645 }
00646 }
00647 }
00648 LINFO("Setting tcov spatial labels");
00649 fCV_tcov.featureName[fCV_tcov.featureName.size() - 2] = "Spatial X";
00650 fCV_tcov.featureName[fCV_tcov.featureName.size() - 1] = "Spatial Y";
00651
00652 LINFO("Setting tcov spatial matching");
00653 std::vector<covHolder<double> > covtemp;
00654 std::cerr << ".";
00655 covtemp.resize(COVSIZE,fCV_tcov);
00656 std::cerr << ".";
00657 fCV_covHolderMatch.resize(COVSIZE,fCV_tcov);
00658 std::cerr << ".";
00659 fCV_covHolder.resize(COVHOLDER,covtemp);
00660 std::cerr << ".";
00661 fCV_covDataSizeMatch = 0;
00662 std::cerr << ".\n";
00663 LINFO("MAP RESIZED 2");
00664
00665
00666
00667 }
00668
00669
00670 template <class FLOAT>
00671 void featureClusterVision<FLOAT>::fCVcreateGaborFilters()
00672 {
00673 const float gaborMasks[4] = {0.0F,45.0F,90.0F,135.0F};
00674 const FLOAT gaborSTD = fCV_gaborStandardDev;
00675 const FLOAT gaborPrd = fCV_gaborPeriod;
00676 Image<float> foo;
00677 fCV_gaborFiltersSin.resize(4,foo);
00678 fCV_gaborFiltersCos.resize(4,foo);
00679
00680 unsigned int iii = 0;
00681 for(typename std::vector<Image<FLOAT> >::iterator igaborFilters
00682 = fCV_gaborFiltersSin.begin();
00683 igaborFilters != fCV_gaborFiltersSin.end(); ++igaborFilters, iii++)
00684 {
00685 *igaborFilters = gaborFilter<FLOAT>(gaborSTD,gaborPrd,0.0F
00686 ,gaborMasks[iii]);
00687
00688 }
00689
00690 iii = 0;
00691 for(typename std::vector<Image<FLOAT> >::iterator igaborFilters
00692 = fCV_gaborFiltersCos.begin();
00693 igaborFilters != fCV_gaborFiltersCos.end(); ++igaborFilters, iii++)
00694 {
00695 *igaborFilters = gaborFilter<FLOAT>(gaborSTD,gaborPrd,45.0F
00696 ,gaborMasks[iii]);
00697
00698 }
00699 }
00700
00701
00702 template <class FLOAT>
00703 void featureClusterVision<FLOAT>::fCVuploadImage(Image<PixRGB<byte> > &input,
00704 std::string fileName)
00705 {
00706 fCV_realImage = input;
00707 fCV_doReal = true;
00708 fCV_fileName = fileName;
00709 LINFO("HEIGHT %d WIDTH %d",fCV_realImage.getHeight(),
00710 fCV_realImage.getWidth());
00711 if(fCV_realImage.getHeight() < fCV_realImage.getWidth())
00712 {
00713 fCV_sizeXbias = 1.0F;
00714 fCV_sizeYbias = (FLOAT)fCV_realImage.getHeight()/
00715 (FLOAT)fCV_realImage.getWidth();
00716 }
00717 else
00718 {
00719 fCV_sizeXbias = (FLOAT)fCV_realImage.getWidth()/
00720 (FLOAT)fCV_realImage.getHeight();
00721 fCV_sizeYbias = 1.0F;
00722 }
00723
00724 }
00725
00726
00727 template <class FLOAT>
00728 void featureClusterVision<FLOAT>::fCVmixChannels(typename
00729 std::vector<std::vector<FLOAT> > *data,
00730 int ch1a, int ch1b,
00731 int ch2a, int ch2b,
00732 typename std::vector<FLOAT> *outAlpha,
00733 typename std::vector<FLOAT> *outBeta,
00734 typename std::vector<FLOAT> *outGamma,
00735 FLOAT norm1, FLOAT norm2,
00736 int size = 0)
00737 {
00738
00739 ASSERT((outAlpha->size() >= data->size()) && "Vector must be larger");
00740 ASSERT((outBeta->size() >= data->size()) && "Vector must be larger");
00741 ASSERT((outGamma->size() >= data->size()) && "Vector must be larger");
00742
00743
00744 typename std::vector<FLOAT>::iterator iOutA;
00745 typename std::vector<FLOAT>::iterator iOutB;
00746 typename std::vector<FLOAT>::iterator iOutG;
00747 iOutA = outAlpha->begin();
00748 iOutB = outBeta->begin();
00749 iOutG = outGamma->begin();
00750 FLOAT c1mix,c2mix,c1Gmix,c2Gmix;
00751 if(size == 0)
00752 size = (signed)data->size();
00753 for(long i = 0; i < size; i++,
00754 ++iOutA, ++iOutB, ++iOutG)
00755 {
00756
00757
00758 c1mix = fabs((data->at(i)[ch1a])-(data->at(i)[ch1b]))/(norm1);
00759 c2mix = fabs((data->at(i)[ch2a])-(data->at(i)[ch2b]))/(norm2);
00760
00761 c1Gmix = (((data->at(i)[ch1a])+(data->at(i)[ch1b]))/(norm1));
00762 c2Gmix = (((data->at(i)[ch2a])+(data->at(i)[ch2b]))/(norm2));
00763
00764 *iOutA = (c1Gmix+c2Gmix)/2;
00765
00766
00767
00768 *iOutB = fabs(c1mix-c2mix)/2;
00769
00770
00771
00772
00773 *iOutG = *iOutA - *iOutB;
00774
00775 }
00776 }
00777
00778
00779 template <class FLOAT>
00780 void featureClusterVision<FLOAT>::fCVmixChannels(Image<FLOAT> &img0,
00781 Image<FLOAT> &img45,
00782 Image<FLOAT> &img90,
00783 Image<FLOAT> &img135,
00784 Image<FLOAT> *Alpha,
00785 Image<FLOAT> *Beta,
00786 Image<FLOAT> *Gamma)
00787 {
00788 FLOAT min0,max0,min45,max45,min90,max90,min135,max135;
00789
00790 getMinMax(img0, min0,max0); getMinMax(img45, min45,max45);
00791 getMinMax(img90, min90,max90); getMinMax(img135, min135,max135);
00792
00793 FLOAT norm1 = max0 + max90;
00794 FLOAT norm2 = max45 + max135;
00795
00796
00797 Image<FLOAT> mix1 = abs(img0 - img90) /norm1;
00798 Image<FLOAT> mix2 = abs(img45 - img135)/norm2;
00799
00800
00801 Image<FLOAT> mixG1 = (img0 + img90) /norm1;
00802 Image<FLOAT> mixG2 = (img45 + img135)/norm1;
00803
00804
00805 *Alpha = (mixG1 + mixG2)/2;
00806
00807
00808 *Beta = abs(mix1 - mix2)/2;
00809
00810
00811 *Gamma = *Alpha - *Beta;
00812 }
00813
00814
00815
00816 template <class FLOAT>
00817 void featureClusterVision<FLOAT>::fCVfindMixedChannels()
00818 {
00819 if(fCV_spatialOn == true)
00820 {
00821
00822 for(int i = 0; i < fCV_featuresPerChannel; i++)
00823 {
00824 fCVmixChannels(&fCV_fmap,((fCV_oriOffset*fCV_featuresPerChannel)+i),
00825 ((fCV_oriOffset*fCV_featuresPerChannel)+
00826 (2*fCV_featuresPerChannel)+i),
00827 ((fCV_oriOffset*fCV_featuresPerChannel)+
00828 (1*fCV_featuresPerChannel)+i),
00829 ((fCV_oriOffset*fCV_featuresPerChannel)+
00830 (3*fCV_featuresPerChannel)+i),
00831 &fCV_mixedRotation[i],
00832 &fCV_mixedRotation[i+fCV_featuresPerChannel],
00833 &fCV_mixedRotation[i+fCV_featuresPerChannel*2],
00834 fCV_maxOriVal,fCV_maxOriVal,fCV_countSM);
00835 }
00836 }
00837
00838 if(fCV_motionOn == true)
00839 {
00840
00841 for(int i = 0; i < fCV_featuresPerChannel; i++)
00842 {
00843 fCVmixChannels(&fCV_fmap,(fCV_motOffset*fCV_featuresPerChannel+i),
00844 (fCV_motOffset*fCV_featuresPerChannel+
00845 (2*fCV_featuresPerChannel)+i),
00846 (fCV_motOffset*fCV_featuresPerChannel+
00847 (fCV_featuresPerChannel)+i),
00848 (fCV_motOffset*fCV_featuresPerChannel+
00849 (3*fCV_featuresPerChannel)+i),
00850 &fCV_mixedMotion[i],
00851 &fCV_mixedMotion[i+fCV_featuresPerChannel],
00852 &fCV_mixedMotion[i+fCV_featuresPerChannel*2],
00853 fCV_maxMotVal,fCV_maxMotVal,fCV_countSM);
00854 }
00855 }
00856 }
00857
00858
00859
00860
00861
00862
00863
00864 #if 0
00865
00866
00867
00868 template <class FLOAT>
00869 void featureClusterVision<FLOAT>::fCVcheckMixing()
00870 {
00871 ASSERT(fCV_useBrain == true);
00872 int mod = 0;
00873 if(fCV_spatialOn == true)
00874 mod = 2;
00875
00876 std::cerr << "(1) GETTING saliency data \n";
00877
00878
00879
00880 Image<FLOAT> salmap;
00881 LFATAL("FIXME!!!!");
00882
00883 salmap = rescaleBilinear(salmap,fCV_sizeX,fCV_sizeY);
00884 std::cerr << "...model objects fetched\n";
00885
00886 typename std::vector<FLOAT> tempVecD2(0,0.0F);
00887 fCV_fmap.resize(0,tempVecD2);
00888 fCV_fmap.resize((salmap.getWidth()*salmap.getHeight()),tempVecD2);
00889 typename std::vector<FLOAT>
00890 tempMix((salmap.getWidth()*salmap.getHeight()),0.0F);
00891 fCV_mixedRotation.resize(0,tempMix);
00892 fCV_mixedMotion.resize(0,tempMix);
00893 fCV_mixedRotation.resize(3*fCV_featuresPerChannel,tempMix);
00894 fCV_mixedMotion.resize(3*fCV_featuresPerChannel,tempMix);
00895
00896
00897 for(int i = 0; i < salmap.getWidth(); i++)
00898 {
00899 for(int j = 0; j < salmap.getHeight(); j++)
00900 {
00901
00902
00903
00904 fCV_VC->getFeatures(Point2D<int>(i,j),fCV_fmap[(j*salmap.getWidth())+i]);
00905 }
00906 }
00907 fCV_countSM = fCV_fmap.size();
00908 fCVfindMixedChannels();
00909
00910 Image<FLOAT> outImage1;
00911 Image<FLOAT> outImage2;
00912 Image<FLOAT> outImage3;
00913 Image<FLOAT> ICAoutImage1;
00914 Image<FLOAT> ICAoutImage2;
00915 Image<FLOAT> ICAoutImage3;
00916
00917 outImage1.resize(salmap.getWidth(),salmap.getHeight());
00918 outImage2.resize(salmap.getWidth(),salmap.getHeight());
00919 outImage3.resize(salmap.getWidth(),salmap.getHeight());
00920 ICAoutImage1.resize(salmap.getWidth(),salmap.getHeight());
00921 ICAoutImage2.resize(salmap.getWidth(),salmap.getHeight());
00922 ICAoutImage3.resize(salmap.getWidth(),salmap.getHeight());
00923
00924
00925 Image<FLOAT> mmmap;
00926 Image<FLOAT> mmap;
00927 Image<FLOAT> foosh;
00928 mmmap = fCV_mixedRotation;
00929 mmap = mmmap;
00930 mmap = transpose(mmap);
00931 Image<FLOAT> ICAoutput1;
00932 Image<FLOAT> ICAoutput2;
00933 Image<FLOAT> ICAoutput3;
00934 unsigned int sm = (unsigned)fCV_countSM;
00935 unsigned int zero = 0;
00936
00937 unsigned int st = 0;
00938 unsigned int sp = st + (fCV_featuresPerChannel-1);
00939 unsigned int width = fCV_ICAunmix[fCV_mixOffset+1].getWidth();
00940 ICAoutput1 = matrixMult(mmap,fCV_ICAunmix[fCV_mixOffset+1],st,sp,
00941 zero,width,zero,sm);
00942
00943
00944 st = sp + 1;
00945 sp = st + (fCV_featuresPerChannel-1);
00946 width = fCV_ICAunmix[fCV_mixOffset+2].getWidth();
00947 ICAoutput2 = matrixMult(mmap,fCV_ICAunmix[fCV_mixOffset+1],st,sp,
00948 zero,width,zero,sm);
00949
00950 st = sp + 1;
00951 sp = st + (fCV_featuresPerChannel-1);
00952 width = fCV_ICAunmix[fCV_mixOffset+3].getWidth();
00953 ICAoutput3 = matrixMult(mmap,fCV_ICAunmix[fCV_mixOffset+1],st,sp,
00954 zero,width,zero,sm);
00955
00956 for(int x = 0; x < ICAoutput1.getWidth(); x++)
00957 {
00958 for(int i = 0; i < salmap.getWidth(); i++)
00959 {
00960 for(int j = 0; j < salmap.getHeight(); j++)
00961 {
00962 ICAoutImage1.setVal(i,j,(ICAoutput1.getVal(x,
00963 (j*salmap.getWidth())+i)));
00964 }
00965 }
00966 Raster::VisuFloat(ICAoutImage1,FLOAT_NORM_0_255,
00967 sformat("%s.out.ImageA.ICA.%d.pgm",
00968 fCV_fileName.c_str(),x));
00969 }
00970
00971 for(int x = 0; x < ICAoutput2.getWidth(); x++)
00972 {
00973 for(int i = 0; i < salmap.getWidth(); i++)
00974 {
00975 for(int j = 0; j < salmap.getHeight(); j++)
00976 {
00977 ICAoutImage2.setVal(i,j,(ICAoutput2.getVal(x,
00978 (j*salmap.getWidth())+i)));
00979 }
00980 }
00981 Raster::VisuFloat(ICAoutImage2,FLOAT_NORM_0_255,
00982 sformat("%s.out.ImageB.ICA.%d.pgm",
00983 fCV_fileName.c_str(),x));
00984 }
00985
00986 for(int x = 0; x < ICAoutput3.getWidth(); x++)
00987 {
00988 for(int i = 0; i < salmap.getWidth(); i++)
00989 {
00990 for(int j = 0; j < salmap.getHeight(); j++)
00991 {
00992 ICAoutImage3.setVal(i,j,(ICAoutput3.getVal(x,
00993 (j*salmap.getWidth())+i)));
00994 }
00995 }
00996 Raster::VisuFloat(ICAoutImage3,FLOAT_NORM_0_255,
00997 sformat("%s.out.ImageG.ICA.%d.pgm",
00998 fCV_fileName.c_str(),x));
00999 }
01000
01001 for(int x = 0; x < fCV_featuresPerChannel; x++)
01002 {
01003 for(int i = 0; i < salmap.getWidth(); i++)
01004 {
01005 for(int j = 0; j < salmap.getHeight(); j++)
01006 {
01007 outImage1.setVal(i,j,
01008 fCV_mixedRotation[x][(j*salmap.getWidth())+i]);
01009 outImage2.setVal(i,j,
01010 fCV_mixedRotation[x+fCV_featuresPerChannel]
01011 [(j*salmap.getWidth())+i]);
01012 outImage3.setVal(i,j,
01013 fCV_mixedRotation[x+fCV_featuresPerChannel*2]
01014 [(j*salmap.getWidth())+i]);
01015 }
01016 }
01017
01018
01019 Raster::VisuFloat(outImage1,FLOAT_NORM_0_255,
01020 sformat("%s.out.ImageA.%d.pgm",
01021 fCV_fileName.c_str(),x));
01022 Raster::VisuFloat(outImage2,FLOAT_NORM_0_255,
01023 sformat("%s.out.ImageB.%d.pgm",
01024 fCV_fileName.c_str(),x));
01025 Raster::VisuFloat(outImage3,FLOAT_NORM_0_255,
01026 sformat("%s.out.ImageG.%d.pgm",
01027 fCV_fileName.c_str(),x));
01028 }
01029 }
01030
01031
01032 template <class FLOAT>
01033 void featureClusterVision<FLOAT>::fCVcheckICA()
01034 {
01035 for(int i = 0; i < (fCV_totalPotFeatures/fCV_featuresPerChannel); i++)
01036 {
01037 LINFO("CHECKING CHANNEL %d",i);
01038 if(*fCV_featureOn[i] == true)
01039 {
01040 LINFO("CHANNEL %d ON",i);
01041 fCVcheckICA(i,true);
01042 }
01043 }
01044 }
01045
01046
01047 template <class FLOAT>
01048 void featureClusterVision<FLOAT>::fCVcheckICA(int channel, bool findMixed)
01049 {
01050 ASSERT(fCV_useBrain == true);
01051 int mod = 0;
01052 if(fCV_spatialOn == true)
01053 mod = 2;
01054
01055
01056 std::cerr << "(1) GETTING saliency data \n";
01057
01058
01059
01060 Image<FLOAT> salmap;
01061 LFATAL("FIXME");
01062
01063 salmap = rescaleBilinear(salmap,fCV_sizeX,fCV_sizeY);
01064 std::cerr << "...model objects fetched\n";
01065 typename std::vector<FLOAT> tempVecD2(0,0.0F);
01066 fCV_fmap.resize(0,tempVecD2);
01067 fCV_fmap.resize((salmap.getWidth()*salmap.getHeight()),tempVecD2);
01068 LINFO("MEMORY ALLOCATED for map %d x %d",
01069 (salmap.getWidth()*salmap.getHeight()),0);
01070
01071 typename std::vector<FLOAT>
01072 tempMix((salmap.getWidth()*salmap.getHeight()),0.0F);
01073 fCV_mixedRotation.resize(0,tempMix);
01074 fCV_mixedMotion.resize(0,tempMix);
01075 fCV_mixedRotation.resize(3*fCV_featuresPerChannel,tempMix);
01076 fCV_mixedMotion.resize(3*fCV_featuresPerChannel,tempMix);
01077
01078
01079
01080 for(int i = 0; i < salmap.getWidth(); i++)
01081 {
01082 for(int j = 0; j < salmap.getHeight(); j++)
01083 {
01084
01085
01086
01087 fCV_VC->getFeatures(Point2D<int>(i,j),fCV_fmap[(j*salmap.getWidth())+i]);
01088 }
01089 }
01090 LINFO("FEATURES fetched");
01091 fCV_countSM = fCV_fmap.size();
01092 if(findMixed == true)
01093 fCVfindMixedChannels();
01094 Image<FLOAT> ifmap;
01095 ifmap = fCV_fmap;
01096 unsigned long zero = 0;
01097 unsigned long pStart = fCV_featuresPerChannel*channel;
01098 unsigned long pStop = pStart+fCV_featuresPerChannel-1;
01099 unsigned long width = fCV_ICAunmix[channel].getWidth();
01100 unsigned long sm = fCV_countSM;
01101 Image<FLOAT> unmixedImage;
01102 unmixedImage.resize(fCV_ICAunmix[channel].getWidth(),ifmap.getHeight());
01103 unmixedImage = matrixMult(ifmap,fCV_ICAunmix[channel],pStart,pStop,
01104 zero,width,zero,sm);
01105 Image<FLOAT> outImage;
01106 outImage.resize(salmap.getWidth(),salmap.getHeight());
01107 LINFO("WRITTING images");
01108 for(int i = 0; i < unmixedImage.getWidth(); i++)
01109 {
01110 LINFO("Image %d",i);
01111 for(int j = 0; j < unmixedImage.getHeight(); j++)
01112 {
01113 int posX = j%outImage.getWidth();
01114 int posY = j/outImage.getWidth();
01115 outImage.setVal(posX,posY,unmixedImage.getVal(i,j));
01116 }
01117 Raster::VisuFloat(outImage,FLOAT_NORM_0_255
01118 ,sformat("out.ICAresponse.%d.%d.pgm",channel,i));
01119 LINFO("DONE");
01120 }
01121 }
01122
01123
01124 template <class FLOAT>
01125 void featureClusterVision<FLOAT>::fCVcheckMotionCombined(long frame)
01126 {
01127 ASSERT(fCV_useBrain == true);
01128 char c[100];
01129 if(frame < 10)
01130 sprintf(c,"00000%d",(int)frame);
01131 else if(frame < 100)
01132 sprintf(c,"0000%d",(int)frame);
01133 else if(frame < 1000)
01134 sprintf(c,"000%d",(int)frame);
01135 else if(frame < 10000)
01136 sprintf(c,"00%d",(int)frame);
01137 else if(frame < 100000)
01138 sprintf(c,"0%d",(int)frame);
01139 else
01140 sprintf(c,"%d",(int)frame);
01141
01142 int mod = 0;
01143 if(fCV_spatialOn == true)
01144 mod = 2;
01145
01146
01147 std::cerr << "(1) GETTING saliency data \n";
01148
01149
01150
01151 Image<FLOAT> salmap;
01152 LFATAL("FIXME!");
01153
01154 salmap = rescaleBilinear(salmap,fCV_sizeX,fCV_sizeY);
01155 std::cerr << "...model objects fetched\n";
01156 typename std::vector<FLOAT> tempVecD2(0,0.0F);
01157 fCV_fmap.resize(0,tempVecD2);
01158 fCV_fmap.resize((salmap.getWidth()*salmap.getHeight()),tempVecD2);
01159 LINFO("MEMORY ALLOCATED for map %d x %d",
01160 (salmap.getWidth()*salmap.getHeight()),0);
01161
01162
01163 for(int i = 0; i < salmap.getWidth(); i++)
01164 {
01165 for(int j = 0; j < salmap.getHeight(); j++)
01166 {
01167
01168
01169
01170 fCV_VC->getFeatures(Point2D<int>(i,j),fCV_fmap[(j*salmap.getWidth())+i]);
01171 }
01172 }
01173 LINFO("FEATURES fetched");
01174 fCV_countSM = fCV_fmap.size();
01175
01176 Image<FLOAT> ifmap;
01177 ifmap = fCV_fmap;
01178 unsigned long zero = 0;
01179 unsigned long pStart = fCV_motOffset*fCV_featuresPerChannel;
01180 unsigned long pStop = pStart+((fCV_featuresPerChannel*4)-1);
01181 unsigned long width = fCV_ICAunmix[15].getWidth();
01182 unsigned long sm = fCV_countSM;
01183
01184 Image<FLOAT> unmixedImage;
01185 unmixedImage.resize(fCV_ICAunmix[15].getWidth(),ifmap.getHeight());
01186 LINFO("RUNNING for Matrix Size %d x %d at position %d to %d",
01187 fCV_ICAunmix[15].getWidth(),fCV_ICAunmix[15].getHeight(),
01188 pStart,pStop);
01189 Image<FLOAT> shit;
01190 shit = fCV_ICAunmix[15];
01191 std::cerr << "filter\n";
01192 for(int i = 0; i < fCV_ICAunmix[15].getWidth(); i++)
01193 {
01194 for(int j = 0; j < fCV_ICAunmix[15].getHeight(); j++)
01195 {
01196 std::cerr << fCV_ICAunmix[15].getVal(i,j) << " ";
01197 }
01198 std::cerr << "\n";
01199 }
01200
01201
01202 unmixedImage = matrixMult(ifmap,fCV_ICAunmix[15],pStart,pStop,
01203 zero,width,zero,sm);
01204 Image<PixRGB<FLOAT> > outImage;
01205 Image<PixRGB<FLOAT> > outImage2;
01206 Image<FLOAT> storeImage;
01207 Image<FLOAT> storeImage2;
01208 outImage.resize(salmap.getWidth(),salmap.getHeight());
01209 outImage2.resize(salmap.getWidth()*3,salmap.getHeight()*2);
01210
01211 storeImage.resize(salmap.getWidth(),salmap.getHeight());
01212 storeImage2.resize(salmap.getWidth()*3,salmap.getHeight()*2);
01213
01214 LINFO("WRITTING images");
01215 int XX = 0;
01216 int YY = 0;
01217
01218 for(int i = 0; i < unmixedImage.getWidth(); i++)
01219 {
01220 LINFO("Image %d",i);
01221 if(i == 0){ XX = 0; YY = 0;}
01222 if(i == 1){ XX = 1; YY = 0;}
01223 if(i == 2){ XX = 2; YY = 0;}
01224 if(i == 3){ XX = 0; YY = 1;}
01225 if(i == 4){ XX = 1; YY = 1;}
01226 if(i == 5){ XX = 2; YY = 1;}
01227 for(int j = 0; j < unmixedImage.getHeight(); j++)
01228 {
01229 int posX = j%outImage.getWidth();
01230 int posY = j/outImage.getWidth();
01231
01232 storeImage.setVal(posX,posY,unmixedImage.getVal(i,j));
01233 storeImage2.setVal(posX+(XX*outImage.getWidth())
01234 ,posY+(YY*outImage.getHeight())
01235 ,unmixedImage.getVal(i,j));
01236 }
01237 outImage = normalizeRGPolar(storeImage,255.0,255.0);
01238 outImage2 = normalizeRGPolar(storeImage2,255.0,255.0);
01239 Raster::WriteRGB(outImage,sformat("out.motionCombined.%d.%s.ppm",i,c));
01240
01241 LINFO("DONE");
01242 }
01243 Raster::WriteRGB(outImage2,sformat("out.motionCombinedAll.%s.ppm",c));
01244 }
01245 #endif
01246
01247
01248
01249 template <class FLOAT>
01250 void featureClusterVision<FLOAT>::fCVfeaturesToFile(std::string fileName,
01251 bool _new = false)
01252 {
01253 if(_new == false)
01254 {
01255 fCVfindFeaturesBrain();
01256 fCVfindMixedChannels();
01257 }
01258 std::string newFile;
01259 newFile = fileName + ".out.features";
01260 std::ofstream outfile(newFile.c_str(),std::ios::app);
01261 typename std::vector<std::vector<FLOAT> >::iterator iFmap;
01262 typename std::vector<FLOAT>::iterator iiFmap;
01263 iFmap = fCV_fmap.begin();
01264 int i = 0;
01265 while(iFmap != fCV_fmap.end())
01266 {
01267 for(iiFmap = iFmap->begin(); iiFmap != iFmap->end(); ++iiFmap)
01268 outfile << *iiFmap << "\t";
01269
01270 for(int x = 0; x < fCV_featuresPerChannel; x++)
01271 outfile << fCV_mixedRotation[x][i] << "\t";
01272
01273 for(int x = 0; x < fCV_featuresPerChannel; x++)
01274 outfile << fCV_mixedRotation[x+fCV_featuresPerChannel][i] << "\t";
01275
01276 for(int x = 0; x < fCV_featuresPerChannel; x++)
01277 outfile << fCV_mixedRotation[x+fCV_featuresPerChannel*2][i] << "\t";
01278
01279 outfile << "\n";
01280 ++iFmap; i++;
01281 }
01282 outfile.close();
01283 }
01284
01285
01286 template <class FLOAT>
01287 void featureClusterVision<FLOAT>::fCVrunStandAloneMSBatchFilter(
01288 std::string filename)
01289 {
01290
01291 Timer tim;
01292 tim.reset();
01293 int t1,t2,t3;
01294 int t0 = tim.get();
01295 t1 = 0;
01296 t2 = t1 - t0;
01297
01298 const unsigned int scales = fCV_gaborScales;
01299 const bool useQuarter = fCV_gaborUseQuarter;
01300
01301 std::vector<PixH2SV2<FLOAT> > samples(fCV_countSM);
01302
01303
01304 fCV_standAloneFeatures.resize((scales*4),samples);
01305 fCV_standAloneFeaturesSin.resize((scales*4),samples);
01306 fCV_standAloneFeaturesCos.resize((scales*4),samples);
01307 fCV_mixedRotationH2SV2.resize(scales,samples);
01308
01309 t3 = t2;
01310 t1 = tim.get();
01311 t2 = t1 - t0;
01312 t3 = t2 - t3;
01313 std::cerr << "\t\t>>>>>>>> Set Up Data Structures TIME: "<< t2 << "ms "
01314 << " SLICE " << t3 << "ms\n";
01315
01316 const unsigned int count = fCV_countSM;
01317
01318 LINFO("COUNT %d %d",count,fCV_countSM);
01319
01320
01321
01322 multiScaleBatchFilter(&fCV_realImageH2SV2, &fCV_rmap, &count
01323 , &fCV_gaborFiltersSin, scales, useQuarter, true,
01324 &fCV_standAloneFeaturesSin);
01325 t3 = t2;
01326 t1 = tim.get();
01327 t2 = t1 - t0;
01328 t3 = t2 - t3;
01329 std::cerr << "\t\t>>>>>>>> Convolved Sin: "<< t2 << "ms "
01330 << " SLICE " << t3 << "ms\n";
01331 multiScaleBatchFilter(&fCV_realImageH2SV2, &fCV_rmap, &count
01332 , &fCV_gaborFiltersCos, scales, useQuarter, true,
01333 &fCV_standAloneFeaturesCos);
01334 t3 = t2;
01335 t1 = tim.get();
01336 t2 = t1 - t0;
01337 t3 = t2 - t3;
01338 std::cerr << "\t\t>>>>>>>> Convolved Cos: "<< t2 << "ms "
01339 << " SLICE " << t3 << "ms\n";
01340
01341
01342 for(unsigned int i = 0; i < fCV_standAloneFeatures.size(); i++)
01343 {
01344 for(unsigned int j = 0; j < fCV_standAloneFeatures[i].size(); j++)
01345 {
01346 fCV_standAloneFeatures[i][j].setH1(
01347 fabs(fCV_standAloneFeaturesSin[i][j].H1()) +
01348 fabs(fCV_standAloneFeaturesCos[i][j].H1()));
01349
01350 fCV_standAloneFeatures[i][j].setH2(
01351 fabs(fCV_standAloneFeaturesSin[i][j].H2()) +
01352 fabs(fCV_standAloneFeaturesCos[i][j].H2()));
01353
01354 fCV_standAloneFeatures[i][j].setS(
01355 fabs(fCV_standAloneFeaturesSin[i][j].S()) +
01356 fabs(fCV_standAloneFeaturesCos[i][j].S()));
01357
01358 fCV_standAloneFeatures[i][j].setV(
01359 fabs(fCV_standAloneFeaturesSin[i][j].V()) +
01360 fabs(fCV_standAloneFeaturesCos[i][j].V()));
01361
01362 }
01363 }
01364
01365 t3 = t2;
01366 t1 = tim.get();
01367 t2 = t1 - t0;
01368 t3 = t2 - t3;
01369 std::cerr << "\t\t>>>>>>>> Mixed Features TIME: "<< t2 << "ms "
01370 << " SLICE " << t3 << "ms\n";
01371
01372 multiScaleJunctionFilter(count, scales, &fCV_standAloneFeatures,
01373 &fCV_mixedRotationH2SV2);
01374
01375 t3 = t2;
01376 t1 = tim.get();
01377 t2 = t1 - t0;
01378 t3 = t2 - t3;
01379 std::cerr << "\t\t>>>>>>>> Junctions Mixed TIME: "<< t2 << "ms "
01380 << " SLICE " << t3 << "ms\n";
01381
01382 const std::string noutFile = filename + ".stand.alone.features.out.txt";
01383
01384 LINFO("WRITING %s", noutFile.c_str());
01385 std::ofstream outFile(noutFile.c_str(),std::ios::app);
01386 for(unsigned int j = 0; j < fCV_standAloneFeatures[0].size(); j++)
01387 {
01388 for(unsigned int i = 0; i < fCV_standAloneFeatures.size(); i++)
01389 {
01390 outFile << fCV_standAloneFeatures[i][j].H1() << "\t";
01391 outFile << fCV_standAloneFeatures[i][j].H2() << "\t";
01392 outFile << fCV_standAloneFeatures[i][j].S() << "\t";
01393 outFile << fCV_standAloneFeatures[i][j].V() << "\t";
01394 }
01395 outFile << "\n";
01396 }
01397
01398 const std::string noutFile2 = filename + ".stand.alone.junctions.out.txt";
01399
01400 LINFO("WRITING %s", noutFile2.c_str());
01401 std::ofstream outFile2(noutFile2.c_str(),std::ios::app);
01402 for(unsigned int j = 0; j < fCV_mixedRotationH2SV2[0].size(); j++)
01403 {
01404 for(unsigned int i = 0; i < fCV_mixedRotationH2SV2.size(); i++)
01405 {
01406 outFile2 << fCV_mixedRotationH2SV2[i][j].H1() << "\t";
01407 outFile2 << fCV_mixedRotationH2SV2[i][j].H2() << "\t";
01408 outFile2 << fCV_mixedRotationH2SV2[i][j].S() << "\t";
01409 outFile2 << fCV_mixedRotationH2SV2[i][j].V() << "\t";
01410 }
01411 outFile2 << "\n";
01412 }
01413
01414 t3 = t2;
01415 t1 = tim.get();
01416 t2 = t1 - t0;
01417 t3 = t2 - t3;
01418 std::cerr << "\t\t>>>>>>>> Features writen to file TIME: "<< t2 << "ms "
01419 << " SLICE " << t3 << "ms\n";
01420 }
01421
01422
01423 template <class FLOAT>
01424 void featureClusterVision<FLOAT>::fCVrunStandAloneMSBatchTest(
01425 std::string filename)
01426 {
01427 Timer tim;
01428 tim.reset();
01429 int t1,t2,t3;
01430 int t0 = tim.get();
01431 t1 = 0;
01432 t2 = t1 - t0;
01433
01434 const float gaborMasks[4] = {0.0F,45.0F,90.0F,135.0F};
01435 std::vector<std::string> gaborLabels(4,"");
01436 gaborLabels[0] = "0"; gaborLabels[1] = "45";
01437 gaborLabels[2] = "90"; gaborLabels[3] = "135";
01438 const FLOAT gaborSTD = fCV_gaborStandardDev;
01439 const FLOAT gaborPrd = fCV_gaborPeriod;
01440 const unsigned int scales = fCV_gaborScales;
01441 const bool useQuarter = fCV_gaborUseQuarter;
01442 LINFO("Gabor period %f std %f",gaborPrd,gaborSTD);
01443
01444
01445 readMatrix junctionMat("ICAunmix.junctions.new.6.dat");
01446 readMatrix junctionMatG("ICAunmix.junctions.new.G.dat");
01447 LINFO("read Matrix");
01448 Image<FLOAT> ICAMatrix = junctionMat.returnMatrixAsImage();
01449 Image<FLOAT> ICAMatrixG = junctionMatG.returnMatrixAsImage();
01450 LINFO("creating images");
01451 Image<FLOAT> junctionMatrix;
01452 Image<FLOAT> junctionMatrixG;
01453
01454 junctionMatrix.resize(4*scales,fCV_realImage.getHeight()*
01455 fCV_realImage.getWidth(),true);
01456 junctionMatrixG.resize(scales,fCV_realImage.getHeight()*
01457 fCV_realImage.getWidth(),true);
01458
01459 Image<FLOAT> reducedMatrix;
01460
01461 Image<FLOAT> reducedMatrixG;
01462
01463 std::vector<PixH2SV2<FLOAT> > samples(
01464 (unsigned)fCV_realImage.getWidth() *
01465 (unsigned)fCV_realImage.getHeight()
01466 ,PixH2SV2<FLOAT>(0.0F));
01467
01468
01469 fCV_standAloneFeatures.resize(scales*4,samples);
01470 fCV_mixedRotationH2SV2.resize(scales,samples);
01471
01472 const Image<FLOAT> blankImage;
01473
01474 std::vector<Image<FLOAT> > gaborFiltersSin(4,blankImage);
01475 std::vector<Image<FLOAT> > gaborFiltersCos(4,blankImage);
01476
01477 t3 = t2;
01478 t1 = tim.get();
01479 t2 = t1 - t0;
01480 t3 = t2 - t3;
01481 std::cerr << "\t\t>>>>>>>> Set Up Data Structures TIME: "<< t2 << "ms "
01482 << " SLICE " << t3 << "ms\n";
01483 unsigned int iii = 0;
01484 for(typename std::vector<Image<FLOAT> >::iterator igaborFilters
01485 = gaborFiltersSin.begin();
01486 igaborFilters != gaborFiltersSin.end(); ++igaborFilters, iii++)
01487 {
01488 *igaborFilters = gaborFilter<FLOAT>(gaborSTD,gaborPrd,0.0F
01489 ,gaborMasks[iii]);
01490 Raster::VisuFloat(*igaborFilters,FLOAT_NORM_0_255
01491 ,sformat("image.gabor.sin.%d.pgm",iii));
01492 }
01493
01494 iii = 0;
01495 for(typename std::vector<Image<FLOAT> >::iterator igaborFilters
01496 = gaborFiltersCos.begin();
01497 igaborFilters != gaborFiltersCos.end(); ++igaborFilters, iii++)
01498 {
01499 *igaborFilters = gaborFilter<FLOAT>(gaborSTD,gaborPrd,45.0F
01500 ,gaborMasks[iii]);
01501 Raster::VisuFloat(*igaborFilters,FLOAT_NORM_0_255
01502 ,sformat("image.gabor.cos.%d.pgm",iii));
01503 }
01504
01505 t3 = t2;
01506 t1 = tim.get();
01507 t2 = t1 - t0;
01508 t3 = t2 - t3;
01509 std::cerr << "\t\t>>>>>>>> Set Up Data Gabors TIME: "<< t2 << "ms "
01510 << " SLICE " << t3 << "ms\n";
01511 fCV_countSM = (fCV_realImage.getWidth()) *
01512 (fCV_realImage.getHeight());
01513 Point2D<int> tempP;
01514 Point2D<int> *tempPP = &tempP;
01515 fCV_cmap.resize(fCV_countSM,tempP);
01516 fCV_rmap.resize(fCV_countSM,tempPP);
01517
01518 std::vector<Point2D<int> >::iterator icmap = fCV_cmap.begin();
01519 std::vector<Point2D<int>*>::iterator irmap = fCV_rmap.begin();
01520 for(int j = 0; j < fCV_realImage.getHeight(); j++)
01521 {
01522 for(int i = 0; i < fCV_realImage.getWidth(); i++)
01523 {
01524 icmap->i = i;
01525 icmap->j = j;
01526 *irmap = &*icmap;
01527 ++icmap; ++irmap;
01528 }
01529 }
01530
01531 typename std::vector<std::vector<PixH2SV2<FLOAT> > > fSin;
01532 typename std::vector<std::vector<PixH2SV2<FLOAT> > > fCos;
01533
01534 typename std::vector<std::vector<FLOAT> > fSinG;
01535 typename std::vector<std::vector<FLOAT> > fCosG;
01536 typename std::vector<std::vector<FLOAT> > standAloneFeaturesG;
01537 typename std::vector<std::vector<FLOAT> > mixedRotationG;
01538
01539 fSin = fCV_standAloneFeatures;
01540 fCos = fCV_standAloneFeatures;
01541
01542 typename std::vector<FLOAT> tempG(fSin[0].size(),0.0F);
01543 fSinG.resize(fSin.size(),tempG);
01544 fCosG.resize(fSin.size(),tempG);
01545 standAloneFeaturesG.resize(fSin.size(),tempG);
01546
01547 typename std::vector<FLOAT> tempGM(fCV_mixedRotationH2SV2[0].size(),0.0F);
01548 mixedRotationG.resize(fCV_mixedRotationH2SV2.size(),tempGM);
01549
01550 Image<FLOAT> realImageG;
01551 realImageG.resize(fCV_realImageH2SV2.getWidth(),
01552 fCV_realImageH2SV2.getHeight(),true);
01553
01554 for(unsigned int i = 0; i < (unsigned)fCV_realImageH2SV2.getWidth(); i++)
01555 {
01556 for(unsigned int j = 0; j < (unsigned)fCV_realImageH2SV2.getHeight(); j++)
01557 {
01558 realImageG.setVal(i,j,(fCV_realImageH2SV2.getVal(i,j)).H1());
01559 }
01560 }
01561
01562 unsigned int count = fCV_countSM;
01563 LINFO("COUNT %d %d",count,fCV_countSM);
01564 LINFO("Scales %d",scales);
01565
01566 multiScaleBatchFilter(&fCV_realImageH2SV2, &fCV_rmap, &count
01567 , &gaborFiltersSin, scales, useQuarter, true,
01568 &fSin);
01569 multiScaleBatchFilter(&fCV_realImageH2SV2, &fCV_rmap, &count
01570 , &gaborFiltersCos, scales, useQuarter, true,
01571 &fCos);
01572
01573 multiScaleBatchFilter(&realImageG, &fCV_rmap, &count
01574 , &gaborFiltersSin, scales, useQuarter, true,
01575 &fSinG);
01576 multiScaleBatchFilter(&realImageG, &fCV_rmap, &count
01577 , &gaborFiltersCos, scales, useQuarter, true,
01578 &fCosG);
01579
01580
01581
01582 for(unsigned int i = 0; i < fCV_standAloneFeatures.size(); i++)
01583 {
01584 for(unsigned int j = 0; j < count; j++)
01585 {
01586 standAloneFeaturesG[i][j] = fabs(fSinG[i][j])
01587 + fabs(fCosG[i][j]);
01588
01589 fCV_standAloneFeatures[i][j].setH1(fabs(fCos[i][j].H1())
01590 + fabs(fSin[i][j].H1()));
01591 fCV_standAloneFeatures[i][j].setH2(fabs(fCos[i][j].H2())
01592 + fabs(fSin[i][j].H2()));
01593 fCV_standAloneFeatures[i][j].setS(fabs(fCos[i][j].S())
01594 + fabs(fSin[i][j].S()));
01595 fCV_standAloneFeatures[i][j].setV(fabs(fCos[i][j].V())
01596 + fabs(fSin[i][j].V()));
01597 }
01598 }
01599
01600 multiScaleJunctionFilter(count, scales, &fCV_standAloneFeatures
01601 ,&fCV_mixedRotationH2SV2);
01602
01603 multiScaleJunctionFilter(count, scales, &standAloneFeaturesG
01604 ,&mixedRotationG);
01605
01606 t3 = t2;
01607 t1 = tim.get();
01608 t2 = t1 - t0;
01609 t3 = t2 - t3;
01610 std::cerr << "\t\t>>>>>>>> Features Fetched TIME: "<< t2 << "ms "
01611 << " SLICE " << t3 << "ms\n";
01612
01613 const std::string noutFile = filename + ".stand.alone.features.out.txt";
01614
01615 LINFO("WRITING %s", noutFile.c_str());
01616 std::ofstream outFile(noutFile.c_str(),std::ios::app);
01617 Image<FLOAT> timageh1;
01618 Image<FLOAT> timageh2;
01619 Image<FLOAT> timages;
01620 Image<FLOAT> timagev;
01621
01622 timageh1.resize(fCV_realImageLowPass.getWidth(),
01623 fCV_realImageLowPass.getHeight());
01624 timageh2.resize(fCV_realImageLowPass.getWidth(),
01625 fCV_realImageLowPass.getHeight());
01626 timages.resize(fCV_realImageLowPass.getWidth(),
01627 fCV_realImageLowPass.getHeight());
01628 timagev.resize(fCV_realImageLowPass.getWidth(),
01629 fCV_realImageLowPass.getHeight());
01630
01631 for(unsigned int i = 0; i < fCV_standAloneFeatures.size(); i++)
01632 {
01633 typename Image<FLOAT>::iterator itimageh1 = timageh1.beginw();
01634 for(unsigned int j = 0; j < count; j++,
01635 ++itimageh1)
01636 {
01637 *itimageh1 = fCV_standAloneFeatures[i][j].H1();
01638 }
01639
01640 typename Image<FLOAT>::iterator itimageh2 = timageh2.beginw();
01641 for(unsigned int j = 0; j < count; j++,
01642 ++itimageh2)
01643 {
01644 *itimageh2 = fCV_standAloneFeatures[i][j].H2();
01645 }
01646
01647 typename Image<FLOAT>::iterator itimages = timages.beginw();
01648 for(unsigned int j = 0; j < count; j++,
01649 ++itimages)
01650 {
01651 *itimages = fCV_standAloneFeatures[i][j].S();
01652 }
01653
01654 typename Image<FLOAT>::iterator itimagev = timagev.beginw();
01655 for(unsigned int j = 0; j < count; j++,
01656 ++itimagev)
01657 {
01658 *itimagev = fCV_standAloneFeatures[i][j].V();
01659 }
01660
01661 Raster::VisuFloat(timageh1,FLOAT_NORM_0_255,sformat("imageOut.H1.%d.pgm",i));
01662 Raster::VisuFloat(timageh2,FLOAT_NORM_0_255,sformat("imageOut.H2.%d.pgm",i));
01663 Raster::VisuFloat(timages ,FLOAT_NORM_0_255,sformat("imageOut.S.%d.pgm" ,i));
01664 Raster::VisuFloat(timagev ,FLOAT_NORM_0_255,sformat("imageOut.V.%d.pgm" ,i));
01665 }
01666
01667 for(unsigned int i = 0; i < fCV_mixedRotationH2SV2.size(); i++)
01668 {
01669 typename Image<FLOAT>::iterator itimage = timageh1.beginw();
01670 for(unsigned int j = 0; j < fCV_standAloneFeatures[i].size(); j++,
01671 ++itimage)
01672 {
01673 *itimage = fCV_mixedRotationH2SV2[i][j].H1();
01674 }
01675
01676 itimage = timageh2.beginw();
01677 for(unsigned int j = 0; j < fCV_standAloneFeatures[i].size(); j++,
01678 ++itimage)
01679 {
01680 *itimage = fCV_mixedRotationH2SV2[i][j].H2();
01681 }
01682
01683 itimage = timages.beginw();
01684 for(unsigned int j = 0; j < fCV_standAloneFeatures[i].size(); j++,
01685 ++itimage)
01686 {
01687 *itimage = fCV_mixedRotationH2SV2[i][j].S();
01688 }
01689
01690 itimage = timagev.beginw();
01691 for(unsigned int j = 0; j < fCV_standAloneFeatures[i].size(); j++,
01692 ++itimage)
01693 {
01694 *itimage = fCV_mixedRotationH2SV2[i][j].V();
01695 }
01696
01697 Raster::VisuFloat(timageh1,FLOAT_NORM_0_255,sformat("imageOut.J.H1.%d.pgm",i));
01698 Raster::VisuFloat(timageh2,FLOAT_NORM_0_255,sformat("imageOut.J.H2.%d.pgm",i));
01699 Raster::VisuFloat(timages ,FLOAT_NORM_0_255,sformat("imageOut.J.S.%d.pgm" ,i));
01700 Raster::VisuFloat(timagev ,FLOAT_NORM_0_255,sformat("imageOut.J.V.%d.pgm" ,i));
01701 }
01702
01703
01704 unsigned int y = 0;
01705 for(unsigned int j = 0; j < fCV_mixedRotationH2SV2[0].size(); j++)
01706 {
01707 unsigned int x = 0;
01708 unsigned int w = 0;
01709 for(unsigned int i = 0; i < fCV_mixedRotationH2SV2.size(); i++)
01710 {
01711 junctionMatrixG.setVal(w,y,mixedRotationG[i][j]); w++;
01712 junctionMatrix.setVal(x,y,fCV_mixedRotationH2SV2[i][j].H1()); x++;
01713 junctionMatrix.setVal(x,y,fCV_mixedRotationH2SV2[i][j].H2()); x++;
01714 junctionMatrix.setVal(x,y,fCV_mixedRotationH2SV2[i][j].S()); x++;
01715 junctionMatrix.setVal(x,y,fCV_mixedRotationH2SV2[i][j].V()); x++;
01716 }
01717 y++;
01718 }
01719 LINFO("%d x %d",junctionMatrix.getWidth(),junctionMatrix.getHeight());
01720 LINFO("%d x %d",ICAMatrix.getWidth(),ICAMatrix.getHeight());
01721
01722 LINFO("%d x %d",junctionMatrixG.getWidth(),junctionMatrixG.getHeight());
01723 LINFO("%d x %d",ICAMatrixG.getWidth(),ICAMatrixG.getHeight());
01724
01725 reducedMatrix = matrixMult(junctionMatrix,ICAMatrix);
01726 reducedMatrixG = matrixMult(junctionMatrixG,ICAMatrixG);
01727 LINFO("%d x %d",reducedMatrix.getWidth(),reducedMatrix.getHeight());
01728
01729 for(unsigned int i = 0; i < (unsigned)reducedMatrix.getWidth(); i++)
01730 {
01731 Image<FLOAT> outImage;
01732 outImage.resize(fCV_realImageLowPass.getWidth(),
01733 fCV_realImageLowPass.getHeight(),true);
01734 typename Image<FLOAT>::iterator outImage_itr = outImage.beginw();
01735 for(unsigned int j = 0; j < (unsigned)reducedMatrix.getHeight(); j++,
01736 ++outImage_itr)
01737 {
01738 *outImage_itr = logsig(0.0F,0.25F,reducedMatrix.getVal(i,j));
01739 }
01740
01741 Raster::VisuFloat(outImage,FLOAT_NORM_0_255,sformat("imageOut.ICA.J.%d.pgm",i));
01742
01743 }
01744
01745 for(unsigned int i = 0; i < (unsigned)reducedMatrixG.getWidth(); i++)
01746 {
01747 Image<FLOAT> outImage;
01748 outImage.resize(fCV_realImageLowPass.getWidth(),
01749 fCV_realImageLowPass.getHeight(),true);
01750 typename Image<FLOAT>::iterator outImage_itr = outImage.beginw();
01751 for(unsigned int j = 0; j < (unsigned)reducedMatrixG.getHeight(); j++,
01752 ++outImage_itr)
01753 {
01754 *outImage_itr = reducedMatrixG.getVal(i,j);
01755 }
01756
01757 Raster::VisuFloat(outImage,FLOAT_NORM_0_255,sformat("imageOut.ICA.J.G.%d.pgm",i));
01758 }
01759
01760 t3 = t2;
01761 t1 = tim.get();
01762 t2 = t1 - t0;
01763 t3 = t2 - t3;
01764 std::cerr << "\t\t>>>>>>>> Features writen to file TIME: "<< t2 << "ms "
01765 << " SLICE " << t3 << "ms\n";
01766
01767 }
01768
01769
01770 template <class FLOAT>
01771 void featureClusterVision<FLOAT>::fCVICAfeaturesToFile(std::string fileName)
01772 {
01773 std::string newFile;
01774 newFile = fileName + ".out.ICA";
01775 std::ofstream outfile(newFile.c_str(),std::ios::app);
01776 typename std::vector<std::vector<FLOAT> >::iterator ispace;
01777 typename std::vector<FLOAT>::iterator iispace;
01778 ispace = fCV_space.begin();
01779 for(int i = 0; i < fCV_countSM; i++, ++ispace)
01780 {
01781 for(iispace = ispace->begin(); iispace != ispace->end(); ++iispace)
01782 outfile << *iispace << "\t";
01783
01784 outfile << "\n";
01785 }
01786 outfile.close();
01787 }
01788
01789
01790
01791
01792
01793
01794 template <class FLOAT>
01795 void featureClusterVision<FLOAT>::fCVswitchCov()
01796 {
01797
01798
01799
01800 fCV_covHolderLast = fCV_covHolderCurrent;
01801 if(fCV_currentCovHolder == COVHOLDER-1)
01802 {
01803 fCV_currentCovHolder = 0;
01804 }
01805 else
01806 {
01807 fCV_currentCovHolder++;
01808 }
01809 fCV_covHolderCurrent = &fCV_covHolder[fCV_currentCovHolder];
01810
01811 for(unsigned long i = 0; i < fCV_covHolderCurrent->size(); i++)
01812 {
01813 fCV_covHolderCurrent->at(i).isLarge = false;
01814 }
01815 fCV_covDataSizeLast = fCV_covDataSizeCurrent;
01816 fCV_covDataSizeCurrent = 0;
01817
01818 }
01819
01820
01821 template <class FLOAT>
01822 void featureClusterVision<FLOAT>::fCVlowPass()
01823 {
01824 if(fCV_lowPassType != 0)
01825 {
01826 std::cerr << "LOW PASSING IMAGE " << fCV_lowPassType << "\n";
01827 if(fCV_lowPassType == 1)
01828 fCV_realImageLowPass = lowPass3(fCV_realImage);
01829 else if(fCV_lowPassType == 2)
01830 fCV_realImageLowPass = lowPass5(fCV_realImage);
01831 else if(fCV_lowPassType == 3)
01832 fCV_realImageLowPass = lowPass9(fCV_realImage);
01833 else if(fCV_lowPassType > 3)
01834 fCV_realImageLowPass = fCV_realImage;
01835 }
01836 else
01837 fCV_realImageLowPass = fCV_realImage;
01838 fCV_realImageH2SV2 = fCV_realImage;
01839 fCV_realImageH2SV2LowPass = fCV_realImageLowPass;
01840
01841
01842 }
01843
01844
01845 template <class FLOAT>
01846 void featureClusterVision<FLOAT>::fCVfindFeaturesBrain()
01847 {
01848 Timer tim;
01849 tim.reset();
01850 int t1,t2,t3;
01851 t2 = 0;
01852 int t0 = tim.get();
01853
01854
01855
01856
01857
01858
01859 Image<FLOAT> salmap;
01860 LFATAL("FIXME");
01861 Image<FLOAT> salmapOut = salmap;
01862
01863
01864 if(fCV_doSLPTB == true)
01865 {
01866 fCV_salmapLowPass = ((fCV_salmapLowPass*fCV_salmapLowPassTemporalBias) +
01867 salmap)/(1.0F +fCV_salmapLowPassTemporalBias);
01868 }
01869 else
01870 {
01871 fCV_salmapLowPass = salmap;
01872 fCV_doSLPTB = true;
01873 }
01874
01875 t3 = t2;
01876 t1 = tim.get();
01877 t2 = t1 - t0;
01878 t3 = t2 - t3;
01879 std::cerr << "\t\t>>>>>>>> findFeatures lowPass init TIME: "<< t2 << "ms "
01880 << " SLICE " << t3 << "ms\n";
01881
01882 LINFO("Salmap size %d x %d to %d x %d",salmap.getWidth()
01883 ,salmap.getHeight(),fCV_sizeX,fCV_sizeY);
01884 salmap = rescaleBilinear(fCV_salmapLowPass,fCV_sizeX/3,fCV_sizeY/3);
01885
01886
01887
01888
01889 ASSERT(salmap.getSize() <= (signed)fCV_cmap.size());
01890
01891
01892
01893 Image<FLOAT> smap = salmap;
01894
01895
01896 Image<FLOAT> fooshit = rescaleBilinear(fCV_salmapLowPass,fCV_sizeX,fCV_sizeY);
01897
01898
01899
01900 fCV_monteDec = 0;
01901 std::vector<Point2D<int>*>::iterator irmap = fCV_rmap.begin();
01902 std::vector<Point2D<int> >::iterator icmapOld = fCV_cmapOld.begin();
01903
01904 for(int i = 0; i < fCV_countSM; i++, ++irmap, ++icmapOld)
01905 {
01906 *icmapOld = **irmap/3;
01907 }
01908 t3 = t2;
01909 t1 = tim.get();
01910 t2 = t1 - t0;
01911 t3 = t2 - t3;
01912 std::cerr << "\t\t>>>>>>>> findFeatures set params TIME: "<< t2 << "ms "
01913 << " SLICE " << t3 << "ms\n";
01914 fCV_countMM = findMonteMap(smap,&fCV_cmap,
01915 fCV_monteDec,fCV_saliencyExp);
01916
01917
01918
01919
01920 t3 = t2;
01921 t1 = tim.get();
01922 t2 = t1 - t0;
01923 t3 = t2 - t3;
01924 std::cerr << "\t\t>>>>>>>> findFeatures find monte map TIME: "<< t2 << "ms "
01925 << " SLICE " << t3 << "ms\n";
01926
01927
01928 fCV_countSM = makeSparceMap(&fCV_cmap, &fCV_rmap, &fCV_cmapOld,
01929 &fCV_keepParticle,
01930 fCV_countMM, fCV_sparcePoints);
01931 t3 = t2;
01932 t1 = tim.get();
01933 t2 = t1 - t0;
01934 t3 = t2 - t3;
01935 std::cerr << "\t\t>>>>>>>> findFeatures find sparce map TIME: "<< t2 << "ms "
01936 << " SLICE " << t3 << "ms\n";
01937
01938 irmap = fCV_rmap.begin();
01939 for(int i = 0; i < fCV_countSM; i++, ++irmap, ++icmapOld)
01940 {
01941
01942
01943
01944 (*irmap)->i = (*irmap)->i * 3;
01945 (*irmap)->j = (*irmap)->j * 3;
01946
01947
01948 }
01949
01950 t3 = t2;
01951 t1 = tim.get();
01952 t2 = t1 - t0;
01953 t3 = t2 - t3;
01954 std::cerr << "\t\t>>>>>>>> findFeatures expand map TIME: "<< t2 << "ms "
01955 << " SLICE " << t3 << "ms\n";
01956
01957 irmap = fCV_rmap.begin();
01958 typename std::vector<FLOAT> emptyVec(1,0.0F);
01959 typename std::vector<std::vector<FLOAT> > tempEmpty(fCV_countSM,emptyVec);
01960 fCV_fmap = tempEmpty;
01961
01962
01963
01964 if(fCV_lowPassType == 5)
01965 {
01966 if(fCV_lowPassVector.size() < fCV_rmap.size())
01967 {
01968 PixRGB<FLOAT> tempish;
01969 fCV_lowPassVector.resize(fCV_rmap.size(),tempish);
01970 }
01971
01972
01973
01974 filterAtLocationBatch(&fCV_realImageLowPass,&fCV_lowPassKernel, &fCV_rmap,
01975 &fCV_lowPassVector,fCV_countSM);
01976 }
01977 t3 = t2;
01978 t1 = tim.get();
01979 t2 = t1 - t0;
01980 t3 = t2 - t3;
01981 std::cerr << "\t\t>>>>>>>> findFeatures lowPass batch TIME: "<< t2 << "ms "
01982 << " SLICE " << t3 << "ms\n";
01983
01984
01985 t3 = t2;
01986 t1 = tim.get();
01987 t2 = t1 - t0;
01988 t3 = t2 - t3;
01989 std::cerr << "\t\t>>>>>>>> findFeatures get features TIME: "<< t2 << "ms "
01990 << " SLICE " << t3 << "ms\n";
01991
01992 }
01993
01994
01995 template <class FLOAT>
01996 void featureClusterVision<FLOAT>::fCVfindFeaturesNoBrain()
01997 {
01998 Timer tim;
01999 tim.reset();
02000 int t1,t2,t3;
02001 t2 = 0; t3 = 0;
02002 int t0 = tim.get();
02003
02004
02005
02006
02007
02008
02009 if(fCV_doSLPTB == true)
02010 {
02011 fCV_salmapLowPass = ((fCV_salmapLowPass*fCV_salmapLowPassTemporalBias) +
02012 *fCV_noBrainSalmap)
02013 /(1.0F +fCV_salmapLowPassTemporalBias);
02014 }
02015 else
02016 {
02017 fCV_salmapLowPass = *fCV_noBrainSalmap;
02018 fCV_doSLPTB = true;
02019 }
02020
02021 t1 = tim.get();
02022 t2 = t1 - t0;
02023 t3 = t2 - t3;
02024 std::cerr << "\t\t>>>>>>>> findFeatures lowPass init TIME: "<< t2 << "ms "
02025 << " SLICE " << t3 << "ms\n";
02026
02027 LINFO("Salmap size %d x %d to %d x %d",fCV_noBrainSalmap->getWidth()
02028 ,fCV_noBrainSalmap->getHeight(),fCV_sizeX,fCV_sizeY);
02029 Image<FLOAT> salmap = rescaleBilinear(fCV_salmapLowPass,fCV_sizeX/3,fCV_sizeY/3);
02030
02031
02032
02033
02034 ASSERT(salmap.getSize() <= (signed)fCV_cmap.size());
02035
02036
02037
02038 Image<FLOAT> smap = salmap;
02039
02040
02041
02042 fCV_monteDec = 0;
02043 std::vector<Point2D<int>*>::iterator irmap = fCV_rmap.begin();
02044 std::vector<Point2D<int> >::iterator icmapOld = fCV_cmapOld.begin();
02045
02046 for(int i = 0; i < fCV_countSM; i++, ++irmap, ++icmapOld)
02047 {
02048 *icmapOld = **irmap/3;
02049 }
02050 t3 = t2;
02051 t1 = tim.get();
02052 t2 = t1 - t0;
02053 t3 = t2 - t3;
02054 std::cerr << "\t\t>>>>>>>> findFeatures set params TIME: "<< t2 << "ms "
02055 << " SLICE " << t3 << "ms\n";
02056 fCV_countMM = findMonteMap(smap,&fCV_cmap,
02057 fCV_monteDec,fCV_saliencyExp);
02058
02059
02060
02061
02062 t3 = t2;
02063 t1 = tim.get();
02064 t2 = t1 - t0;
02065 t3 = t2 - t3;
02066 std::cerr << "\t\t>>>>>>>> findFeatures find monte map TIME: "<< t2 << "ms "
02067 << " SLICE " << t3 << "ms\n";
02068
02069
02070 fCV_countSM = makeSparceMap(&fCV_cmap, &fCV_rmap, &fCV_cmapOld,
02071 &fCV_keepParticle,
02072 fCV_countMM, fCV_sparcePoints);
02073 t3 = t2;
02074 t1 = tim.get();
02075 t2 = t1 - t0;
02076 t3 = t2 - t3;
02077 std::cerr << "\t\t>>>>>>>> findFeatures find sparce map TIME: "<< t2 << "ms "
02078 << " SLICE " << t3 << "ms\n";
02079
02080 irmap = fCV_rmap.begin();
02081 for(int i = 0; i < fCV_countSM; i++, ++irmap, ++icmapOld)
02082 {
02083
02084
02085
02086 (*irmap)->i = (*irmap)->i * 3;
02087 (*irmap)->j = (*irmap)->j * 3;
02088
02089
02090 }
02091
02092 t3 = t2;
02093 t1 = tim.get();
02094 t2 = t1 - t0;
02095 t3 = t2 - t3;
02096 std::cerr << "\t\t>>>>>>>> findFeatures expand map TIME: "<< t2 << "ms "
02097 << " SLICE " << t3 << "ms\n";
02098
02099
02100 typename std::vector<FLOAT> cmaps(fCV_cmaps->size(),0.0F);
02101 typename std::vector<std::vector<FLOAT> > tempEmpty(fCV_countSM,cmaps);
02102 fCV_fmap = tempEmpty;
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114
02115
02116
02117 t3 = t2;
02118 t1 = tim.get();
02119 t2 = t1 - t0;
02120 t3 = t2 - t3;
02121 std::cerr << "\t\t>>>>>>>> findFeatures lowPass batch TIME: "<< t2 << "ms "
02122 << " SLICE " << t3 << "ms\n";
02123
02124 irmap = fCV_rmap.begin();
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134 t3 = t2;
02135 t1 = tim.get();
02136 t2 = t1 - t0;
02137 t3 = t2 - t3;
02138 std::cerr << "\t\t>>>>>>>> findFeatures get features TIME: "<< t2 << "ms "
02139 << " SLICE " << t3 << "ms\n";
02140
02141 }
02142
02143
02144 template <class FLOAT>
02145 void featureClusterVision<FLOAT>::fCVfindFeaturesFromFile(std::string fileName)
02146 {
02147 ASSERT(fCV_useBrain == true);
02148
02149
02150
02151
02152
02153
02154 Image<FLOAT> salmap;
02155 LFATAL("FIXME");
02156 Image<FLOAT> salmapOut = salmap;
02157
02158
02159 if(fCV_doSLPTB == true)
02160 {
02161 fCV_salmapLowPass = ((fCV_salmapLowPass*fCV_salmapLowPassTemporalBias) +
02162 salmap)/(1.0F +fCV_salmapLowPassTemporalBias);
02163 }
02164 else
02165 {
02166 fCV_salmapLowPass = salmap;
02167 fCV_doSLPTB = true;
02168 }
02169
02170
02171 ASSERT(salmap.getSize() <= (signed)fCV_cmap.size());
02172
02173
02174
02175
02176
02177
02178 std::string in;
02179 std::ifstream saccadeFile(fileName.c_str(),std::ios::in);
02180 std::string values[7];
02181 unsigned int count = 0;
02182 unsigned int sampleNumber = 0;
02183 unsigned int indexNumber = 0;
02184 Point2D<int> point;
02185 Point2D<int> *pointer;
02186 pointer = &point;
02187 int tensions = 0;
02188 fCV_indexNumber.resize(fCV_cmap.size(),tensions);
02189 fCV_jumpTo.resize(fCV_cmap.size(),point);
02190 while(saccadeFile >> in)
02191 {
02192 values[count] = in;
02193 if(count == 6)
02194 {
02195 count = 0;
02196
02197
02198
02199
02200
02201
02202
02203 if((int)atof(values[2].c_str()) != 0)
02204 {
02205 if(fCV_cmap.size() == sampleNumber)
02206 {
02207 fCV_cmap.resize(fCV_cmap.size() + VEC_RESIZE,point);
02208 fCV_rmap.resize(fCV_cmap.size() + VEC_RESIZE,pointer);
02209 fCV_indexNumber.resize(fCV_cmap.size() + VEC_RESIZE,tensions);
02210 fCV_jumpTo.resize(fCV_cmap.size() + VEC_RESIZE,point);
02211 }
02212 fCV_cmap[sampleNumber].i = (int)atof(values[0].c_str());
02213 fCV_cmap[sampleNumber].j =
02214 (int)atof(values[1].c_str()) - STUPIDMASKOFFSET/2;
02215
02216 fCV_rmap[sampleNumber] = &fCV_cmap[sampleNumber];
02217 fCV_indexNumber[sampleNumber] = indexNumber;
02218 fCV_jumpTo[sampleNumber].i = (int)atof(values[3].c_str());
02219 fCV_jumpTo[sampleNumber].j =
02220 (int)atof(values[4].c_str()) - STUPIDMASKOFFSET/2;
02221 sampleNumber++;
02222 }
02223 indexNumber++;
02224 }
02225 else
02226 {
02227 count++;
02228 }
02229 }
02230
02231
02232 LINFO("FOUND %d samples from %s",sampleNumber,fileName.c_str());
02233 fCV_countSM = sampleNumber;
02234
02235
02236 fCVresizeMaps1(sampleNumber);
02237 fCVresizeMaps2(sampleNumber,fCV_newMatSize);
02238 for(unsigned int i = 0; i < (unsigned)fCV_countSM; i++)
02239 {
02240 if(fCV_rmap[i]->i >= fCV_sizeX) fCV_rmap[i]->i = fCV_sizeX-1;
02241 if(fCV_rmap[i]->j >= fCV_sizeY) fCV_rmap[i]->j = fCV_sizeY-1;
02242 if(fCV_jumpTo[i].i >= fCV_sizeX) fCV_jumpTo[i].i = fCV_sizeX-1;
02243 if(fCV_jumpTo[i].j >= fCV_sizeY) fCV_jumpTo[i].j = fCV_sizeY-1;
02244
02245 }
02246 typename std::vector<FLOAT> emptyVec(1,0.0F);
02247 typename std::vector<std::vector<FLOAT> > tempEmpty(fCV_countSM,emptyVec);
02248 fCV_fmap = tempEmpty;
02249
02250
02251
02252 }
02253
02254
02255 template <class FLOAT>
02256 void featureClusterVision<FLOAT>::fCVrunICA()
02257 {
02258
02259
02260
02261
02262 typename std::vector<Image<FLOAT> >::iterator image_itr;
02263 typename std::vector<Image<FLOAT> >::iterator unmixed_itr;
02264 typename std::vector<std::vector<FLOAT*> >::iterator unmixedMap_itr;
02265 typename std::vector<std::vector<FLOAT> >::iterator finalMap_itr;
02266 typename std::vector<std::vector<FLOAT> >::iterator space_itr;
02267 typename std::vector<FLOAT>::iterator space_itr_itr;
02268 typename std::vector<FLOAT*>::iterator weight_itr;
02269 typename std::vector<FLOAT>::iterator normalize_itr;
02270 typename std::vector<FLOAT>::iterator trans_itr;
02271 std::vector<int>::iterator index_itr;
02272 std::vector<int*>::iterator fpc_itr;
02273 typename Image<FLOAT>::iterator i_itr;
02274 std::vector<bool*>::iterator featureOn_itr;
02275 std::vector<std::string*>::iterator featureNameICA_itr;
02276
02277 unmixedMap_itr = fCV_unmixedMap.begin();
02278 unmixed_itr = fCV_Unmixed.begin();
02279 space_itr = fCV_space.begin();
02280 featureOn_itr = fCV_featureOn.begin();
02281 weight_itr = fCV_weights.begin();
02282 normalize_itr = fCV_featureNormConst.begin();
02283 trans_itr = fCV_featureTransConst.begin();
02284 fpc_itr = fCV_ICAfeaturesPerChannel.begin();
02285 featureNameICA_itr = fCV_featureNameICA.begin();
02286
02287 ASSERT(fCV_Unmixed.size() == fCV_featureMatrixSizes.size());
02288 ASSERT(fCV_Unmixed.size() == fCV_ICAunmix.size());
02289
02290
02291
02292 Image<FLOAT> ifmap = vectorToImage(fCV_fmap);
02293 Image<FLOAT> mmmap = vectorToImage(fCV_mixedRotation);
02294 Image<FLOAT> mmap = transpose(mmmap);
02295
02296
02297
02298
02299
02300
02301
02302
02303 unsigned int pStart = 0; unsigned int pStop = 0;
02304 unsigned int zero = 0;
02305 unsigned int sm = (unsigned)fCV_countSM;
02306
02307
02308 int current = 0;
02309 int iter = 0;
02310 long colorOffset = 0;
02311
02312
02313
02314
02315 for(image_itr = fCV_ICAunmix.begin(); image_itr != fCV_ICAunmix.end();
02316 ++image_itr, ++unmixed_itr, ++featureOn_itr, ++weight_itr, ++fpc_itr,
02317 ++normalize_itr, ++trans_itr, iter++)
02318 {
02319 bool doThis = false;
02320 unsigned int width = 0;
02321 unsigned int ICAwidth = 0;
02322 FLOAT translate = 0.0F;
02323 FLOAT normalize = 0.0F;
02324 FLOAT weight = 0.0F;
02325 pStop = pStart + (fCV_featuresPerChannel-1);
02326 if(iter < fCV_mixOffset)
02327 {
02328 width = (unsigned)image_itr->getWidth();
02329
02330
02331
02332
02333
02334
02335
02336 }
02337 else
02338 {
02339 width = (unsigned)(image_itr-1)->getWidth();
02340
02341
02342
02343
02344
02345
02346
02347 }
02348
02349 if(**featureOn_itr == true)
02350 {
02351 if(iter < fCV_mixOffset)
02352 {
02353
02354
02355 *unmixed_itr = matrixMult(ifmap,*image_itr,pStart,pStop,
02356 zero,width,zero,sm);
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366
02367
02368 colorOffset += unmixed_itr->getWidth();
02369 for(int i = 0; i < unmixed_itr->getWidth(); i++)
02370 {
02371 *featureNameICA_itr = &fCV_featureName[iter];
02372 ++featureNameICA_itr;
02373 }
02374 doThis = true;
02375 ICAwidth = unmixed_itr->getWidth();
02376 translate = *trans_itr;
02377 normalize = *normalize_itr;
02378 weight = **weight_itr;
02379
02380 }
02381 else
02382 {
02383 if((iter <= fCV_mixOffset+3) && (iter != fCV_mixOffset))
02384 {
02385
02386
02387 unsigned int st = fCV_featuresPerChannel*(iter-fCV_mixOffset-1);
02388 unsigned int sp = st + (fCV_featuresPerChannel-1);
02389
02390
02391
02392 *unmixed_itr = matrixMult(mmap,*(image_itr-1),st,sp,
02393 zero,width,zero,sm);
02394
02395
02396
02397
02398
02399
02400
02401
02402
02403
02404
02405 colorOffset += unmixed_itr->getWidth();
02406 for(int i = 0; i < unmixed_itr->getWidth(); i++)
02407 {
02408 *featureNameICA_itr = &fCV_featureName[iter];
02409 ++featureNameICA_itr;
02410 }
02411 doThis = true;
02412 ICAwidth = unmixed_itr->getWidth();
02413 translate = *(trans_itr);
02414 normalize = *(normalize_itr);
02415 weight = **(weight_itr);
02416
02417 }
02418 else if((iter <= fCV_motionCombinedOffset) && (iter != fCV_mixOffset))
02419 {
02420
02421
02422
02423 unsigned int st = fCV_motOffset*fCV_featuresPerChannel;
02424 unsigned int sp = st + ((fCV_featuresPerChannel*4)-1);
02425
02426 *unmixed_itr = matrixMult(ifmap,*(image_itr-1),st,sp,
02427 zero,width,zero,sm);
02428
02429 *unmixed_itr = logSig(*unmixed_itr,*(trans_itr),*(normalize_itr));
02430
02431 colorOffset += unmixed_itr->getWidth();
02432
02433
02434
02435
02436
02437
02438
02439
02440
02441
02442
02443 for(int i = 0; i < unmixed_itr->getWidth(); i++)
02444 {
02445 *featureNameICA_itr = &fCV_featureName[iter];
02446 ++featureNameICA_itr;
02447 }
02448 doThis = true;
02449 ICAwidth = unmixed_itr->getWidth();
02450 translate = 0;
02451 normalize = 1;
02452 weight = **(weight_itr);
02453
02454 }
02455 else
02456 {
02457
02458 }
02459 }
02460
02461
02462
02463
02464
02465 }
02466 else
02467 {
02468
02469 }
02470 pStart = pStop + 1;
02471
02472
02473
02474 if(doThis == true)
02475 {
02476
02477
02478 space_itr = fCV_space.begin();
02479 i_itr = unmixed_itr->beginw();
02480
02481
02482
02483 while(i_itr != unmixed_itr->endw())
02484 {
02485 space_itr_itr = space_itr->begin() + current;
02486 for(int j = 0; j < unmixed_itr->getWidth(); j++, ++space_itr_itr
02487 , ++i_itr)
02488 {
02489 *space_itr_itr = (*i_itr+translate)
02490 * weight * normalize;
02491 }
02492 ++space_itr;
02493 }
02494
02495
02496 current += ICAwidth;
02497
02498
02499 }
02500 }
02501
02502
02503 if((fCV_redOn == true) || (fCV_greenOn == true) ||
02504 (fCV_blueOn == true) || (fCV_yellowOn == true) ||
02505 (fCV_hueOn == true) || (fCV_satOn == true) ||
02506 (fCV_valOn == true))
02507 {
02508
02509 PixRGB<FLOAT> pix;
02510 space_itr = fCV_space.begin();
02511
02512
02513 if(fCV_redOn == true)
02514 {
02515 *featureNameICA_itr = &fCV_featureName[fCV_colorOffset];
02516
02517
02518 ++featureNameICA_itr;
02519
02520 }
02521 if(fCV_greenOn == true)
02522 {
02523 *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+1];
02524
02525
02526 ++featureNameICA_itr;
02527 }
02528 if(fCV_blueOn == true)
02529 {
02530 *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+2];
02531
02532
02533 ++featureNameICA_itr;
02534 }
02535 if(fCV_yellowOn == true)
02536 {
02537 *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+3];
02538
02539
02540 ++featureNameICA_itr;
02541 }
02542 if(fCV_hueOn == true)
02543 {
02544 *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+4];
02545
02546
02547 ++featureNameICA_itr;
02548 }
02549 if(fCV_satOn == true)
02550 {
02551 *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+5];
02552
02553
02554 ++featureNameICA_itr;
02555 }
02556 if(fCV_valOn == true)
02557 {
02558 *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+6];
02559
02560
02561 ++featureNameICA_itr;
02562 }
02563 if(fCV_hue1On == true)
02564 {
02565 *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+7];
02566
02567
02568 ++featureNameICA_itr;
02569 }
02570 if(fCV_hue2On == true)
02571 {
02572 *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+8];
02573
02574
02575 ++featureNameICA_itr;
02576 }
02577
02578 if(fCV_lowPassType == 5)
02579 {
02580 if(fCV_lowPassVector.size() < fCV_rmap.size())
02581 {
02582 PixRGB<FLOAT> tempish;
02583 fCV_lowPassVector.resize(fCV_rmap.size(),tempish);
02584 }
02585 filterAtLocationBatch(&fCV_realImageLowPass,&fCV_lowPassKernel,
02586 &fCV_rmap,
02587 &fCV_lowPassVector,fCV_countSM);
02588 }
02589 for(int i = 0; i < fCV_countSM; i++, ++space_itr)
02590 {
02591
02592
02593 if(fCV_lowPassType == 5)
02594 {
02595 pix = fCV_lowPassVector[i];
02596
02597 }
02598 else if(fCV_lowPassType == 4)
02599 pix = filterAtLocation(&fCV_realImageLowPass,&fCV_lowPassKernel,
02600 &*fCV_rmap[i]);
02601 else
02602 pix = fCV_realImageLowPass.getVal(fCV_rmap[i]->i,fCV_rmap[i]->j);
02603
02604 space_itr_itr = space_itr->begin() + colorOffset;
02605
02606 if(fCV_redOn == true)
02607 {
02608 *space_itr_itr = ((pix.red()+(*fCV_redTrans))*(*fCV_redNorm))
02609 * fCV_redWeight;
02610 ++space_itr_itr;
02611 }
02612 if(fCV_greenOn == true)
02613 {
02614 *space_itr_itr = ((pix.green()+(*fCV_greenTrans))*(*fCV_greenNorm))
02615 * fCV_greenWeight;
02616 ++space_itr_itr;
02617 }
02618 if(fCV_blueOn == true)
02619 {
02620 *space_itr_itr = ((pix.blue()+(*fCV_blueTrans))*(*fCV_blueNorm))
02621 * fCV_blueWeight;
02622 ++space_itr_itr;
02623 }
02624 if(fCV_yellowOn == true)
02625 {
02626 *space_itr_itr = (((((pix.red() + pix.green()) -
02627 fabs(pix.red() - pix.green()))/2.0F)
02628 +(*fCV_yellowTrans))
02629 *(*fCV_yellowNorm))
02630 * fCV_yellowWeight;
02631 ++space_itr_itr;
02632 }
02633
02634 FLOAT pixH = 0, pixS, pixV;
02635 FLOAT pixH1 = 0, pixH2 = 0;
02636
02637 if(fCV_hueOn == true)
02638 PixHSV<FLOAT>(pix).getHSV(pixH,pixS,pixV);
02639 else
02640 pix.getHSV(pixH1,pixH2,pixS,pixV);
02641
02642
02643 if(fCV_hueOn == true)
02644 {
02645 *space_itr_itr = ((pixH+(*fCV_hueTrans))*(*fCV_hueNorm))
02646 * fCV_hueWeight;
02647 ++space_itr_itr;
02648 }
02649 if(fCV_satOn == true)
02650 {
02651 *space_itr_itr = ((pixS+(*fCV_satTrans))*(*fCV_satNorm))
02652 * fCV_satWeight;
02653 ++space_itr_itr;
02654 }
02655 if(fCV_valOn == true)
02656 {
02657 *space_itr_itr = ((pixV+(*fCV_valTrans))*(*fCV_valNorm))
02658 * fCV_valWeight;
02659 ++space_itr_itr;
02660 }
02661 if(fCV_hue1On == true)
02662 {
02663 *space_itr_itr = ((pixH1+(*fCV_hue1Trans))*(*fCV_hue1Norm))
02664 * fCV_hue1Weight;
02665 ++space_itr_itr;
02666 }
02667 if(fCV_hue2On == true)
02668 {
02669 *space_itr_itr = ((pixH2+(*fCV_hue2Trans))*(*fCV_hue2Norm))
02670 * fCV_hue2Weight;
02671 ++space_itr_itr;
02672 }
02673 }
02674
02675 }
02676
02677
02678 if(fCV_spatialOn == true)
02679 {
02680
02681
02682
02683
02684
02685
02686
02687 space_itr = fCV_space.begin();
02688 *featureNameICA_itr = &fCV_featureName[fCV_spatOffset];
02689 fCV_featureNormConst[fCV_featureNormConst.size() - 2] =
02690 fCV_sizeXbias;
02691 fCV_featureNormConst[fCV_featureNormConst.size() - 1] =
02692 fCV_sizeYbias;
02693 ++featureNameICA_itr;
02694
02695 *featureNameICA_itr = &fCV_featureName[fCV_spatOffset];
02696 for(int i = 0; i < fCV_countSM; i++, ++space_itr)
02697 {
02698 space_itr_itr = space_itr->begin() + fCV_space[0].size() - 2;
02699 *space_itr_itr = ((fCV_rmap[i]->i)
02700 /(FLOAT)fCV_sizeX)*fCV_spatialWeight*fCV_sizeXbias;
02701
02702 space_itr_itr = space_itr->begin() + fCV_space[0].size() - 1;
02703 *space_itr_itr = ((fCV_rmap[i]->j)
02704 /(FLOAT)fCV_sizeY)*fCV_spatialWeight*fCV_sizeYbias;
02705
02706 }
02707 }
02708
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721 }
02722
02723
02724 template <class FLOAT>
02725 void featureClusterVision<FLOAT>::fCVrunNPclassify()
02726 {
02727
02728
02729
02730
02731 fCV_NP.NPresetSpace(fCV_countSM,(fCV_space[0].size()));
02732
02733 fCV_NP.NPaddSpace(fCV_space);
02734
02735
02736 if(fCV_doNPbias == true)
02737 if(fCV_NPtemporalBias != 0.0F)
02738 fCV_NP.NPsetConvolveBias(fCV_covHolderLast,fCV_covDataSizeLast
02739 ,fCV_NPtemporalBias);
02740
02741 fCV_NP.NPclassifySpaceNew(fCV_doNPbias);
02742 if(DUMPNP == true)
02743 fCV_NP.NPdumpLinkInfo(fCV_fileName);
02744
02745 std::vector<std::vector<int*> >* foo;
02746 foo = fCV_NP.NPgetClass();
02747 fCV_classList = foo;
02748 fCV_doNPbias = true;
02749
02750
02751
02752 }
02753
02754
02755 template <class FLOAT>
02756 void featureClusterVision<FLOAT>::fCVrunCovEstimate()
02757 {
02758
02759
02760
02761 for(int i = 0; i < fCV_NP.NPgetStemNumber(); i++)
02762 {
02763 if(fCV_NP.NPgetClassSize(i) > fCV_NP.NPgetMinClassSize())
02764 {
02765
02766 for(int j = 0; j < fCV_NP.NPgetClassSize(i); j++)
02767 {
02768 for(int k = 0; k < (signed)fCV_space[0].size(); k++)
02769 {
02770
02771
02772
02773
02774
02775
02776 fCV_sortedSpace[i][k][j] = &fCV_space[*fCV_classList->at(i)[j]][k];
02777
02778 }
02779 }
02780 if(fCV_covDataSizeCurrent == fCV_covHolderCurrent->size())
02781 {
02782 fCV_covHolderCurrent->resize(fCV_covHolderCurrent->size()+COVSIZE
02783 ,fCV_tcov);
02784 }
02785
02786
02787 fCV_covHolderCurrent->at(fCV_covDataSizeCurrent).isLarge = true;
02788 fCV_CV.setNewF(fCV_sortedSpace[i],
02789 0.0F,fCV_NP.NPgetClassSize(i)
02790 ,(signed)fCV_space[0].size(),
02791 fCV_covHolderCurrent->at(fCV_covDataSizeCurrent),
02792 false);
02793 fCV_covHolderCurrent->at(fCV_covDataSizeCurrent).baseID = i;
02794 fCV_covDataSizeCurrent++;
02795
02796
02797
02798 fCV_CV.run();
02799
02800
02801
02802
02803 }
02804 }
02805 }
02806
02807
02808 template <class FLOAT>
02809 void featureClusterVision<FLOAT>::fCVcheckParticles()
02810 {
02811
02812 std::vector<FLOAT>* meanClassDensity = fCV_NP.NPgetMeanClassDensity();
02813 std::vector<FLOAT>* stdClassDensity = fCV_NP.NPgetStdClassDensity();
02814 std::vector<FLOAT>* density = fCV_NP.NPgetDensityPtr();
02815
02816 for(int i = 0; i < fCV_NP.NPgetStemNumber(); i++)
02817 {
02818 if(fCV_NP.NPgetClassSize(i) > fCV_NP.NPgetMinClassSize())
02819 {
02820 FLOAT thresh = meanClassDensity->at(i) +
02821 (stdClassDensity->at(i)*fCV_densityBias);
02822
02823
02824
02825
02826 for(int j = 0; j < fCV_NP.NPgetClassSize(i); j++)
02827 {
02828
02829
02830
02831 if(density->at(fCV_NP.NPgetClass(i,j)) > thresh)
02832 {
02833 fCV_keepParticle[fCV_NP.NPgetClass(i,j)] = true;
02834 }
02835 else
02836 {
02837 fCV_keepParticle[fCV_NP.NPgetClass(i,j)] = false;
02838 }
02839 }
02840 }
02841 }
02842 }
02843
02844
02845 template <class FLOAT>
02846 void featureClusterVision<FLOAT>::fCVmatchClassTemporal()
02847 {
02848
02849 fCV_sortClassSize.resize(fCV_NP.NPgetStemNumber()+1,0);
02850 fCV_sortClassMember.resize(fCV_NP.NPgetStemNumber()+1,0);
02851 fCV_sortCount = 0;
02852
02853
02854
02855 for(int i = 0; i < fCV_NP.NPgetStemNumber(); i++)
02856 {
02857
02858 if(fCV_sortCount == 0)
02859 {
02860
02861 fCV_sortClassSize[0] = fCV_NP.NPgetClassSize(i);
02862 fCV_sortClassMember[0] = i;
02863 fCV_sortCount++;
02864 }
02865 else
02866 {
02867 bool setThis = false;
02868
02869 long initSC = fCV_sortCount;
02870 for(long j = 0; j < initSC; j++)
02871 {
02872
02873
02874 if(fCV_NP.NPgetClassSize(i) > fCV_sortClassSize[j])
02875 {
02876 setThis = true;
02877 long tempClassSize;
02878 long tempClassNum;
02879 long newClassSize = fCV_NP.NPgetClassSize(i);
02880 long newClassNum = i;
02881 for(int k = j; k <= fCV_sortCount; k++)
02882 {
02883 tempClassSize = fCV_sortClassSize[k];
02884 tempClassNum = fCV_sortClassMember[k];
02885 fCV_sortClassSize[k] = newClassSize;
02886 fCV_sortClassMember[k] = newClassNum;
02887 newClassSize = tempClassSize;
02888 newClassNum = tempClassNum;
02889 }
02890 break;
02891 }
02892 }
02893 if(setThis == false)
02894 {
02895 fCV_sortClassSize[fCV_sortCount] = fCV_NP.NPgetClassSize(i);
02896 fCV_sortClassMember[fCV_sortCount] = i;
02897 }
02898 fCV_sortCount++;
02899 }
02900 }
02901
02902
02903 for(int i = 0; i < fCV_sortCount; i++)
02904 {
02905 long *thisClass = &fCV_sortClassMember[i];
02906
02907 fCV_covHolderCurrent->at(*thisClass).sortID = i;
02908 }
02909
02910
02911
02912 if(fCV_doMatchSelf == true)
02913 {
02914 for(unsigned int i = 0; i < fCV_covDataSizeCurrent; i++)
02915 {
02916
02917
02918 fCV_covHolderCurrent->at(i).matchID = i;
02919 }
02920 fCV_doMatchSelf = false;
02921 }
02922 else
02923 {
02924
02925
02926 fCV_CV.matchPmeanAccum(fCV_covHolderCurrent,&fCV_covDataSizeCurrent,
02927 &fCV_covHolderMatch,&fCV_covDataSizeMatch,
02928 fCV_NP.NPgetMinClassSize());
02929 }
02930 }
02931
02932
02933 template <class FLOAT>
02934 void featureClusterVision<FLOAT>::fCVsetImageParams()
02935 {
02936 for(unsigned long i = 0; i < fCV_covDataSizeCurrent; i++)
02937 {
02938
02939
02940
02941
02942
02943 if(fCV_covHolderCurrent->at(i).isLarge)
02944 {
02945 unsigned int X = 0;
02946 unsigned int Y = 0;
02947 unsigned int minX = fCV_sizeX;
02948 unsigned int minY = fCV_sizeY;
02949 unsigned int maxX = 0;
02950 unsigned int maxY = 0;
02951
02952 for(int j = 0;
02953 j < fCV_NP.NPgetClassSize(fCV_covHolderCurrent->at(i).baseID); j++)
02954 {
02955
02956 long item = fCV_NP.NPgetClass(fCV_covHolderCurrent->at(i).baseID
02957 ,j);
02958
02959 int ii = (int)((fCV_NP.NPgetFeature(item,fCV_space[0].size()-2)
02960 /(fCV_spatialWeight*fCV_sizeXbias))*fCV_sizeX);
02961 X += ii;
02962 if((unsigned)ii < minX) minX = (unsigned)ii;
02963 if((unsigned)ii > maxX) maxX = (unsigned)ii;
02964
02965 int jj = (int)((fCV_NP.NPgetFeature(item,fCV_space[0].size()-1)
02966 /(fCV_spatialWeight*fCV_sizeYbias))*fCV_sizeY);
02967
02968 Y += jj;
02969 if((unsigned)jj < minY) minY = (unsigned)jj;
02970 if((unsigned)jj > maxY) maxY = (unsigned)jj;
02971 }
02972 fCV_covHolderCurrent->at(i).posX =
02973 X/fCV_NP.NPgetClassSize(fCV_covHolderCurrent->at(i).baseID);
02974 fCV_covHolderCurrent->at(i).posY =
02975 Y/fCV_NP.NPgetClassSize(fCV_covHolderCurrent->at(i).baseID);
02976 fCV_covHolderCurrent->at(i).maxX = maxX;
02977 fCV_covHolderCurrent->at(i).minX = minX;
02978 fCV_covHolderCurrent->at(i).maxY = maxY;
02979 fCV_covHolderCurrent->at(i).minY = minY;
02980 }
02981 }
02982 }
02983
02984
02985
02986
02987
02988
02989
02990
02991 template <class FLOAT>
02992 void featureClusterVision<FLOAT>::fCVclusterImage()
02993 {
02994 std::ofstream timerFile("./clusterTimer.txt",std::ios::app);
02995 Timer tim;
02996 tim.reset();
02997 int t1,t2,t3;
02998 int t0 = tim.get();
02999
03000 LINFO("SWITCH COV");
03001 fCVswitchCov();
03002
03003 t1 = tim.get();
03004 t2 = t1 - t0;
03005
03006 std::cerr << "\t>>>>>>>> fCV (SWITCH COV) TIME: " << t2 << "ms\n";
03007 if(fCV_useTimerFile == true)
03008 timerFile << t2 << "\t";
03009
03010 LINFO("LOW PASSING IMAGE");
03011 fCVlowPass();
03012 t3 = t2;
03013 t1 = tim.get();
03014 t2 = t1 - t0;
03015 t3 = t2 - t3;
03016 std::cerr << "\t>>>>>>>> fCV (LOW PASS) TIME: " << t2 << "ms "
03017 << " SLICE " << t3 << "ms\n";
03018 if(fCV_useTimerFile == true)
03019 timerFile << t2 << "\t" << t3 << "\t";
03020
03021 LINFO("FIND FEATURES");
03022 if(fCV_useBrain == true)
03023 fCVfindFeaturesBrain();
03024 else
03025 fCVfindFeaturesNoBrain();
03026 t3 = t2;
03027 t1 = tim.get();
03028 t2 = t1 - t0;
03029 t3 = t2 - t3;
03030 std::cerr << "\t>>>>>>>> fCV (FIND FEATURES) TIME: " << t2 << "ms "
03031 << " SLICE " << t3 << "ms\n";
03032 if(fCV_useTimerFile == true)
03033 timerFile << t2 << "\t" << t3 << "\t";
03034
03035 LINFO("FIND MIXED CHANNELS");
03036 fCVfindMixedChannels();
03037 t3 = t2;
03038 t1 = tim.get();
03039 t2 = t1 - t0;
03040 t3 = t2 - t3;
03041 std::cerr << "\t>>>>>>>> fCV (FIND MIXED CHAN) TIME: "<< t2 << "ms "
03042 << " SLICE " << t3 << "ms\n";
03043 if(fCV_useTimerFile == true)
03044 timerFile << t2 << "\t" << t3 << "\t";
03045
03046 LINFO("RUN ICA");
03047 fCVrunICA();
03048 t3 = t2;
03049 t1 = tim.get();
03050 t2 = t1 - t0;
03051 t3 = t2 - t3;
03052 std::cerr << "\t>>>>>>>> fCV (RUN ICA) TIME: "<< t2 << "ms "
03053 << " SLICE " << t3 << "ms\n";
03054 if(fCV_useTimerFile == true)
03055 timerFile << t2 << "\t" << t3 << "\t";
03056
03057 LINFO("RUN NPCLASSIFY");
03058 fCVrunNPclassify();
03059 t3 = t2;
03060 t1 = tim.get();
03061 t2 = t1 - t0;
03062 t3 = t2 - t3;
03063 std::cerr << "\t>>>>>>>> fCV (NP CLASSIFY) TIME: "<< t2 << "ms "
03064 << " SLICE " << t3 << "ms\n";
03065 if(fCV_useTimerFile == true)
03066 timerFile << t2 << "\t" << t3 << "\t";
03067
03068 LINFO("RUN COVESTIMATE");
03069 fCVrunCovEstimate();
03070 t3 = t2;
03071 t1 = tim.get();
03072 t2 = t1 - t0;
03073 t3 = t2 - t3;;
03074 std::cerr << ".\t>>>>>>>> fCV (COV ESTIMATE) TIME: "<< t2 << "ms "
03075 << " SLICE " << t3 << "ms\n";
03076 if(fCV_useTimerFile == true)
03077 timerFile << t2 << "\t" << t3 << "\t";
03078
03079 LINFO("RUN MATCH CLASS TEMPORAL");
03080 fCVmatchClassTemporal();
03081 t3 = t2;
03082 t1 = tim.get();
03083 t2 = t1 - t0;
03084 t3 = t2 - t3;
03085 std::cerr << "\t>>>>>>>> fCV (MATCH CLASS TEMPORAL) TIME: "<< t2 << "ms "
03086 << " SLICE " << t3 << "ms\n";
03087 if(fCV_useTimerFile == true)
03088 timerFile << t2 << "\t" << t3 << "\t";
03089 LINFO("FIND IMAGE PARAMETERS");
03090 fCVsetImageParams();
03091 t3 = t2;
03092 t1 = tim.get();
03093 t2 = t1 - t0;
03094 t3 = t2 - t3;
03095 std::cerr << "\t>>>>>>>> fCV (FIND IMAGE PARAMETERS) TIME: "<< t2 << "ms "
03096 << " SLICE " << t3 << "ms\n";
03097 if(fCV_useTimerFile == true)
03098 timerFile << t2 << "\t" << t3 << "\t";
03099
03100 LINFO("PRINT CLUSTERS");
03101 fCVprintOutClusters();
03102 t3 = t2;
03103 t1 = tim.get();
03104 t2 = t1 - t0;
03105 t3 = t2 - t3;
03106 std::cerr << "\t>>>>>>>> fCV (PRINT CLUSTERS) TIME: "<< t2 << "ms "
03107 << " SLICE " << t3 << "ms\n";
03108 if(fCV_useTimerFile == true)
03109 timerFile << t2 << "\t" << t3 << "\t";
03110
03111 LINFO("CHECK PARTICLES");
03112 fCVcheckParticles();
03113 t3 = t2;
03114 t1 = tim.get();
03115 t2 = t1 - t0;
03116 t3 = t2 - t3;
03117 std::cerr << "\t>>>>>>>> fCV (CHECK PARTICLES) TIME: "<< t2 << "ms "
03118 << " SLICE " << t3 << "ms\n";
03119 if(fCV_useTimerFile == true)
03120 timerFile << t2 << "\t" << t3 << "\t";
03121
03122 LINFO("RESET SPACE");
03123 fCV_NP.NPresetSpace();
03124 t3 = t2;
03125 t1 = tim.get();
03126 t2 = t1 - t0;
03127 t3 = t2 - t3;
03128 std::cerr << "\t>>>>>>>> fCV (RESET) TIME: "<< t2 << "ms "
03129 << " SLICE " << t3 << "ms\n";
03130 if(fCV_useTimerFile == true)
03131 {
03132 timerFile << t2 << "\t" << t3 << "\n";
03133 timerFile.close();
03134 }
03135
03136 std::cerr << "DONE\n";
03137
03138 }
03139
03140
03141 template <class FLOAT>
03142 void featureClusterVision<FLOAT>::fCVsaccadeTest(std::string _maskFile,
03143 std::string _outFile,
03144 std::string _label,
03145 std::string _fileName)
03146 {
03147
03148 Timer tim;
03149 tim.reset();
03150 int t1,t2,t3;
03151 int t0 = tim.get();
03152
03153 LINFO("SWITCH COV");
03154 fCVswitchCov();
03155
03156 t1 = tim.get();
03157 t2 = t1 - t0;
03158
03159 std::cerr << "\t>>>>>>>> fCV (SWITCH COV) TIME: " << t2 << "ms\n";
03160
03161 LINFO("LOW PASSING IMAGE");
03162 fCVlowPass();
03163 t3 = t2;
03164 t1 = tim.get();
03165 t2 = t1 - t0;
03166 t3 = t2 - t3;
03167 std::cerr << "\t>>>>>>>> fCV (LOW PASS) TIME: " << t2 << "ms "
03168 << " SLICE " << t3 << "ms\n";
03169
03170 LINFO("FIND FEATURES");
03171 fCVfindFeaturesFromFile(_fileName);
03172 t3 = t2;
03173 t1 = tim.get();
03174 t2 = t1 - t0;
03175 t3 = t2 - t3;
03176 std::cerr << "\t>>>>>>>> fCV (FIND FEATURES) TIME: " << t2 << "ms "
03177 << " SLICE " << t3 << "ms\n";
03178
03179 LINFO("FIND MIXED CHANNELS");
03180 fCVfindMixedChannels();
03181 t3 = t2;
03182 t1 = tim.get();
03183 t2 = t1 - t0;
03184 t3 = t2 - t3;
03185 std::cerr << "\t>>>>>>>> fCV (FIND MIXED CHAN) TIME: "<< t2 << "ms "
03186 << " SLICE " << t3 << "ms\n";
03187
03188 LINFO("RUN ICA");
03189 fCVrunICA();
03190 t3 = t2;
03191 t1 = tim.get();
03192 t2 = t1 - t0;
03193 t3 = t2 - t3;
03194 std::cerr << "\t>>>>>>>> fCV (RUN ICA) TIME: "<< t2 << "ms "
03195 << " SLICE " << t3 << "ms\n";
03196
03197 LINFO("DUMP FEATUES AND SACCADE DATA");
03198 fCVprocessOutSaccadeData(_maskFile,_outFile,_label);
03199 t1 = tim.get();
03200 t2 = t1 - t0;
03201 t3 = t2 - t3;
03202 std::cerr << "\t>>>>>>>> fCV (DUMP DATA) TIME: "<< t2 << "ms "
03203 << " SLICE " << t3 << "ms\n";
03204
03205 std::cerr << "DONE\n";
03206
03207 }
03208
03209
03210 template <class FLOAT>
03211 void featureClusterVision<FLOAT>::fCVstandAloneFeatureTest(std::string _fileName)
03212 {
03213 std::ofstream timerFile("./clusterTimer.txt",std::ios::app);
03214 Timer tim;
03215 tim.reset();
03216 int t1,t2,t3;
03217 int t0 = tim.get();
03218
03219 LINFO("SWITCH COV");
03220 fCVswitchCov();
03221
03222 t1 = tim.get();
03223 t2 = t1 - t0;
03224
03225 std::cerr << "\t>>>>>>>> fCV (SWITCH COV) TIME: " << t2 << "ms\n";
03226 if(fCV_useTimerFile == true)
03227 timerFile << t2 << "\t";
03228
03229 LINFO("LOW PASSING IMAGE");
03230 fCVlowPass();
03231 t3 = t2;
03232 t1 = tim.get();
03233 t2 = t1 - t0;
03234 t3 = t2 - t3;
03235 std::cerr << "\t>>>>>>>> fCV (LOW PASS) TIME: " << t2 << "ms "
03236 << " SLICE " << t3 << "ms\n";
03237 if(fCV_useTimerFile == true)
03238 timerFile << t2 << "\t" << t3 << "\t";
03239
03240 LINFO("FIND FEATURES");
03241 if(fCV_useBrain == true)
03242 fCVfindFeaturesBrain();
03243 else
03244 fCVfindFeaturesNoBrain();
03245 t3 = t2;
03246 t1 = tim.get();
03247 t2 = t1 - t0;
03248 t3 = t2 - t3;
03249 std::cerr << "\t>>>>>>>> fCV (FIND FEATURES) TIME: " << t2 << "ms "
03250 << " SLICE " << t3 << "ms\n";
03251 if(fCV_useTimerFile == true)
03252 timerFile << t2 << "\t" << t3 << "\t";
03253
03254 LINFO("FIND MIXED CHANNELS");
03255 fCVfindMixedChannels();
03256 t3 = t2;
03257 t1 = tim.get();
03258 t2 = t1 - t0;
03259 t3 = t2 - t3;
03260 std::cerr << "\t>>>>>>>> fCV (FIND MIXED CHAN) TIME: "<< t2 << "ms "
03261 << " SLICE " << t3 << "ms\n";
03262 if(fCV_useTimerFile == true)
03263 timerFile << t2 << "\t" << t3 << "\t";
03264
03265 LINFO("FIND MIXED CHANNELS");
03266
03267 fCVrunStandAloneMSBatchFilter(_fileName);
03268 t3 = t2;
03269 t1 = tim.get();
03270 t2 = t1 - t0;
03271 t3 = t2 - t3;
03272 std::cerr << "\t>>>>>>>> fCV (RUN STAND ALONE) TIME: "<< t2 << "ms "
03273 << " SLICE " << t3 << "ms\n";
03274 if(fCV_useTimerFile == true)
03275 timerFile << t2 << "\t" << t3 << "\t";
03276
03277 }
03278
03279
03280
03281
03282
03283
03284 template <class FLOAT>
03285 void featureClusterVision<FLOAT>::fCVprintOutClusters()
03286 {
03287
03288
03289 findColorIndex FAC;
03290 unsigned int zero = 0;
03291
03292 PixRGB<FLOAT> mrPixel;
03293 FAC.FACgetColor12(&zero,&mrPixel);
03294
03295 PixRGB<FLOAT> mrPixelMatch;
03296 FAC.FACgetColor12(&zero,&mrPixelMatch);
03297
03298 PixRGB<FLOAT> mrPixelOver;
03299 FAC.FACgetColor12(&zero,&mrPixelOver);
03300
03301 fCV_outImageClasses = fCV_realImage;
03302 fCV_outImageTemporal = fCV_realImage;
03303 fCV_outImageTarget = fCV_realImage;
03304
03305
03306 for(unsigned long i = 0; i < fCV_covDataSizeCurrent; i++)
03307 {
03308
03309
03310
03311 unsigned int current = fCV_covHolderCurrent->at(i).matchID;
03312 if(fCV_covHolderCurrent->at(i).isLarge)
03313 {
03314 bool small = true;
03315 if(current < 12)
03316 FAC.FACgetColor12(¤t,&mrPixelMatch);
03317 else
03318 {
03319 small = false;
03320 current = current - 12;
03321 FAC.FACgetColor12(¤t,&mrPixelMatch);
03322 }
03323 for(int j = 0;
03324 j < fCV_NP.NPgetClassSize(fCV_covHolderCurrent->at(i).baseID); j++)
03325 {
03326 long item = fCV_NP.NPgetClass(fCV_covHolderCurrent->at(i).baseID
03327 ,j);
03328 int ii = (int)((fCV_NP.NPgetFeature(item,fCV_space[0].size()-2)
03329 /(fCV_spatialWeight*fCV_sizeXbias))*fCV_sizeX);
03330 int jj = (int)((fCV_NP.NPgetFeature(item,fCV_space[0].size()-1)
03331 /(fCV_spatialWeight*fCV_sizeYbias))*fCV_sizeY);
03332
03333 if(small == true)
03334 drawCircle(fCV_outImageTemporal, Point2D<int>(ii,jj),2,mrPixelMatch,2);
03335 else
03336 drawCircle(fCV_outImageTemporal, Point2D<int>(ii,jj),3,mrPixelMatch,3);
03337
03338 if(j == 0)
03339 {
03340 char foo2;
03341 sprintf(&foo2,"%d",(int)fCV_covHolderCurrent->at(i).matchID);
03342 writeText(fCV_outImageTemporal, Point2D<int>(ii,jj),&foo2,
03343 PixRGB<FLOAT>(255),PixRGB<FLOAT>(0));
03344 }
03345 }
03346 }
03347 }
03348
03349
03350
03351
03352
03353
03354 for(int i = 0; i < fCV_sortCount; i++)
03355 {
03356 unsigned int number;
03357 long *thisClass = &fCV_sortClassMember[i];
03358 if(fCV_NP.NPgetClassSize(*thisClass) > fCV_NP.NPgetMinClassSize())
03359 {
03360 number = (unsigned)(i + 1);
03361
03362 FAC.FACgetColor12(&number,&mrPixel);
03363 unsigned int current = fCV_covHolderCurrent->at(*thisClass).matchID;
03364 FAC.FACgetColor12(¤t,&mrPixelMatch);
03365
03366 Image<PixRGB<FLOAT> > outputClass;
03367 outputClass.resize(fCV_sizeX,fCV_sizeY);
03368
03369 for(int j = 0; j < fCV_NP.NPgetClassSize(*thisClass); j++)
03370 {
03371
03372
03373
03374
03375
03376 long item = fCV_NP.NPgetClass(*thisClass,j);
03377
03378 int ii = (int)((fCV_NP.NPgetFeature(item,fCV_space[0].size()-2)
03379 /(fCV_spatialWeight*fCV_sizeXbias))*fCV_sizeX);
03380 int jj = (int)((fCV_NP.NPgetFeature(item,fCV_space[0].size()-1)
03381 /(fCV_spatialWeight*fCV_sizeYbias))*fCV_sizeY);
03382
03383 drawCircle(fCV_outImageClasses, Point2D<int>(ii,jj),2,mrPixel,2);
03384
03385 if(j == 0)
03386 {
03387 if(fCV_NP.NPgetMinClassSize() <= fCV_NP.NPgetClassSize(*thisClass))
03388 {
03389 char foo;
03390 sprintf(&foo,"%d",(int)*thisClass);
03391 writeText(fCV_outImageClasses, Point2D<int>(ii,jj),&foo,
03392 PixRGB<FLOAT>(255),PixRGB<FLOAT>(0));
03393 }
03394 }
03395 }
03396 }
03397 }
03398
03399
03400 for(unsigned long i = 0; i < fCV_covDataSizeCurrent; i++)
03401 {
03402 if(fCV_covHolderCurrent->at(i).isLarge)
03403 {
03404 unsigned int current = fCV_covHolderCurrent->at(i).matchID;
03405 bool small = true;
03406 if(current < 12)
03407 FAC.FACgetColor12(¤t,&mrPixelMatch);
03408 else
03409 {
03410 small = false;
03411 current = current - 12;
03412 FAC.FACgetColor12(¤t,&mrPixelMatch);
03413 }
03414
03415 drawCross(fCV_outImageTarget,
03416 Point2D<int>(fCV_covHolderCurrent->at(i).posX,
03417 fCV_covHolderCurrent->at(i).posY
03418 ),mrPixelMatch,20,2);
03419 if(small == true)
03420 drawCross(fCV_outImageTarget,
03421 Point2D<int>(fCV_covHolderCurrent->at(i).posX,
03422 fCV_covHolderCurrent->at(i).posY
03423 ),PixRGB<float>(0,0,0),20,1);
03424 else
03425 drawCross(fCV_outImageTarget,
03426 Point2D<int>(fCV_covHolderCurrent->at(i).posX,
03427 fCV_covHolderCurrent->at(i).posY
03428 ),PixRGB<float>(255,255,255),20,1);
03429
03430
03431
03432
03433
03434
03435
03436
03437
03438
03439
03440
03441 }
03442 }
03443 }
03444
03445
03446 template <class FLOAT>
03447 void featureClusterVision<FLOAT>::fCVprintOutCovSlices(int sizeX, int sizeY)
03448 {
03449 LINFO("PRINT COV Slices");
03450 Image<FLOAT> outImage;
03451 int isize;
03452 if(fCV_sizeX > fCV_sizeY)
03453 isize = fCV_sizeX;
03454 else
03455 isize = fCV_sizeY;
03456 for(int k = 0; k < (signed)fCV_space[0].size(); k++)
03457 {
03458 outImage.resize(isize,isize,true);
03459 outImage.resize(isize,isize);
03460
03461 if(k == ((signed)fCV_space[0].size()-1))
03462 {
03463 outImage = fCV_CV.returnCovSlice(0,k,outImage,true);
03464 }
03465 else
03466 {
03467 outImage = fCV_CV.returnCovSlice(k,k+1,outImage,true);
03468 }
03469 Raster::WriteGray(outImage,
03470 sformat("%s.out.covSlice.%d.pgm"
03471 ,fCV_fileName.c_str(),k));
03472 }
03473 }
03474
03475 #if 0
03476
03477
03478
03479
03480 template <class FLOAT>
03481 void featureClusterVision<FLOAT>::fCVprintOutBayesClass()
03482 {
03483 LINFO("PRINT BAYES CLASSES");
03484 findColorIndex FAC;
03485 typename std::vector<FLOAT> ptemp;
03486 ptemp.resize(fCV_covDataSizeCurrent,0.0F);
03487 typename std::vector<std::vector<FLOAT> > pVal;
03488 pVal.resize(fCV_countSM,ptemp);
03489 std::vector<int> classMember;
03490 classMember.resize(fCV_countSM,-1);
03491 typename std::vector<FLOAT> classWinner;
03492 classWinner.resize(fCV_countSM,0.0F);
03493
03494 for(int i = 0; i < fCV_countSM; i++)
03495 {
03496 for(unsigned int k = 0; k < fCV_covDataSizeCurrent; k++)
03497 {
03498
03499
03500 pVal[i][k] = fCV_CV.getP(fCV_space[i],fCV_covHolderCurrent->at(k),2);
03501
03502 if(classMember[i] == -1)
03503 {
03504 classMember[i] = k;
03505 classWinner[i] = pVal[i][k];
03506 }
03507 else
03508 if(pVal[i][k] > classWinner[i])
03509 {
03510 classWinner[i] = pVal[i][k];
03511 classMember[i] = k;
03512 }
03513 }
03514 }
03515
03516 Image<PixRGB<FLOAT> > realImage;
03517 Image<PixRGB<FLOAT> > blankImage;
03518 realImage = fCV_realImage;
03519 blankImage.resize(realImage.getWidth(),realImage.getHeight(),0.0F);
03520 PixRGB<FLOAT> mrPixel;
03521 unsigned int zero = 0;
03522 FAC.FACgetColor12(&zero,&mrPixel);
03523 for(int i = 0; i < fCV_countSM; i++)
03524 {
03525 unsigned int current = classMember[i];
03526 int sz = 2;
03527 if(current >= 12)
03528 {
03529 sz = 3;
03530 unsigned int c = current - 12;
03531 FAC.FACgetColor12(&c,&mrPixel);
03532 }
03533 else
03534 FAC.FACgetColor12(¤t,&mrPixel);
03535 Point2D<int> P;
03536 P = *fCV_rmap[i];
03537 drawCircle(realImage, P,sz,mrPixel,2);
03538 drawCircle(blankImage, P,sz,mrPixel,2);
03539 }
03540 Raster::WriteRGB(realImage,sformat("%s.out.CLASS_MAP_BAYES.ppm"
03541 ,fCV_fileName.c_str()));
03542 Raster::WriteRGB(blankImage,sformat("%s.out.BLANK_MAP_BAYES.ppm"
03543 ,fCV_fileName.c_str()));
03544
03545 }
03546
03547
03548 template <class FLOAT>
03549 void featureClusterVision<FLOAT>::fCVprintOutNeighborClass()
03550 {
03551 LINFO("PRINT Neighbor classes");
03552 findColorIndex FAC;
03553 typename std::vector<FLOAT> ptemp;
03554 ptemp.resize(fCV_covDataSizeCurrent,0.0F);
03555 std::vector<std::vector<FLOAT> > pVal;
03556 pVal.resize(fCV_countSM,ptemp);
03557 std::vector<int> classMember;
03558 classMember.resize(fCV_countSM,-1);
03559 typename std::vector<FLOAT> classWinner;
03560 classWinner.resize(fCV_countSM,0.0F);
03561
03562 for(int i = 0; i < fCV_countSM; i++)
03563 {
03564 for(unsigned int k = 0; k < fCV_covDataSizeCurrent; k++)
03565 {
03566
03567 pVal[i][k] = fCV_CV.getD(fCV_space[i],fCV_covHolderCurrent->at(k),2);
03568
03569 if(classMember[i] == -1)
03570 {
03571 classMember[i] = k;
03572 classWinner[i] = pVal[i][k];
03573 }
03574 else
03575 if(pVal[i][k] < classWinner[i])
03576 {
03577 classWinner[i] = pVal[i][k];
03578 classMember[i] = k;
03579 }
03580 }
03581 }
03582
03583 Image<PixRGB<FLOAT> > realImage;
03584 Image<PixRGB<FLOAT> > blankImage;
03585 realImage = fCV_realImage;
03586 blankImage.resize(realImage.getWidth(),realImage.getHeight(),0.0F);
03587 PixRGB<FLOAT> mrPixel;
03588
03589 for(int i = 0; i < fCV_countSM; i++)
03590 {
03591 unsigned int current = classMember[i];
03592 FAC.FACgetColor12(¤t,&mrPixel);
03593 Point2D<int> P;
03594 P = *fCV_rmap[i];
03595 drawCircle(realImage, P,2,mrPixel,2);
03596 drawCircle(blankImage, P,2,mrPixel,2);
03597 }
03598
03599 Raster::WriteRGB(realImage,sformat("%s.out.CLASS_MAP_NEIGH.ppm"
03600 ,fCV_fileName.c_str()));
03601 Raster::WriteRGB(blankImage,sformat("%s.out.BLANK_MAP_NEIGH.ppm"
03602 ,fCV_fileName.c_str()));
03603
03604 }
03605 #endif
03606
03607
03608 template <class FLOAT>
03609 void featureClusterVision<FLOAT>::fCVdumpCovMatrix(std::string fileName)
03610 {
03611 for(unsigned int i = 0; i < fCV_covDataSizeCurrent; i++)
03612 {
03613 fCV_CV.dumpMatrix(fileName,fCV_covHolderCurrent->at(i),i,fCV_fileName);
03614 }
03615 }
03616
03617
03618 template <class FLOAT>
03619 std::vector<covHolder<double> > featureClusterVision<FLOAT>::fCVgetCovHolders()
03620 {
03621 return *fCV_covHolderCurrent;
03622 }
03623
03624
03625 template <class FLOAT>
03626 unsigned int featureClusterVision<FLOAT>::fCVgetCovHolderSize()
03627 {
03628 return fCV_covDataSizeCurrent;
03629 }
03630
03631
03632 template <class FLOAT>
03633 void featureClusterVision<FLOAT>::fCVgetClusterImages(
03634 Image<PixRGB<FLOAT> > *classImage,
03635 Image<PixRGB<FLOAT> > *temporalImage,
03636 Image<PixRGB<FLOAT> > *targetImage,
03637 Image<FLOAT> *salMap)
03638 {
03639 *classImage = fCV_outImageClasses;
03640 *temporalImage = fCV_outImageTemporal;
03641 *targetImage = fCV_outImageTarget;
03642 *salMap = fCV_salmapLowPass;
03643 }
03644
03645
03646 template <class FLOAT>
03647 void featureClusterVision<FLOAT>::fCVprocessOutSaccadeData(std::string _maskFile,
03648 std::string _outFile,
03649 std::string _label)
03650 {
03651 Image<FLOAT> maskFile;
03652 Image<FLOAT> maskFileLP;
03653 std::ofstream outFile(_outFile.c_str(),std::ios::app);
03654 maskFile = Raster::ReadGray(_maskFile, RASFMT_PNM);
03655 Image<FLOAT> salmap;
03656 LFATAL("FIXME");
03657 salmap = rescaleBilinear(salmap,fCV_sizeX,fCV_sizeY);
03658 LINFO("DUMPING VALUES");
03659
03660
03661
03662 maskFileLP = lowPass9(maskFile);
03663 unsigned int mwidth = (unsigned)maskFile.getWidth();
03664 FLOAT maxDist = sqrt(pow((FLOAT)fCV_sizeX,2)+pow((FLOAT)fCV_sizeY,2));
03665
03666
03667
03668
03669 for(unsigned int i = 0; i < (unsigned)fCV_countSM; i++)
03670 {
03671
03672 outFile << _label << "\t" << fCV_indexNumber[i] << "\t";
03673 outFile << fCV_cmap[i].i << "\t" << fCV_cmap[i].j << "\t";
03674 outFile << fCV_jumpTo[i].i << "\t" << fCV_jumpTo[i].j << "\t";
03675
03676
03677 typename Image<FLOAT>::iterator maskFileItr = maskFile.beginw();
03678 FLOAT distance = 0;
03679 FLOAT minDist = maxDist;
03680 unsigned int ii = 0;
03681
03682
03683 while(maskFileItr != maskFile.endw())
03684 {
03685 if(*maskFileItr != 0.0F)
03686 {
03687 distance = sqrt(pow((FLOAT)(ii % mwidth) - (FLOAT)fCV_cmap[i].i,2) +
03688 pow((FLOAT)(ii / mwidth) - (FLOAT)fCV_cmap[i].j,2));
03689 if(distance < minDist) minDist = distance;
03690 }
03691 ++maskFileItr; ++ii;
03692 }
03693
03694
03695
03696
03697 FLOAT masky = maskFileLP.getVal(fCV_cmap[i].i,fCV_cmap[i].j);
03698 LINFO("MASK VALUE %f d %f at %dx%d",masky,minDist,fCV_cmap[i].i,
03699 fCV_cmap[i].j);
03700
03701 if(masky >= .000001F)
03702
03703 outFile << "1\t";
03704 else
03705 outFile << "0\t";
03706
03707 outFile << minDist << "\t";
03708
03709
03710 FLOAT saly = salmap.getVal(fCV_cmap[i].i,fCV_cmap[i].j);
03711 outFile << saly << "\t";
03712
03713 outFile << "XXXXX\t";
03714
03715
03716 for(unsigned int j = 0; j < fCV_fmap[i].size(); j++)
03717 {
03718 outFile << fCV_fmap[i][j] << "\t";
03719 }
03720
03721 outFile << "XXXXX\t";
03722
03723
03724 for(unsigned int j = 0; j < fCV_space[i].size(); j++)
03725 {
03726 outFile << fCV_space[i][j] << "\t";
03727 }
03728
03729 outFile << "\n";
03730 }
03731 outFile.close();
03732
03733
03734
03735
03736 }
03737
03738
03739
03740 template <class FLOAT>
03741 void featureClusterVision<FLOAT>::fCVgetImageBaseStats(std::string _maskFile,
03742 std::string _imageFile,
03743 std::string _outFile,
03744 std::string _label)
03745 {
03746 LINFO("GETTING BASE STATS");
03747 LINFO("MASK FILE %s",_maskFile.c_str());
03748 LINFO("IMAGE FILE %s",_imageFile.c_str());
03749 Image<FLOAT> maskFile;
03750 Image<PixRGB<FLOAT> > imageFile;
03751 maskFile = Raster::ReadGray(_maskFile, RASFMT_PNM);
03752 imageFile = Raster::ReadRGB(_imageFile, RASFMT_PNM);
03753 FLOAT maskOffset = (maskFile.getHeight() - imageFile.getHeight())/2;
03754
03755
03756 FLOAT H1onMean, H2onMean, SonMean, VonMean;
03757 FLOAT H1onSTD, H2onSTD, SonSTD, VonSTD;
03758 FLOAT H1onSum = 0; FLOAT H2onSum = 0;
03759 FLOAT SonSum = 0; FLOAT VonSum = 0;
03760 double H1onSS = 0; double H2onSS = 0;
03761 double SonSS = 0; double VonSS = 0;
03762
03763 FLOAT H1offMean, H2offMean, SoffMean, VoffMean;
03764 FLOAT H1offSTD, H2offSTD, SoffSTD, VoffSTD;
03765 FLOAT H1offSum = 0; FLOAT H2offSum = 0;
03766 FLOAT SoffSum = 0; FLOAT VoffSum = 0;
03767 double H1offSS = 0; double H2offSS = 0;
03768 double SoffSS = 0; double VoffSS = 0;
03769
03770 FLOAT H1Mean, H2Mean, SMean, VMean;
03771 FLOAT H1STD, H2STD, SSTD, VSTD;
03772 FLOAT H1Sum = 0; FLOAT H2Sum = 0;
03773 FLOAT SSum = 0; FLOAT VSum = 0;
03774 double H1SS = 0; double H2SS = 0;
03775 double SSS = 0; double VSS = 0;
03776
03777 FLOAT maskMeanX, maskMeanY, maskSTDX, maskSTDY;
03778 FLOAT maskSumX = 0; FLOAT maskSumY = 0;
03779 double maskSSX = 0; double maskSSY = 0;
03780 unsigned long maskMass = 0;
03781 unsigned long nonMaskMass = 0;
03782 unsigned long totalMass = 0;
03783
03784 FLOAT pixH1, pixH2, pixS, pixV;
03785
03786 for(unsigned int x = 0; x < (unsigned)imageFile.getWidth(); x++)
03787 {
03788 for(unsigned int y = 0; y < (unsigned)imageFile.getHeight(); y++)
03789 {
03790
03791 FLOAT maskVal = maskFile.getVal(x,(int)(y+maskOffset));
03792
03793 if(maskVal >= 0.000001F)
03794 {
03795 maskMass++;
03796 }
03797 else
03798 {
03799 nonMaskMass++;
03800 }
03801 }
03802 }
03803
03804 totalMass = maskMass + nonMaskMass;
03805
03806 for(unsigned int x = 0; x < (unsigned)imageFile.getWidth(); x++)
03807 {
03808 for(unsigned int y = 0; y < (unsigned)imageFile.getHeight(); y++)
03809 {
03810 PixRGB<FLOAT> thisColor = imageFile.getVal(x,y);
03811 FLOAT maskVal = maskFile.getVal(x,(int)(y+maskOffset));
03812 thisColor.getHSV(pixH1,pixH2,pixS,pixV);
03813
03814
03815 if(maskVal >= 0.000001F)
03816 {
03817
03818 maskSumX += x; maskSumY += y;
03819 H1onSum += pixH1; H2onSum += pixH2;
03820 SonSum += pixS; VonSum += pixV;
03821
03822 maskSSX += pow((FLOAT)x,2)/maskMass;
03823 maskSSY += pow((FLOAT)y,2)/maskMass;
03824 H1onSS += pow(pixH1,2) /maskMass;
03825 H2onSS += pow(pixH2,2) /maskMass;
03826 SonSS += pow(pixS,2) /maskMass;
03827 VonSS += pow(pixV,2) /maskMass;
03828 }
03829 else
03830 {
03831
03832
03833 H1offSum += pixH1; H2offSum += pixH2;
03834 SoffSum += pixS; VoffSum += pixV;
03835
03836 H1offSS += pow(pixH1,2)/nonMaskMass;
03837 H2offSS += pow(pixH2,2)/nonMaskMass;
03838 SoffSS += pow(pixS,2) /nonMaskMass;
03839 VoffSS += pow(pixV,2) /nonMaskMass;
03840 }
03841
03842
03843 H1Sum += pixH1; H2Sum += pixH2;
03844 SSum += pixS; VSum += pixV;
03845
03846 H1SS += pow(pixH1,2)/totalMass;
03847 H2SS += pow(pixH2,2)/totalMass;
03848 SSS += pow(pixS,2) /totalMass;
03849 VSS += pow(pixV,2) /totalMass;
03850 }
03851 }
03852
03853
03854
03855
03856 maskMeanX = maskSumX/maskMass; maskMeanY = maskSumY/maskMass;
03857 H1onMean = H1onSum /maskMass; H2onMean = H2onSum /maskMass;
03858 SonMean = SonSum /maskMass; VonMean = VonSum /maskMass;
03859 maskSTDX = sqrt(maskSSX - pow(maskMeanX,2));
03860 maskSTDY = sqrt(maskSSY - pow(maskMeanY,2));
03861 H1onSTD = sqrt(H1onSS - pow(H1onMean,2));
03862 H2onSTD = sqrt(H2onSS - pow(H2onMean,2));
03863 SonSTD = sqrt(SonSS - pow(SonMean,2));
03864 VonSTD = sqrt(VonSS - pow(VonMean,2));
03865
03866
03867 H1offMean = H1offSum /nonMaskMass; H2offMean = H2offSum /nonMaskMass;
03868 SoffMean = SoffSum /nonMaskMass; VoffMean = VoffSum /nonMaskMass;
03869 H1offSTD = sqrt(H1offSS - pow(H1offMean,2));
03870 H2offSTD = sqrt(H2offSS - pow(H2offMean,2));
03871 SoffSTD = sqrt(SoffSS - pow(SoffMean,2));
03872 VoffSTD = sqrt(VoffSS - pow(VoffMean,2));
03873
03874
03875 H1Mean = H1Sum /totalMass; H2Mean = H2Sum /totalMass;
03876 SMean = SSum /totalMass; VMean = VSum /totalMass;
03877 H1STD = sqrt(H1SS - pow(H1Mean,2));
03878 H2STD = sqrt(H2SS - pow(H2Mean,2));
03879 SSTD = sqrt(SSS - pow(SMean,2));
03880 VSTD = sqrt(VSS - pow(VMean,2));
03881
03882
03883 std::string noutFile = _outFile + ".simple.stats.out.txt";
03884 LINFO("WRITING %s", noutFile.c_str());
03885 std::ofstream outFile(noutFile.c_str(),std::ios::app);
03886
03887 outFile << _label << "\t";
03888 outFile << maskMass << "\t" << nonMaskMass << "\t" << totalMass << "\t";
03889
03890
03891 outFile << maskMeanX << "\t" << maskSTDX << "\t"
03892 << maskMeanY << "\t" << maskSTDY << "\t"
03893 << H1onMean << "\t" << H1onSTD << "\t"
03894 << H2onMean << "\t" << H2onSTD << "\t"
03895 << SonMean << "\t" << SonSTD << "\t"
03896 << VonMean << "\t" << VonSTD << "\t";
03897
03898
03899 outFile << H1offMean << "\t" << H1offSTD << "\t"
03900 << H2offMean << "\t" << H2offSTD << "\t"
03901 << SoffMean << "\t" << SoffSTD << "\t"
03902 << VoffMean << "\t" << VoffSTD << "\t";
03903
03904
03905 outFile << H1Mean << "\t" << H1STD << "\t"
03906 << H2Mean << "\t" << H2STD << "\t"
03907 << SMean << "\t" << SSTD << "\t"
03908 << VMean << "\t" << VSTD << "\n";
03909
03910 outFile.close();
03911 }
03912
03913 template <class FLOAT>
03914 void featureClusterVision<FLOAT>::fCVgetImageComplexStats(std::string _maskFile,
03915 std::string _imageFile,
03916 std::string _outFile,
03917 std::string _label)
03918 {
03919 unsigned int rotationChannels = 5;
03920 int rotations[5] = {0,45,90,135,-2};
03921 unsigned int junctionList1[2] = {0,1};
03922 unsigned int junctionList2[2] = {2,3};
03923 unsigned int scales = 6;
03924 FLOAT gaborSTD = 6.0F;
03925 FLOAT gaborPrd = 3.0F;
03926 LINFO("GETTING BASE STATS");
03927 LINFO("MASK FILE %s",_maskFile.c_str());
03928 LINFO("IMAGE FILE %s",_imageFile.c_str());
03929 Image<FLOAT> maskFile;
03930 Image<PixRGB<FLOAT> > imageFile;
03931 Image<PixRGB<FLOAT> > CmaskFile;
03932 maskFile = Raster::ReadGray(_maskFile, RASFMT_PNM);
03933 getColor(maskFile,CmaskFile);
03934
03935
03936 imageFile = Raster::ReadRGB(_imageFile, RASFMT_PNM);
03937 FLOAT maskOffset = (maskFile.getHeight() - imageFile.getHeight())/2;
03938 typename std::vector<Image<FLOAT> > masks(scales,maskFile*255.0F);
03939
03940
03941
03942
03943 Image<FLOAT> holder;
03944 typename std::vector<Image<FLOAT> > HSVpart(4,holder);
03945 typename std::vector<std::vector<Image<FLOAT> > >
03946 rot(rotationChannels,HSVpart);
03947 typename std::vector<std::vector<std::vector<Image<FLOAT> > > >
03948 complexPyramid(scales,rot);
03949
03950
03951
03952 typename Image<FLOAT>::iterator H1itr;
03953 typename Image<FLOAT>::iterator H2itr;
03954 typename Image<FLOAT>::iterator Sitr;
03955 typename Image<FLOAT>::iterator Vitr;
03956
03957
03958
03959
03960 Image<PixRGB<FLOAT> > currentImage = imageFile;
03961
03962
03963 unsigned int s = 0;
03964 for(typename std::vector<std::vector<std::vector<Image<FLOAT> > > >::iterator
03965 complexPyramidItr = complexPyramid.begin();
03966 complexPyramidItr != complexPyramid.end();
03967 ++complexPyramidItr, s++)
03968 {
03969 unsigned int i = 0;
03970
03971 for(typename std::vector<std::vector<Image<FLOAT> > >::iterator rotationItr =
03972 complexPyramidItr->begin(); rotationItr != complexPyramidItr->end();
03973 ++rotationItr, i++)
03974 {
03975
03976 if(rotations[i] >= 0)
03977 {
03978 LINFO("Running rotations scale %d rot %d",s,rotations[i]);
03979
03980 rotationItr->at(0).resize(currentImage.getWidth(),
03981 currentImage.getHeight());
03982 H1itr = rotationItr->at(0).beginw();
03983
03984 rotationItr->at(1).resize(currentImage.getWidth(),
03985 currentImage.getHeight());
03986 H2itr = rotationItr->at(1).beginw();
03987
03988 rotationItr->at(2).resize(currentImage.getWidth()
03989 ,currentImage.getHeight());
03990 Sitr = rotationItr->at(2).beginw();
03991
03992 rotationItr->at(3).resize(currentImage.getWidth(),
03993 currentImage.getHeight());
03994 Vitr = rotationItr->at(3).beginw();
03995
03996 for(typename Image<PixRGB<FLOAT> >::iterator currentItr
03997 = currentImage.beginw();
03998 currentItr != currentImage.endw();
03999 ++currentItr,++H1itr,++H2itr,++Sitr,++Vitr)
04000 {
04001 currentItr->getHSV(*H1itr,*H2itr,*Sitr,*Vitr);
04002
04003
04004 *Vitr = (*Vitr) * (*fCV_valNorm);
04005 }
04006
04007
04008
04009
04010 Image<FLOAT> mrGabor = gaborFilter2<FLOAT>(gaborSTD,gaborPrd,0.0F,
04011 (FLOAT)rotations[i]);
04012
04013 Image<FLOAT> mrGaborAF = gaborFilter2<FLOAT>(gaborSTD,gaborPrd
04014 ,gaborPrd/2,
04015 (FLOAT)rotations[i]);
04016
04017
04018 rotationItr->at(0) = abs(convolve(rotationItr->at(0),mrGabor,CONV_BOUNDARY_ZERO)) +
04019 abs(convolve(rotationItr->at(0),mrGaborAF,CONV_BOUNDARY_ZERO));
04020 inplaceAttenuateBorders(rotationItr->at(0), (int)gaborSTD);
04021
04022
04023 Raster::WriteGray(rotationItr->at(0)*255.0F,
04024 sformat("imgH1.%d.%d.%s.out.pgm",
04025 s,rotations[i],_label.c_str()));
04026
04027 rotationItr->at(1) = abs(convolve(rotationItr->at(1),mrGabor,CONV_BOUNDARY_ZERO)) +
04028 abs(convolve(rotationItr->at(1),mrGaborAF,CONV_BOUNDARY_ZERO));
04029 inplaceAttenuateBorders(rotationItr->at(1), (int)gaborSTD);
04030
04031
04032 Raster::WriteGray(rotationItr->at(1)*255.0F,
04033 sformat("imgH2.%d.%d.%s.out.pgm",
04034 s,rotations[i],_label.c_str()));
04035
04036 rotationItr->at(2) = abs(convolve(rotationItr->at(2),mrGabor,CONV_BOUNDARY_ZERO)) +
04037 abs(convolve(rotationItr->at(2),mrGaborAF,CONV_BOUNDARY_ZERO));
04038 inplaceAttenuateBorders(rotationItr->at(2), (int)gaborSTD);
04039
04040
04041 Raster::WriteGray(rotationItr->at(2)*255.0F,
04042 sformat("imgS.%d.%d.%s.out.pgm",
04043 s,rotations[i],_label.c_str()));
04044
04045 rotationItr->at(3) = abs(convolve(rotationItr->at(3),mrGabor,CONV_BOUNDARY_ZERO)) +
04046 abs(convolve(rotationItr->at(3),mrGaborAF,CONV_BOUNDARY_ZERO));
04047 inplaceAttenuateBorders(rotationItr->at(3), (int)gaborSTD);
04048
04049
04050 Raster::WriteGray(rotationItr->at(3)*255.0F,
04051 sformat("imgV.%d.%d.%s.out.pgm",
04052 s,rotations[i],_label.c_str()));
04053 }
04054
04055 else
04056 {
04057 LINFO("Running junctions scale %d rot %d",s,rotations[i]);
04058
04059
04060
04061
04062 Image<FLOAT> Alpha;
04063 Image<FLOAT> Beta;
04064
04065
04066 fCVmixChannels(complexPyramidItr->at(junctionList1[0])[0],
04067 complexPyramidItr->at(junctionList1[1])[0],
04068 complexPyramidItr->at(junctionList2[0])[0],
04069 complexPyramidItr->at(junctionList2[1])[0],
04070 &Alpha,&Beta,&complexPyramidItr->at(i)[0]);
04071
04072
04073 Raster::WriteGray(complexPyramidItr->at(i)[0]*255.0F,
04074 sformat("imgH1.junc.%d.%s.out.pgm",
04075 s,_label.c_str()));
04076
04077
04078 fCVmixChannels(complexPyramidItr->at(junctionList1[0])[1],
04079 complexPyramidItr->at(junctionList1[1])[1],
04080 complexPyramidItr->at(junctionList2[0])[1],
04081 complexPyramidItr->at(junctionList2[1])[1],
04082 &Alpha,&Beta,&complexPyramidItr->at(i)[1]);
04083
04084
04085 Raster::WriteGray(complexPyramidItr->at(i)[1]*255.0F,
04086 sformat("imgH2.junc.%d.%s.out.pgm",
04087 s,_label.c_str()));
04088
04089 fCVmixChannels(complexPyramidItr->at(junctionList1[0])[2],
04090 complexPyramidItr->at(junctionList1[1])[2],
04091 complexPyramidItr->at(junctionList2[0])[2],
04092 complexPyramidItr->at(junctionList2[1])[2],
04093 &Alpha,&Beta,&complexPyramidItr->at(i)[2]);
04094
04095
04096 Raster::WriteGray(complexPyramidItr->at(i)[2]*255.0F,
04097 sformat("imgS.junc.%d.%s.out.pgm",
04098 s,_label.c_str()));
04099
04100 fCVmixChannels(complexPyramidItr->at(junctionList1[0])[3],
04101 complexPyramidItr->at(junctionList1[1])[3],
04102 complexPyramidItr->at(junctionList2[0])[3],
04103 complexPyramidItr->at(junctionList2[1])[3],
04104 &Alpha,&Beta,&complexPyramidItr->at(i)[3]);
04105
04106
04107 Raster::WriteGray(complexPyramidItr->at(i)[3]*255.0F,
04108 sformat("imgV.junc.%d.%s.out.pgm",
04109 s,_label.c_str()));
04110 }
04111 }
04112
04113 currentImage = rescaleBilinear(currentImage,
04114 currentImage.getWidth()/2,
04115 currentImage.getHeight()/2);
04116
04117
04118 if(s < scales-1)
04119 {
04120
04121
04122 LINFO("DOWNSCALE");
04123 Image<PixRGB<FLOAT> > Cmask = downscaleFancy(CmaskFile,
04124 currentImage.getWidth()
04125 ,masks[s].getHeight()/2,1
04126 ,true);
04127
04128
04129
04130 getGrey(Cmask,masks[s+1]);
04131 masks[s+1] = masks[s+1]*255.0F;
04132 Raster::WriteGray(masks[s+1],
04133 sformat("masks.%d.%s.out.pgm",
04134 s,_label.c_str()));
04135
04136
04137 }
04138 }
04139
04140 std::string noutFile = _outFile + ".complex.stats.out.txt";
04141
04142 LINFO("WRITING %s", noutFile.c_str());
04143 std::ofstream outFile(noutFile.c_str(),std::ios::app);
04144 s = 0;
04145
04146 for(typename std::vector<std::vector<std::vector<Image<FLOAT> > > >::iterator
04147 complexPyramidItr = complexPyramid.begin();
04148 complexPyramidItr != complexPyramid.end();
04149 ++complexPyramidItr, s++)
04150 {
04151 unsigned int i = 0;
04152
04153 for(typename std::vector<std::vector<Image<FLOAT> > >::iterator rotationItr =
04154 complexPyramidItr->begin(); rotationItr != complexPyramidItr->end();
04155 ++rotationItr, i++)
04156 {
04157 LINFO("COMPUTING over scale %d rot %d",s,rotations[i]);
04158 maskOffset = (masks[s].getHeight() - rotationItr->at(0).getHeight())/2;
04159 H1itr = rotationItr->at(0).beginw();
04160 H2itr = rotationItr->at(1).beginw();
04161 Sitr = rotationItr->at(2).beginw();
04162 Vitr = rotationItr->at(3).beginw();
04163
04164 FLOAT H1onMean, H2onMean, SonMean, VonMean;
04165 FLOAT H1onSTD, H2onSTD, SonSTD, VonSTD;
04166 FLOAT H1onSum = 0; FLOAT H2onSum = 0;
04167 FLOAT SonSum = 0; FLOAT VonSum = 0;
04168 double H1onSS = 0; double H2onSS = 0;
04169 double SonSS = 0; double VonSS = 0;
04170
04171 FLOAT H1offMean, H2offMean, SoffMean, VoffMean;
04172 FLOAT H1offSTD, H2offSTD, SoffSTD, VoffSTD;
04173 FLOAT H1offSum = 0; FLOAT H2offSum = 0;
04174 FLOAT SoffSum = 0; FLOAT VoffSum = 0;
04175 double H1offSS = 0; double H2offSS = 0;
04176 double SoffSS = 0; double VoffSS = 0;
04177
04178 FLOAT H1Mean, H2Mean, SMean, VMean;
04179 FLOAT H1STD, H2STD, SSTD, VSTD;
04180 FLOAT H1Sum = 0; FLOAT H2Sum = 0;
04181 FLOAT SSum = 0; FLOAT VSum = 0;
04182 double H1SS = 0; double H2SS = 0;
04183 double SSS = 0; double VSS = 0;
04184
04185 FLOAT maskMeanX, maskMeanY, maskSTDX, maskSTDY;
04186 FLOAT maskSumX = 0; FLOAT maskSumY = 0;
04187 double maskSSX = 0; double maskSSY = 0;
04188 unsigned long maskMass = 0;
04189 unsigned long nonMaskMass = 0;
04190 unsigned long totalMass = 0;
04191
04192
04193
04194 typename Image<FLOAT>::iterator Mitr = masks[s].beginw() +
04195 (int)(masks[s].getWidth() * maskOffset);
04196
04197
04198 LINFO("COMPUTING mass values");
04199 for(typename Image<FLOAT>::iterator currentItr =
04200 rotationItr->at(0).beginw();
04201 currentItr != rotationItr->at(0).endw(); ++Mitr, ++currentItr)
04202 {
04203 if(*Mitr > 0.01F)
04204 {
04205 maskMass++;
04206 }
04207 else
04208 {
04209 nonMaskMass++;
04210 }
04211 totalMass++;
04212 }
04213
04214 LINFO("MASS mask %lx non-mask %lx total %lx",maskMass,nonMaskMass,
04215 totalMass);
04216
04217 Mitr = masks[s].beginw() +
04218 (int)(masks[s].getWidth() * maskOffset);
04219 unsigned int x = 0;
04220
04221
04222
04223
04224 for(typename Image<FLOAT>::iterator currentItr =
04225 rotationItr->at(0).beginw();
04226 currentItr != rotationItr->at(0).endw();
04227 ++currentItr,++H1itr,++H2itr,++Sitr,++Vitr, ++Mitr, x++)
04228 {
04229
04230 if(*Mitr > 0.01F)
04231 {
04232 maskSumX += x % rotationItr->at(0).getWidth();
04233 maskSumY += x / rotationItr->at(0).getWidth();
04234 H1onSum = *H1itr + H1onSum;
04235 H2onSum = *H2itr + H2onSum;
04236 SonSum = *Sitr + SonSum;
04237 VonSum = *Vitr + VonSum;
04238
04239 maskSSX += pow((FLOAT)(x % rotationItr->at(0).getWidth()),2)
04240 /maskMass;
04241 maskSSY += pow((FLOAT)(x / rotationItr->at(0).getWidth()),2)
04242 /maskMass;
04243 H1onSS = (pow(*H1itr,2) /maskMass) + H1onSS;
04244 H2onSS = (pow(*H2itr,2) /maskMass) + H2onSS;
04245 SonSS = (pow(*Sitr,2) /maskMass) + SonSS;
04246 VonSS = (pow(*Vitr,2) /maskMass) + VonSS;
04247 }
04248
04249 else
04250 {
04251
04252
04253 H1offSum = *H1itr + H1offSum;
04254 H2offSum = *H2itr + H2offSum;
04255 SoffSum = *Sitr + SoffSum;
04256 VoffSum = *Vitr + VoffSum;
04257
04258 H1offSS = (pow(*H1itr,2)/nonMaskMass) + H1offSS;
04259 H2offSS = (pow(*H2itr,2)/nonMaskMass) + H2offSS;
04260 SoffSS = (pow(*Sitr,2) /nonMaskMass) + SoffSS;
04261 VoffSS = (pow(*Vitr,2) /nonMaskMass) + VoffSS;
04262 }
04263
04264
04265 H1Sum = *H1itr + H1Sum;
04266 H2Sum = *H2itr + H2Sum;
04267 SSum = *Sitr + SSum;
04268 VSum = *Vitr + VSum;
04269
04270 H1SS = (pow(*H1itr,2)/totalMass) + H1SS;
04271 H2SS = (pow(*H2itr,2)/totalMass) + H2SS;
04272 SSS = (pow(*Sitr,2) /totalMass) + SSS;
04273 VSS = (pow(*Vitr,2) /totalMass) + VSS;
04274 }
04275
04276 LINFO("COMPUTING TOTAL STATS");
04277
04278
04279 maskMeanX = maskSumX/maskMass; maskMeanY = maskSumY/maskMass;
04280 H1onMean = H1onSum /maskMass; H2onMean = H2onSum /maskMass;
04281 SonMean = SonSum /maskMass; VonMean = VonSum /maskMass;
04282 maskSTDX = sqrt(maskSSX - pow(maskMeanX,2));
04283 maskSTDY = sqrt(maskSSY - pow(maskMeanY,2));
04284 H1onSTD = sqrt(H1onSS - pow(H1onMean,2));
04285 H2onSTD = sqrt(H2onSS - pow(H2onMean,2));
04286 SonSTD = sqrt(SonSS - pow(SonMean,2));
04287 VonSTD = sqrt(VonSS - pow(VonMean,2));
04288
04289
04290 H1offMean = H1offSum /nonMaskMass; H2offMean = H2offSum /nonMaskMass;
04291 SoffMean = SoffSum /nonMaskMass; VoffMean = VoffSum /nonMaskMass;
04292 H1offSTD = sqrt(H1offSS - pow(H1offMean,2));
04293 H2offSTD = sqrt(H2offSS - pow(H2offMean,2));
04294 SoffSTD = sqrt(SoffSS - pow(SoffMean,2));
04295 VoffSTD = sqrt(VoffSS - pow(VoffMean,2));
04296
04297
04298 H1Mean = H1Sum /totalMass; H2Mean = H2Sum /totalMass;
04299 SMean = SSum /totalMass; VMean = VSum /totalMass;
04300 H1STD = sqrt(H1SS - pow(H1Mean,2));
04301 H2STD = sqrt(H2SS - pow(H2Mean,2));
04302 SSTD = sqrt(SSS - pow(SMean,2));
04303 VSTD = sqrt(VSS - pow(VMean,2));
04304
04305 LINFO("WRITING STATS TO FILE");
04306
04307
04308 outFile << _label << "\t";
04309 outFile << s << "\t" << rotations[i] << "\t";
04310 outFile << maskMass << "\t" << nonMaskMass << "\t" << totalMass << "\t";
04311
04312
04313 outFile << maskMeanX << "\t" << maskSTDX << "\t"
04314 << maskMeanY << "\t" << maskSTDY << "\t"
04315 << H1onMean << "\t" << H1onSTD << "\t"
04316 << H2onMean << "\t" << H2onSTD << "\t"
04317 << SonMean << "\t" << SonSTD << "\t"
04318 << VonMean << "\t" << VonSTD << "\t";
04319
04320
04321 outFile << H1offMean << "\t" << H1offSTD << "\t"
04322 << H2offMean << "\t" << H2offSTD << "\t"
04323 << SoffMean << "\t" << SoffSTD << "\t"
04324 << VoffMean << "\t" << VoffSTD << "\t";
04325
04326
04327 outFile << H1Mean << "\t" << H1STD << "\t"
04328 << H2Mean << "\t" << H2STD << "\t"
04329 << SMean << "\t" << SSTD << "\t"
04330 << VMean << "\t" << VSTD << "\n";
04331 }
04332 }
04333 }
04334
04335
04336
04337
04338
04339 template class featureClusterVision<float>;