featureClusterVision.C

Go to the documentation of this file.
00001 /*!@file VFAT/featureClusterVision.C  Test the nonparametric classifier
00002  */
00003 
00004 // //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00006 // University of Southern California (USC) and the iLab at USC.         //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: T Nathan Mundhenk <mundhenk@usc.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/VFAT/featureClusterVision.C $
00036 // $Id: featureClusterVision.C 14376 2011-01-11 02:44:34Z pez $
00037 //
00038 
00039 // ############################################################
00040 // ############################################################
00041 // ##### --- VFAT ---
00042 // ##### Vision Feature Analysis Tool:
00043 // ##### T. Nathan Mundhenk nathan@mundhenk.com
00044 // ##### Laurent Itti itti@pollux.usc.edu
00045 // #####
00046 // ############################################################
00047 // ############################################################
00048 
00049 #include "VFAT/featureClusterVision.H"
00050 
00051 #include "Image/Conversions.H"     // for vectorToImage()
00052 #include "Image/Kernels.H"         // for gaborFilter()
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   // Moved getColor() and getGrey() here during Image class cleanup,
00072   // they could go somewhere else eventually but this seemed to be the
00073   // only place that was using them.
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 // NOTE: The bulk of the code here is just to load values from config files
00107 // and to set up basic data structures.
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   // config file for NP classify
00166   std::cerr << "(1) SETTING readConfig Objects";
00167   readConfig NPConfig(25);
00168   // config file for local method (this one)
00169   std::cerr << ".";
00170   readConfig localConfig(25);
00171   // config file for kernel parameters in NPconfig
00172   std::cerr << ".\n";
00173   readConfig KernelConfig(25);
00174 
00175   std::cerr << "(2) READING readConfig Files\n";
00176   // load config values for local config
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   // create NP classify object
00183   fCV_NP.NPsetup(NPConfig,KernelConfig,false);
00184   //resize vectors
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   // This is currently equal to 22
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(); // taken from input image
00199   fCV_sizeY = fuck.getHeight(); // taken from input image
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   // initialized to 0 to avoid "warning: ‘temppPoint’ is used
00212   // uninitialized in this function" with g++ 4.1
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     //ttemp = rm.returnMatrixAsImage();
00246     //fCV_ICAunmix[i] = transpose(ttemp);
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   // fCV_featureNameICA.resize(secretVariable,&temp);
00262   // load in these values as individual values but create a vector of
00263   // pointers for quick reference
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   // New combined motion channel
00309   fCV_motionCombinedOn = localConfig.getItemValueB("motionCombinedOn");
00310   fCV_featureOn[16] = &fCV_motionCombinedOn;
00311   fCV_featureName[16] = "MotionCombined";
00312   // color channels
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   // load in these values as individual values but create a vector of
00341   // pointers for quick reference
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   // New combined motion channel weights
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   // color weights
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   // New combined motion channel ICA
00507   fCV_ICAfeaturesMotionCombined =
00508     (int)localConfig.getItemValueF("ICAfeaturesMotionCombined");
00509   fCV_ICAfeaturesPerChannel[16] = &fCV_ICAfeaturesMotionCombined;
00510   // color ICA
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   //fCV_useCovHolderUp = true;
00559   fCV_doMatchSelf = true;
00560   fCV_doSLPTB = false;
00561 
00562   //get the low pass kernel
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   //std::vector<FLOAT> tempVecDp;
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   //fCV_tcov.featureName = &fCV_featureNameICA;
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   //fCV_covHolderUp.resize(COVSIZE,fCV_tcov);
00665   //fCV_covHolderDown.resize(COVSIZE,fCV_tcov);
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     //Raster::VisuFloat(*igaborFilters,FLOAT_NORM_0_255,sformat("image.gabor.sin.%d.pgm",iii));
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     //Raster::VisuFloat(*igaborFilters,FLOAT_NORM_0_255,sformat("image.gabor.cos.%d.pgm",iii));
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   //LINFO("%d %d",outAlpha->size(),data->size());
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   //LINFO("MIXING CHANNELS");
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     //LINFO("%d",i);
00757     // compute lineyness at location (strength of line)
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     // compute crossyness at location (strength of junction)
00761     c1Gmix = (((data->at(i)[ch1a])+(data->at(i)[ch1b]))/(norm1));
00762     c2Gmix = (((data->at(i)[ch2a])+(data->at(i)[ch2b]))/(norm2));
00763     // Indicates general intensity of the output
00764     *iOutA = (c1Gmix+c2Gmix)/2;
00765     //LINFO("ALPHA %f", *iOutA);
00766     // Finish computing crossyness by subtracting lineyness
00767     // indicates the crispness of lines
00768     *iOutB = fabs(c1mix-c2mix)/2;
00769     //c1Gmix = c1mix - c1Gmix;
00770     //c2Gmix = c2mix - c2Gmix;
00771     //LINFO("BETA %f", *iOutB);
00772     // indicates the crispness of junctions
00773     *iOutG = *iOutA - *iOutB;
00774     //LINFO("GAMMA %f",*iOutG);
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   // compute lineyness at this location
00797   Image<FLOAT> mix1  = abs(img0  - img90) /norm1;
00798   Image<FLOAT> mix2  = abs(img45 - img135)/norm2;
00799 
00800   // compute crossyness at this location
00801   Image<FLOAT> mixG1 = (img0  + img90) /norm1;
00802   Image<FLOAT> mixG2 = (img45 + img135)/norm1;
00803 
00804   // Average crossyness
00805   *Alpha = (mixG1 + mixG2)/2;
00806 
00807   // Average Lineyness
00808   *Beta  = abs(mix1 - mix2)/2;
00809 
00810   // Crispness of junctions
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     //LINFO("MIXING ORIENTATIONS");
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     //LINFO("MIXING MOTIONS");
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 // TEST METHODS
00861 // ######################################################################
00862 // ######################################################################
00863 
00864 #if 0
00865 // FIXME These functions doesn't compile cleanly anymore because
00866 // VisualCortex::getFeatures() expects a std::vector<double>, but
00867 // we're trying to pass it a std::vector<float>.
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   //---------------Get Saliency Data---------------//
00876   std::cerr << "(1) GETTING saliency data \n";
00877   // get the current saliency map see Brain.C for examples
00878   /////fCV_SM = fCV_brain->getSM();
00879   /////fCV_VC = fCV_brain->getVC();
00880   Image<FLOAT> salmap;///////// = fCV_SM->getV(false);
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   // get sal values for each point into a vector fmap
00897   for(int i = 0; i < salmap.getWidth(); i++)
00898   {
00899     for(int j = 0; j < salmap.getHeight(); j++)
00900     {
00901       //void getFeatures(const Point2D<int>& locn, std::vector<FLOAT>& mean) const;
00902       // see VisualCortex.*
00903       //LINFO("SETTING %d",(j*salmap.getWidth())+i);
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   // check ICA on mixed channels
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   //foosh = ICAoutput1;
00943   //Raster::VisuFloat(foosh,FLOAT_NORM_0_255,"foo.pgm");
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     //Raster::VisuRGB(outputClass,"CLASS_%d.pnm",i);
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   //---------------Get Saliency Data---------------//
01056   std::cerr << "(1) GETTING saliency data \n";
01057   // get the current saliency map see Brain.C for examples
01058   ///////fCV_SM = fCV_brain->getSM();
01059   //////fCV_VC = fCV_brain->getVC();
01060   Image<FLOAT> salmap;//////////////// = fCV_SM->getV(false);
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   // get sal values for each point into a vector fmap
01080   for(int i = 0; i < salmap.getWidth(); i++)
01081   {
01082     for(int j = 0; j < salmap.getHeight(); j++)
01083     {
01084       //void getFeatures(const Point2D<int>& locn, std::vector<FLOAT>& mean) const;
01085       // see VisualCortex.*
01086       //LINFO("SETTING %d",(j*salmap.getWidth())+i);
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   //---------------Get Saliency Data---------------//
01147   std::cerr << "(1) GETTING saliency data \n";
01148   // get the current saliency map see Brain.C for examples
01149   ///////fCV_SM = fCV_brain->getSM();
01150   //////fCV_VC = fCV_brain->getVC();
01151   Image<FLOAT> salmap;/////////////// = fCV_SM->getV(false);
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   // get sal values for each point into a vector fmap
01163   for(int i = 0; i < salmap.getWidth(); i++)
01164   {
01165     for(int j = 0; j < salmap.getHeight(); j++)
01166     {
01167       //void getFeatures(const Point2D<int>& locn, std::vector<FLOAT>& mean) const;
01168       // see VisualCortex.*
01169       //LINFO("SETTING %d",(j*salmap.getWidth())+i);
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   //shit = ifmap;
01201   //Raster::VisuFloat(shit,FLOAT_NORM_0_255,"InputFeatures.pgm");
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   // TOTAL FUDGE REMOVE IF WANTED //
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       //LINFO("%f",unmixedImage.getVal(i,j));
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();  // to measure display time
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   // resize (scales * HSV2 * angles) + junctions;
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   //Image<PixH2SV<FLOAT> > imageH2SV = fCV_realImageLowPass;
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       //LINFO("%f",fCV_standAloneFeatures[i][j].h1);
01350       fCV_standAloneFeatures[i][j].setH2(
01351         fabs(fCV_standAloneFeaturesSin[i][j].H2()) +
01352         fabs(fCV_standAloneFeaturesCos[i][j].H2()));
01353       //LINFO("%f",fCV_standAloneFeatures[i][j].h2);
01354       fCV_standAloneFeatures[i][j].setS(
01355         fabs(fCV_standAloneFeaturesSin[i][j].S()) +
01356         fabs(fCV_standAloneFeaturesCos[i][j].S()));
01357       //LINFO("%f",fCV_standAloneFeatures[i][j].s);
01358       fCV_standAloneFeatures[i][j].setV(
01359         fabs(fCV_standAloneFeaturesSin[i][j].V()) +
01360         fabs(fCV_standAloneFeaturesCos[i][j].V()));
01361       //LINFO("%f",fCV_standAloneFeatures[i][j].v);
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();  // to measure display time
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   // load ICA unmixing matrix for junctions
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   // resize (scales * HSV2 * angles) + junctions;
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   // Color
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   // Value Only
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   // load up the image matrix
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     //outImage = lowPass9(outImage);
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     //outImage = lowPass9(outImage);
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 // MAIN WORKING PRIVATE METHODS
01792 // ######################################################################
01793 // ######################################################################
01794 template <class FLOAT>
01795 void featureClusterVision<FLOAT>::fCVswitchCov()
01796 {
01797 
01798   // Alternate pointers between covHolder objects
01799   // this is done to keep a record of the last iter. results
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   //Raster::VisuRGB(fCV_realImageLowPass,"LP.ppm");
01841   //Raster::VisuRGB(fCV_realImage,"real.ppm");
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();  // to measure display time
01853 
01854   //---------------Get Saliency Data---------------//
01855   //std::cerr << "(1) GETTING saliency data \n";
01856   // get the current saliency map see Brain.C for examples
01857   ///////fCV_SM = fCV_brain->getSM();
01858   ///////fCV_VC = fCV_brain->getVC();
01859   Image<FLOAT> salmap;/////////////// = fCV_SM->getV(false);
01860   LFATAL("FIXME");
01861   Image<FLOAT> salmapOut = salmap;
01862 
01863   // apply temporal band pass to saliency map
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   //std::cerr << "...model objects fetched\n";
01887 
01888   // make sure the salmap is less than the size of the Cmap
01889   ASSERT(salmap.getSize() <= (signed)fCV_cmap.size());
01890 
01891   // find a sparcer represntation of salincy map by treating salmap as
01892   // a map of statistical values. See function in Image_MathOps.*
01893   Image<FLOAT> smap = salmap;
01894 
01895   //Raster::WriteRGB(smap1,sformat("%s.out.salmapBias.ppm",fCV_fileName.c_str()));
01896   Image<FLOAT> fooshit = rescaleBilinear(fCV_salmapLowPass,fCV_sizeX,fCV_sizeY);
01897 
01898   //Raster::VisuFloat(fooshit,FLOAT_NORM_0_255,
01899   //sformat("%s.out.salmap.pgm",fCV_fileName.c_str()));
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   //std::cerr << "...First pass found " << fCV_countMM << " points\n";
01918 
01919   // Make the cmap sparser by decimation (see Image_MathOps.*
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     //LINFO("A2");
01942     //LINFO("%d %d %d",i,(*irmap)->i,(*irmap)->j);
01943 
01944     (*irmap)->i = (*irmap)->i * 3;
01945     (*irmap)->j = (*irmap)->j * 3;
01946     //LINFO("%d %d %d",i,(*irmap)->i,(*irmap)->j);
01947     //LINFO("SALMAP SIZE %d %d",salmap.getWidth(),salmap.getHeight());
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   // get sal values for each point into a vector fmap
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     //pix = filterAtLocation(&fCV_realImageLowPass,&fCV_lowPassKernel,
01973     //                         &*fCV_rmap[i]);
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   ///////////////////  fCV_VC->getFeaturesBatch(&fCV_rmap,&fCV_fmap,&fCV_countSM);
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();  // to measure display time
02003 
02004   //---------------Get Saliency Data---------------//
02005   //std::cerr << "(1) GETTING saliency data \n";
02006   // get the current saliency map see Brain.C for examples
02007 
02008   // apply temporal band pass to saliency map
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   //std::cerr << "...model objects fetched\n";
02032 
02033   // make sure the salmap is less than the size of the Cmap
02034   ASSERT(salmap.getSize() <= (signed)fCV_cmap.size());
02035 
02036   // find a sparcer represntation of salincy map by treating salmap as
02037   // a map of statistical values. See function in Image_MathOps.*
02038   Image<FLOAT> smap = salmap;
02039 
02040   //Raster::WriteRGB(smap1,sformat("%s.out.salmapBias.ppm",fCV_fileName.c_str()));
02041   //Raster::WriteRGB(smap2,sformat("%s.out.salmap.ppm",fCV_fileName.c_str()));
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   //std::cerr << "...First pass found " << fCV_countMM << " points\n";
02060 
02061   // Make the cmap sparser by decimation (see Image_MathOps.*
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     //LINFO("A2");
02084     //LINFO("%d %d %d",i,(*irmap)->i,(*irmap)->j);
02085 
02086     (*irmap)->i = (*irmap)->i * 3;
02087     (*irmap)->j = (*irmap)->j * 3;
02088     //LINFO("%d %d %d",i,(*irmap)->i,(*irmap)->j);
02089     //LINFO("SALMAP SIZE %d %d",salmap.getWidth(),salmap.getHeight());
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   // get sal values for each point into a vector fmap
02106 
02107   //if(fCV_lowPassType == 5)
02108   //{
02109   // if(fCV_lowPassVector.size() < fCV_rmap.size())
02110   // {
02111   //   PixRGB<FLOAT> tempish;
02112   //   fCV_lowPassVector.resize(fCV_rmap.size(),tempish);
02113   // }
02114   // filterAtLocationBatch(&fCV_realImageLowPass,&fCV_lowPassKernel, &fCV_rmap,
02115   //                      &fCV_lowPassVector,fCV_countSM);
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   // get values from conspicuity maps with simple interpolation
02127 
02128   // first iterate over each feature location
02129 
02130   //#######################################################
02131   // get feaures stand alone
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   //---------------Get Saliency Data---------------//
02150   //std::cerr << "(1) GETTING saliency data \n";
02151   // get the current saliency map see Brain.C for examples
02152   //////fCV_SM = fCV_brain->getSM();
02153   //////fCV_VC = fCV_brain->getVC();
02154   Image<FLOAT> salmap;////////////// = fCV_SM->getV(false);
02155   LFATAL("FIXME");
02156   Image<FLOAT> salmapOut = salmap;
02157 
02158   // apply temporal band pass to saliency map
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   // make sure the salmap is less than the size of the Cmap
02171   ASSERT(salmap.getSize() <= (signed)fCV_cmap.size());
02172 
02173   // find a sparcer represntation of salincy map by treating salmap as
02174   // a map of statistical values. See function in Image_MathOps.*
02175   //Image<PixRGB<FLOAT> > realImageCopy =  fCV_realImage;
02176   //PixRGB<FLOAT> mrPixel;
02177   //mrPixel.setRed(255); mrPixel.setBlue(128); mrPixel.setGreen(0);
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       /*std::cout << values[0] << "\t"
02197                 << values[1] << "\t"
02198                 << values[2] << "\t"
02199                 << values[3] << "\t"
02200                 << values[4] << "\t"
02201                 << values[5] << "\t"
02202                 << values[6] << "\n";*/
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         //drawCircle(realImageCopy, fCV_cmap[sampleNumber],3,mrPixel,2);
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   //Raster::WriteRGB(realImageCopy,sformat("%s.out.eyeDataOver.ppm"
02231   //               ,fileName.c_str()));
02232   LINFO("FOUND %d samples from %s",sampleNumber,fileName.c_str());
02233   fCV_countSM = sampleNumber;
02234 
02235   // resize sample containers
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     /*LINFO("VALS %d,%d", fCV_rmap[i]->i,fCV_rmap[i]->j);*/
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   // get sal values for each point into a vector fmap
02251   /////////////////////  fCV_VC->getFeaturesBatch(&fCV_rmap,&fCV_fmap,&fCV_countSM);
02252 }
02253 
02254 // ######################################################################
02255 template <class FLOAT>
02256 void featureClusterVision<FLOAT>::fCVrunICA()
02257 {
02258 
02259 
02260   //---------------Run ICA unmixing per Channel---------------//
02261   //std::cerr << "(2) RUNNING ICA unmixing\n";
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   //index_itr = fCV_featureMatrixSizes.begin();
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   // make sure channel size and matrix sizes match
02287   ASSERT(fCV_Unmixed.size() == fCV_featureMatrixSizes.size());
02288   ASSERT(fCV_Unmixed.size() == fCV_ICAunmix.size());
02289   // convert vector to image
02290   //LINFO("SIZEEE 2 %d x %d",fCV_fmap.size(),fCV_fmap[0].size());
02291 
02292   Image<FLOAT> ifmap = vectorToImage(fCV_fmap);
02293   Image<FLOAT> mmmap = vectorToImage(fCV_mixedRotation);
02294   Image<FLOAT> mmap = transpose(mmmap);
02295 
02296   // print out feature map if desired
02297   //if(fCV_printOutFeatures == true)
02298   //{
02299   //  Image<FLOAT> tfoo = ifmap;
02300   //  Raster::WriteGray(tfoo,sformat("%s.out.featureSet.pgm",fCV_fileName.c_str()));
02301   //}
02302   // create indexes into matrices
02303   unsigned int pStart = 0; unsigned int pStop = 0;
02304   unsigned int zero = 0;
02305   unsigned int sm = (unsigned)fCV_countSM;
02306   // multiply each feature set (channel) by it's unmixing matrix for ICA
02307   // store output
02308   int current = 0;
02309   int iter = 0;
02310   long colorOffset = 0;
02311 
02312   //LINFO("GO");
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       /*std::cerr << "Iter " << iter
02330                 << "...Matrix sizes 1) " << ifmap.getWidth() << " x "
02331                 << ifmap.getHeight() << " 2) "
02332                 << image_itr->getWidth() << " x "
02333                 << image_itr->getHeight() << "\n"
02334                 << "...Interval " << pStart << " - "
02335                 << pStop << "\n";*/
02336     }
02337     else
02338     {
02339       width = (unsigned)(image_itr-1)->getWidth();
02340       /*std::cerr << "Iter " << iter+1
02341                 << "...Matrix sizes 1) " << ifmap.getWidth() << " x "
02342                 << ifmap.getHeight() << " 2) "
02343                 << (image_itr-1)->getWidth() << " x "
02344                 << (image_itr-1)->getHeight() << "\n"
02345                 << "...Interval " << pStart << " - "
02346                 << pStop << "\n";*/
02347     }
02348 
02349     if(**featureOn_itr == true)
02350     {
02351       if(iter < fCV_mixOffset)
02352       {
02353         //std::cerr << ">>>Regular Channel " << fCV_featureName[iter]
02354         //        << " is On - Offset: " << iter << "\n";
02355         *unmixed_itr = matrixMult(ifmap,*image_itr,pStart,pStop,
02356                                   zero,width,zero,sm);
02357         //std::cerr << "\tData width: " << unmixed_itr->getWidth() << "\n";
02358         /*
02359         for(int ii = 0; ii <  (image_itr-1)->getWidth(); ii++)
02360         {
02361           for(int jj = 0; jj < (image_itr-1)->getHeight(); jj++)
02362           {
02363             std::cout << (image_itr-1)->getVal(ii,jj);
02364           }
02365           std::cout << "\n";
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           //std::cerr << ">>>Mix Channel " << fCV_featureName[iter]
02386           //        << " is On - Offset: " << iter << "\n";
02387           unsigned int st = fCV_featuresPerChannel*(iter-fCV_mixOffset-1);
02388           unsigned int sp = st + (fCV_featuresPerChannel-1);
02389           //LINFO("START %d STOP %d width %d sm %d",st,sp,width,sm);
02390           //LINFO("SIZE %d x %d", mmap.getWidth(), mmap.getHeight());
02391           //LINFO("WIDTH %d",(image_itr-1)->getWidth());
02392           *unmixed_itr = matrixMult(mmap,*(image_itr-1),st,sp,
02393                                   zero,width,zero,sm);
02394           //std::cerr << "\tData width: " << unmixed_itr->getWidth() << "\n";
02395           /*
02396           for(int ii = 0; ii <  (image_itr-1)->getWidth(); ii++)
02397           {
02398             for(int jj = 0; jj < (image_itr-1)->getHeight(); jj++)
02399             {
02400               std::cout << (image_itr-1)->getVal(ii,jj);
02401             }
02402             std::cout << "\n";
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           //std::cerr << ">>>Combined Motion Channel is On - "
02421           //        << fCV_featureName[iter]
02422           //        << " Offset: " << iter << "\n";
02423           unsigned int st = fCV_motOffset*fCV_featuresPerChannel;
02424           unsigned int sp = st + ((fCV_featuresPerChannel*4)-1);
02425           //LINFO("START %d STOP %d width %d sm %d",st,sp,width,sm);
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           //std::cerr << "\tData width: " << unmixed_itr->getWidth() << "\n";
02433           /*
02434           for(int ii = 0; ii <  (image_itr-1)->getWidth(); ii++)
02435           {
02436             for(int jj = 0; jj < (image_itr-1)->getHeight(); jj++)
02437             {
02438               std::cout << (image_itr-1)->getVal(ii,jj);
02439             }
02440             std::cout << "\n";
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           //std::cerr << "<Special Channel is Off>\n";
02458         }
02459       }
02460 
02461       //Image<FLOAT> thisSucks;
02462       //thisSucks = *unmixed_itr;
02463       //Raster::VisuFloat(thisSucks,FLOAT_NORM_0_255,sformat("ICA.%d.pgm",current));
02464       //std::cerr << "done\n";
02465     }
02466     else
02467     {
02468       //std::cerr << "<Channel is Off>\n";
02469     }
02470     pStart = pStop + 1;
02471     // rejoin output into a vector map (uck)
02472     // this takes each image matrix output and appends it onto a
02473     // full output vector
02474     if(doThis == true)
02475     {
02476       //if((iter < newOffset) && (iter != fCV_mixOffset))
02477       //{
02478         space_itr = fCV_space.begin();
02479         i_itr = unmixed_itr->beginw();
02480         //std::cerr << "REJOINING output from feautes in ICA\n";
02481         //std::cerr << "Translate " << translate << " Weight "
02482         //        << weight << " Normalize " << normalize << "\n";
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         //std::cerr << "\t.Added DATA - Width: " << ICAwidth
02495         //        << " At position: " << current << "\n";
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     //std::cerr << ">>>Color Channel is On\n";
02509     PixRGB<FLOAT> pix;
02510     space_itr = fCV_space.begin();
02511     //LINFO("SPACE SIZE %d x %d",fCV_space.size(),fCV_space[0].size());
02512     //LINFO("OFFSET %d", colorOffset);
02513     if(fCV_redOn == true)
02514     {
02515       *featureNameICA_itr = &fCV_featureName[fCV_colorOffset];
02516       //std::cerr << ">>>Color Channel " << fCV_featureName[fCV_colorOffset]
02517       //        << " is On - Offset: " << colorOffset << "\n";
02518       ++featureNameICA_itr;
02519 
02520     }
02521     if(fCV_greenOn == true)
02522     {
02523       *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+1];
02524       //std::cerr << ">>>Color Channel " << fCV_featureName[fCV_colorOffset+1]
02525       //                << " is On - Offset: " << colorOffset << "\n";
02526       ++featureNameICA_itr;
02527     }
02528     if(fCV_blueOn == true)
02529     {
02530       *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+2];
02531       //std::cerr << ">>>Color Channel " << fCV_featureName[fCV_colorOffset+2]
02532       //                << " is On - Offset: " << colorOffset << "\n";
02533       ++featureNameICA_itr;
02534     }
02535     if(fCV_yellowOn == true)
02536     {
02537       *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+3];
02538       //std::cerr << ">>>Color Channel " << fCV_featureName[fCV_colorOffset+3]
02539       //        << " is On - Offset: " << colorOffset << "\n";
02540       ++featureNameICA_itr;
02541     }
02542     if(fCV_hueOn == true)
02543     {
02544       *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+4];
02545       //std::cerr << ">>>Color Channel " << fCV_featureName[fCV_colorOffset+4]
02546       //                << " is On - Offset: " << colorOffset << "\n";
02547       ++featureNameICA_itr;
02548     }
02549     if(fCV_satOn == true)
02550     {
02551       *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+5];
02552       //std::cerr << ">>>Color Channel " << fCV_featureName[fCV_colorOffset+5]
02553       //                << " is On - Offset: " << colorOffset << "\n";
02554       ++featureNameICA_itr;
02555     }
02556     if(fCV_valOn == true)
02557     {
02558       *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+6];
02559       //std::cerr << ">>>Color Channel " << fCV_featureName[fCV_colorOffset+6]
02560       //        << " is On - Offset: " << colorOffset << "\n";
02561       ++featureNameICA_itr;
02562     }
02563     if(fCV_hue1On == true)
02564     {
02565       *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+7];
02566       //std::cerr << ">>>Color Channel " << fCV_featureName[fCV_colorOffset+7]
02567       //        << " is On - Offset: " << colorOffset << "\n";
02568       ++featureNameICA_itr;
02569     }
02570     if(fCV_hue2On == true)
02571     {
02572       *featureNameICA_itr = &fCV_featureName[fCV_colorOffset+8];
02573       //std::cerr << ">>>Color Channel " << fCV_featureName[fCV_colorOffset+8]
02574       //                << " is On - Offset: " << colorOffset << "\n";
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       // did we low pass the whole image or are we just using
02592       // band pass parts
02593       if(fCV_lowPassType == 5)
02594       {
02595         pix = fCV_lowPassVector[i];
02596         //LINFO("VALS %d %f %f %f",i,pix.r,pix.g,pix.b);
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       // LINFO("HSV Fetched");
02642       // WEE
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     //LINFO("DONE");
02675   }
02676 
02677   // if we want to include spatial factors then copy those into the space map
02678   if(fCV_spatialOn == true)
02679   {
02680     //int s1 = fCV_space[0].size() - 2;
02681     //int s2 = fCV_space[0].size() - 1;
02682     //std::cerr << ">>>Spatial Channel "
02683     //        << " is On - Offset: " << s1 << "\n";
02684     //std::cerr << ">>>Spatial Channel "
02685     //        << " is On - Offset: " << s2 << "\n";
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       //LINFO("OUT X VAL = %f", *space_itr_itr);
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       //LINFO("OUT Y VAL = %f", *space_itr_itr);
02706     }
02707   }
02708 
02709 
02710   // print reduced feature map if desired
02711   /*
02712   if(fCV_printOutFeatures == true)
02713   {
02714     Image<FLOAT> foo_ish;
02715     foo_ish  = fCV_space;
02716     Image<FLOAT> foo_me;
02717     foo_me = foo_ish;
02718     Raster::WriteGray(foo_me,sformat("%s.out.featureSetICA.pgm",fCV_fileName.c_str()));
02719   }
02720   */
02721 }
02722 
02723 // ######################################################################
02724 template <class FLOAT>
02725 void featureClusterVision<FLOAT>::fCVrunNPclassify()
02726 {
02727   //---------------Cluster Space with NPclassify---------------//
02728 
02729   //std::cerr << "(3) RUNNING NPclassify\n";
02730   //LINFO("RESETTING SPACE %d x %d",fCV_countSM,fCV_space[0].size());
02731   fCV_NP.NPresetSpace(fCV_countSM,(fCV_space[0].size()));
02732   //LINFO("ADDING SPACE");
02733   fCV_NP.NPaddSpace(fCV_space);
02734   //fCV_NP.NPechoSpace();
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   //LINFO("NP DONE");
02745   std::vector<std::vector<int*> >* foo;
02746   foo = fCV_NP.NPgetClass();
02747   fCV_classList = foo;
02748   fCV_doNPbias = true;
02749 
02750   //if(fCV_printOutClusters == true)
02751   //  fCVprintOutClusters();
02752 }
02753 
02754 // ######################################################################
02755 template <class FLOAT>
02756 void featureClusterVision<FLOAT>::fCVrunCovEstimate()
02757 {
02758   //---------------Find Covariances with covEstimate---------------//
02759 
02760   //std::cerr << "(4) FINDING covariance\n";
02761   for(int i = 0; i < fCV_NP.NPgetStemNumber(); i++)
02762   {
02763     if(fCV_NP.NPgetClassSize(i) > fCV_NP.NPgetMinClassSize())
02764     {
02765       // sort space into sub spaces by class, find the gauss for sub spaces
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           //long item = fCV_NP.NPgetClass(i,j);
02771           //std::cerr << i << " " << j << " " << k << "\n";
02772           /*
02773           fCV_sortedSpace[i][j][k]
02774             = &fCV_space[*fCV_classList->at(i)[j]][k];
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       //std::cerr << "SETTING: covmatrix\n";
02786       // insert Data
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       //fCV_CV.printDebug();
02796       // (1) find means in space
02797       //std::cerr << "FINDING mean\n";
02798       fCV_CV.run();
02799 
02800       //if(i == 0)
02801       //        fCVprintOutCovSlices(fCV_sizeX,fCV_sizeY);
02802       //fCV_CV.printEigenVals();
02803     }
02804   }
02805 }
02806 
02807 // ######################################################################
02808 template <class FLOAT>
02809 void featureClusterVision<FLOAT>::fCVcheckParticles()
02810 {
02811   //LINFO("CHECKING PARTICLES");
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       //LINFO("MEAN %f STD %f BIAS %f",meanClassDensity->at(i),
02823       //            stdClassDensity->at(i),fCV_densityBias);
02824       //LINFO("THRESH %f",thresh);
02825       // sort space into sub spaces by class, find the gauss for sub spaces
02826       for(int j = 0; j < fCV_NP.NPgetClassSize(i); j++)
02827       {
02828         //LINFO("CHECKING %d",fCV_NP.NPgetClass(i,j));
02829         //LINFO("THRESH %f",thresh);
02830         //LINFO("DENSITY %f",density->at(fCV_NP.NPgetClass(i,j)));
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   //LINFO("CLASS MATCH TEMPORAL");
02849   fCV_sortClassSize.resize(fCV_NP.NPgetStemNumber()+1,0);
02850   fCV_sortClassMember.resize(fCV_NP.NPgetStemNumber()+1,0);
02851   fCV_sortCount = 0;
02852 
02853   // sort classes based upon size
02854 
02855   for(int i = 0; i < fCV_NP.NPgetStemNumber(); i++)
02856   {
02857     // if I am the first class, set me as number 1
02858     if(fCV_sortCount == 0)
02859     {
02860       //LINFO("SETTING first class at %d size %d",i,NP.NPgetClassSize(i));
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       // look through the entire list in order
02869       long initSC = fCV_sortCount;
02870       for(long j = 0; j < initSC; j++)
02871       {
02872         // if I am bigger than someone, bump him and
02873         // everyone else back one, insert me
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   //LINFO("SETTING COVHOLDER");
02903   for(int i = 0; i < fCV_sortCount; i++)
02904   {
02905     long *thisClass = &fCV_sortClassMember[i];
02906     //LINFO("THIS CLASS %d",*thisClass);
02907     fCV_covHolderCurrent->at(*thisClass).sortID = i;
02908   }
02909 
02910   //LINFO("MATCHING ID");
02911   // set match ID at first iteration
02912   if(fCV_doMatchSelf == true)
02913   {
02914     for(unsigned int i = 0; i < fCV_covDataSizeCurrent; i++)
02915     {
02916       //LINFO("MATCHING SELF (real) %d",i);
02917       //LINFO("Size %d",fCV_covHolderCurrent->at(i).samples);
02918       fCV_covHolderCurrent->at(i).matchID = i;
02919     }
02920     fCV_doMatchSelf = false;
02921   }
02922   else
02923   {
02924     //LINFO("CALLING MATCH PMEAN new size %d, old size %d",
02925     //    fCV_covDataSizeCurrent,fCV_covDataSizeMatch);
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     //LINFO("%d : SIZE %d",i,fCV_covHolderCurrent->at(i).samples);
02939     //LINFO("%d : MATCHED at %d",i,
02940     //    fCV_covHolderCurrent->at(i).matchID);
02941 
02942     //unsigned int current = fCV_covHolderCurrent->at(i).matchID;
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 // CALL ALL IMPORTANT METHODS IN ORDER
02987 // This is the main execution path
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();  // to measure display time
02999   // (-1) switch the pointers between frames for i and i-1
03000   LINFO("SWITCH COV");
03001   fCVswitchCov();
03002   /////t3 = t2;
03003   t1 = tim.get();
03004   t2 = t1 - t0;
03005   /////t3 = t2 - t3;
03006   std::cerr << "\t>>>>>>>> fCV (SWITCH COV) TIME: " << t2 << "ms\n";
03007   if(fCV_useTimerFile == true)
03008     timerFile << t2 << "\t";
03009   // (0) Low Pass the real image if needed for color extraction
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   // (1) get features from saliency map using MC method
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   // (2) Mix orientation and motion channles into rotation invariant info
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   // (3) Reduce and purify data with ICA/PCA
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   // (4) cluster data sets
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   // (5) find statistical relevance
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   // (6) process clusters, sort by size and match between iterations
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   // (x) print out the basic stuff that we found
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   // (7) Check with features that were extracted should be re-used
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   // (8) reset the NPclassifier
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();  // to measure display time
03152   // (-1) switch the pointers between frames for i and i-1
03153   LINFO("SWITCH COV");
03154   fCVswitchCov();
03155   /////t3 = t2;
03156   t1 = tim.get();
03157   t2 = t1 - t0;
03158   /////t3 = t2 - t3;
03159   std::cerr << "\t>>>>>>>> fCV (SWITCH COV) TIME: " << t2 << "ms\n";
03160   // (0) Low Pass the real image if needed for color extraction
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   // (1) get features from saliency map using MC method
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   // (2) Mix orientation and motion channles into rotation invariant info
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   // (3) Reduce and purify data with ICA/PCA
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   // (4) dump out raw data
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();  // to measure display time
03218   // (-1) switch the pointers between frames for i and i-1
03219   LINFO("SWITCH COV");
03220   fCVswitchCov();
03221   ///  t3 = t2; // what is that supposed to do?
03222   t1 = tim.get();
03223   t2 = t1 - t0;
03224   ///t3 = t2 - t3; // and what about that one??
03225   std::cerr << "\t>>>>>>>> fCV (SWITCH COV) TIME: " << t2 << "ms\n";
03226   if(fCV_useTimerFile == true)
03227     timerFile << t2 << "\t";
03228   // (0) Low Pass the real image if needed for color extraction
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   // (1) get features from saliency map using MC method
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   // (2) Mix orientation and motion channles into rotation invariant info
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   // (2) Mix orientation and motion channles into rotation invariant info
03265   LINFO("FIND MIXED CHANNELS");
03266   //fCVrunStandAloneMSBatchTest(_fileName);
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 // MORE TEST METHODS
03282 // ######################################################################
03283 // ######################################################################
03284 template <class FLOAT>
03285 void featureClusterVision<FLOAT>::fCVprintOutClusters()
03286 {
03287   //LINFO("Draw Class Images");
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   //LINFO("SETTING TEMPORAL");
03306   for(unsigned long i = 0; i < fCV_covDataSizeCurrent; i++)
03307   {
03308     //LINFO("%d : SIZE %d",i,fCV_covHolderCurrent->at(i).samples);
03309     //LINFO("%d : MATCHED at %d",i,
03310     //  fCV_covHolderCurrent->at(i).matchID);
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(&current,&mrPixelMatch);
03317       else
03318       {
03319         small = false;
03320         current = current - 12;
03321         FAC.FACgetColor12(&current,&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   //Raster::VisuRGB(fCV_outImageTemporal,"FOOish.ppm");
03349   //*******************************************************
03350   // draw output images
03351 
03352   //LINFO("Creating Cluster Visual Output");
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       //LINFO("SETTING PIXEL %d",number);
03362       FAC.FACgetColor12(&number,&mrPixel);
03363       unsigned int current = fCV_covHolderCurrent->at(*thisClass).matchID;
03364       FAC.FACgetColor12(&current,&mrPixelMatch);
03365 
03366       Image<PixRGB<FLOAT> > outputClass;
03367       outputClass.resize(fCV_sizeX,fCV_sizeY);
03368       //std::cerr << "class size " <<  fCV_NP.NPgetClassSize(*thisClass) << "\n";
03369       for(int j = 0; j < fCV_NP.NPgetClassSize(*thisClass); j++)
03370       {
03371 
03372         // --- NOTE:
03373         // NPgetFeature = ((fCV_rmap[i]->i)
03374         // /(FLOAT)fCV_sizeX)*fCV_spatialWeight;
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(&current,&mrPixelMatch);
03408       else
03409       {
03410         small = false;
03411         current = current - 12;
03412         FAC.FACgetColor12(&current,&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       drawRect(matchMap, Rectangle::tlbrI(fCV_covHolderCurrent->at(i).maxY,
03431                                   fCV_covHolderCurrent->at(i).minX,
03432                                   fCV_covHolderCurrent->at(i).minY,
03433                                   fCV_covHolderCurrent->at(i).maxX),
03434                         mrPixelMatch,2);
03435       drawRect(realImage, Rectangle::tlbrI(fCV_covHolderCurrent->at(i).maxY,
03436                                    fCV_covHolderCurrent->at(i).minX,
03437                                    fCV_covHolderCurrent->at(i).minY,
03438                                    fCV_covHolderCurrent->at(i).maxX),
03439                          mrPixelMatch,2);
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     //outImage.resize(sizeX,sizeY);
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 // FIXME these functions doesn't compile cleanly anymore because
03477 // covEstimate<double>::getP() and getD() expect a
03478 // std::vector<double>, but we're trying to pass a std::vector<float>
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   //LINFO("FINDING P VALS");
03494   for(int i = 0; i < fCV_countSM; i++)
03495   {
03496     for(unsigned int k = 0; k < fCV_covDataSizeCurrent; k++)
03497     {
03498       // LINFO("%d %d",fCV_space[i].size(),fCV_covHolderCurrent->at(k).mean.size());
03499       //LINFO("%d %d",i,k);
03500       pVal[i][k] = fCV_CV.getP(fCV_space[i],fCV_covHolderCurrent->at(k),2);
03501       //LINFO("PVAL %d,%d %f",i,k,pVal[i][k]);
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   //LINFO("DRAW IMAGE");
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(&current,&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   //LINFO("BAYES DONE");
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   //LINFO("FINDING P VALS");
03562   for(int i = 0; i < fCV_countSM; i++)
03563   {
03564     for(unsigned int k = 0; k < fCV_covDataSizeCurrent; k++)
03565     {
03566       //LINFO("%d %d",fCV_space[i].size(),fCV_covHolder[k].mean.size());
03567       pVal[i][k] = fCV_CV.getD(fCV_space[i],fCV_covHolderCurrent->at(k),2);
03568       //LINFO("PVAL %d,%d %f",i,k,pVal[i][k]);
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(&current,&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   //LINFO("NEIGHBOR DONE");
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;//////////////// = fCV_SM->getV(false);
03656   LFATAL("FIXME");
03657   salmap = rescaleBilinear(salmap,fCV_sizeX,fCV_sizeY);
03658   LINFO("DUMPING VALUES");
03659 
03660   // mask and real may not be the same size, then center
03661   //int maskOffset = (maskFile.getHeight() - fCV_realImage.getHeight())/2;
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   //PixRGB<FLOAT> mrPixel;
03666   //mrPixel.setRed(255); mrPixel.setGreen(0); mrPixel.setBlue(255);
03667   //Image<PixRGB<FLOAT> > realImage = fCV_realImage;
03668 
03669   for(unsigned int i = 0; i < (unsigned)fCV_countSM; i++)
03670   {
03671     // Dump saccade placement
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     // Dump Mask Value
03676 
03677     typename Image<FLOAT>::iterator maskFileItr = maskFile.beginw();
03678     FLOAT distance = 0;
03679     FLOAT minDist  = maxDist;
03680     unsigned int ii = 0;
03681 
03682     // how far is this coord from a mask coord
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     //mrPixel.setBlue(255.0F - (minDist/maxDist)*255.0F);
03694     //mrPixel.setRed(255.0F - (minDist/maxDist)*255.0F);
03695     //drawCircle(realImage, fCV_cmap[i],3,mrPixel,2);
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     // dump saliency map value
03710     FLOAT saly = salmap.getVal(fCV_cmap[i].i,fCV_cmap[i].j);
03711     outFile << saly << "\t";
03712 
03713     outFile << "XXXXX\t";
03714 
03715     // Dump Raw Feature Values
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     // Dump processed feature Data
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   // Raster::WriteRGB(realImage,sformat("%s.%s.out.eyeDataOver.ppm",_label.c_str()
03734   //               ,_outFile.c_str()));
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   // color stats
03755   // colors on the target
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   // colors off the target
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   // total colors
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   // mask stats
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   // first find basic mask stats
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       //LINFO("Coords %dx%d",x,(int)(y+maskOffset));
03791       FLOAT maskVal = maskFile.getVal(x,(int)(y+maskOffset));
03792       // on mask stats
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       // on mask stats
03815       if(maskVal >= 0.000001F)
03816       {
03817         // SUM
03818         maskSumX += x;     maskSumY += y;
03819         H1onSum  += pixH1; H2onSum  += pixH2;
03820         SonSum   += pixS;  VonSum   += pixV;
03821         // SUM of SQUARES
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         // off mask stats
03832         // SUM
03833         H1offSum += pixH1; H2offSum += pixH2;
03834         SoffSum  += pixS;  VoffSum  += pixV;
03835         // SUM of SQUARES
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       // total stats
03842       // SUM
03843       H1Sum += pixH1; H2Sum += pixH2;
03844       SSum  += pixS;  VSum  += pixV;
03845       // SUM of SQUARES
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   // Compute all final stats for this image
03854 
03855   // MASK STATS
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   // NON MASK STATS
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   // TOTAL STATS
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   // DUMP STATS TO FILE
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   // mass stats
03887   outFile << _label   << "\t";
03888   outFile << maskMass << "\t" << nonMaskMass << "\t" << totalMass << "\t";
03889 
03890   // MASK STATS
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   // NON MASK STATS
03899   outFile << H1offMean  << "\t" << H1offSTD  << "\t"
03900           << H2offMean  << "\t" << H2offSTD  << "\t"
03901           << SoffMean   << "\t" << SoffSTD   << "\t"
03902           << VoffMean   << "\t" << VoffSTD   << "\t";
03903 
03904   // TOTAL STATS
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   //Raster::VisuRGB(CmaskFile,"CmaskFile.ppm");
03935   //CmaskFile = CmaskFile*255;
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   // Create a nested vector to contain all the images
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   // Create iterator pointers for the image components
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   // This will pull out the Gabor responses for the image at different
03958   // angles and scales over H2SV components;
03959 
03960   Image<PixRGB<FLOAT> > currentImage = imageFile;
03961 
03962   // move over all scales
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     // move over all rotations
03971     for(typename std::vector<std::vector<Image<FLOAT> > >::iterator rotationItr =
03972           complexPyramidItr->begin(); rotationItr != complexPyramidItr->end();
03973         ++rotationItr, i++)
03974     {
03975       // simple gabor interations, else we look for junctions etc.
03976       if(rotations[i] >= 0)
03977       {
03978         LINFO("Running rotations scale %d rot %d",s,rotations[i]);
03979         // process the H2SV color components
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         // pull out color components into seperate images
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             //LINFO("PIX %f %f %f %f",*H1itr,*H2itr,*Sitr,*Vitr);
04003             // normalize value (intensity)
04004             *Vitr = (*Vitr) * (*fCV_valNorm);
04005           }
04006         // find the gabor interactions over all H2SV images at this
04007         // scale and rotation
04008 
04009         // SIN gabor
04010         Image<FLOAT> mrGabor   = gaborFilter2<FLOAT>(gaborSTD,gaborPrd,0.0F,
04011                                                      (FLOAT)rotations[i]);
04012         // COS gabor
04013         Image<FLOAT> mrGaborAF = gaborFilter2<FLOAT>(gaborSTD,gaborPrd
04014                                                      ,gaborPrd/2,
04015                                                      (FLOAT)rotations[i]);
04016 
04017         // find gabor interaction with H2SV images at this scale/rotation
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         //Raster::VisuFloat(rotationItr->at(0),FLOAT_NORM_0_255,
04022         //           sformat("imgH1.%d.%d.pgm",s,rotations[i]));
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         //Raster::VisuFloat(rotationItr->at(1),FLOAT_NORM_0_255,
04031         //           sformat("imgH2.%d.%d.pgm",s,rotations[i]));
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         //Raster::VisuFloat(rotationItr->at(2),FLOAT_NORM_0_255,
04040         //           sformat("imgS.%d.%d.pgm",s,rotations[i]));
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         //Raster::VisuFloat(rotationItr->at(3),FLOAT_NORM_0_255,
04049         //                   sformat("imgV.%d.%d.pgm",s,rotations[i]));
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       // here we use complex channels to look for junctions
04055       else
04056       {
04057         LINFO("Running junctions scale %d rot %d",s,rotations[i]);
04058         // first element H1 - its orthogonal counterpart
04059         // first compute lineyness
04060         // This is the same formula used in mixChannels at ln 597 (ish)
04061 
04062         Image<FLOAT> Alpha;
04063         Image<FLOAT> Beta;
04064         // Mix 0,45,90,135 degree angles and find junctions at this scale
04065         // H1
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         //Raster::VisuFloat(complexPyramidItr->at(i)[0],FLOAT_NORM_0_255,
04072         //                   sformat("juncH1.%d.pgm",s));
04073         Raster::WriteGray(complexPyramidItr->at(i)[0]*255.0F,
04074                           sformat("imgH1.junc.%d.%s.out.pgm",
04075                                   s,_label.c_str()));
04076 
04077         // H2
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         //Raster::VisuFloat(complexPyramidItr->at(i)[1],FLOAT_NORM_0_255,
04084         //           sformat("juncH2.%d.pgm",s));
04085         Raster::WriteGray(complexPyramidItr->at(i)[1]*255.0F,
04086                           sformat("imgH2.junc.%d.%s.out.pgm",
04087                                   s,_label.c_str()));
04088         // S
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         //Raster::VisuFloat(complexPyramidItr->at(i)[2],FLOAT_NORM_0_255,
04095         //           sformat("juncS.%d.pgm",s));
04096         Raster::WriteGray(complexPyramidItr->at(i)[2]*255.0F,
04097                           sformat("imgS.junc.%d.%s.out.pgm",
04098                                   s,_label.c_str()));
04099         // V
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         //Raster::VisuFloat(complexPyramidItr->at(i)[3],FLOAT_NORM_0_255,
04106         //                   sformat("juncV.%d.pgm",s));
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     // Make image half size after each iteration
04113     currentImage = rescaleBilinear(currentImage,
04114                            currentImage.getWidth()/2,
04115                            currentImage.getHeight()/2);
04116     // resize the mask as well, but keep it similar in size to the
04117     // orignal image for the width
04118     if(s < scales-1)
04119     {
04120       //masks[s+1] = rescaleBilinear(maskFile,currentImage.getWidth()/2
04121       //                           ,masks[s].getHeight()/2);
04122       LINFO("DOWNSCALE");
04123       Image<PixRGB<FLOAT> > Cmask = downscaleFancy(CmaskFile,
04124                                                    currentImage.getWidth()
04125                                                    ,masks[s].getHeight()/2,1
04126                                                    ,true);
04127       //LINFO("COPY COLOR");
04128       //Raster::VisuRGB(Cmask,sformat("CMask.%d.ppm",s+1));
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       //LINFO("RASTER");
04136       //Raster::VisuRGB(masks[s+1],sformat("Mask.%d.ppm",s+1));
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   // get stats on image
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     // move over all rotations
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       // colors off the target
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       // total colors
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       // mask stats
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       // offset the mask iterator to align with the image
04194       typename Image<FLOAT>::iterator Mitr = masks[s].beginw() +
04195                (int)(masks[s].getWidth() * maskOffset);
04196 
04197       // find the mass of the mask at each scale
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       // for each image pixel and each of the H2SV components
04222       // compute the complex image stats
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         //We fall on a mask
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           // SUM of SQUARES
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         // We don't fall on a mask
04249         else
04250         {
04251           // off mask stats
04252           // SUM
04253           H1offSum = *H1itr + H1offSum;
04254           H2offSum = *H2itr + H2offSum;
04255           SoffSum  = *Sitr  + SoffSum;
04256           VoffSum  = *Vitr  + VoffSum;
04257           // SUM of SQUARES
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         // total stats
04264         // SUM
04265         H1Sum = *H1itr + H1Sum;
04266         H2Sum = *H2itr + H2Sum;
04267         SSum  = *Sitr  + SSum;
04268         VSum  = *Vitr  + VSum;
04269         // SUM of SQUARES
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       // MASK STATS
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       // NON MASK STATS
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       // TOTAL STATS
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       // dump all this fun stuff to a file
04308       outFile << _label   << "\t";
04309       outFile << s        << "\t" << rotations[i] << "\t";
04310       outFile << maskMass << "\t" << nonMaskMass  << "\t" << totalMass << "\t";
04311 
04312       // MASK STATS
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       // NON MASK STATS
04321       outFile << H1offMean  << "\t" << H1offSTD  << "\t"
04322               << H2offMean  << "\t" << H2offSTD  << "\t"
04323               << SoffMean   << "\t" << SoffSTD   << "\t"
04324               << VoffMean   << "\t" << VoffSTD   << "\t";
04325 
04326       // TOTAL STATS
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 // explicit instantiations
04337 // ############################################################
04338 
04339 template class featureClusterVision<float>;
Generated on Sun May 8 08:07:03 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3