ScaleRemoveSurprise.C

Go to the documentation of this file.
00001 /*!@file Surprise/ScaleRemoveSurprise.C attempt to remove surprise from image */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: T. Nathan Mundhenk <mundhenk@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Surprise/ScaleRemoveSurprise.C $
00035 // $Id: ScaleRemoveSurprise.C 6795 2006-06-29 20:45:32Z rjpeters $
00036 //
00037 
00038 #ifndef SCALE_REMOVE_SURPRISE_C_DEFINED
00039 #define SCALE_REMOVE_SURPRISE_C_DEFINED
00040 
00041 #include "Surprise/ScaleRemoveSurprise.H"
00042 #include "Image/ColorOps.H"
00043 
00044 #define SURPRISE_CONF_PATH "/lab/mundhenk/saliency/etc/"
00045 #define SURPRISE_CONF_FILE "removeSurprise.conf"
00046 
00047 template <class FLOAT>
00048 ScaleRemoveSurprise<FLOAT>::ScaleRemoveSurprise(const ushort sizeX,
00049                                                 const ushort sizeY,
00050                                                 const string confFile)
00051 {
00052   const string nc = "null";
00053   string file;
00054   // if(strcmp(confFile.c_str(),nc.c_str()))
00055   //  file = SURPRISE_CONF_FILE;
00056   // else
00057     file = confFile;
00058 
00059   const string path     = SURPRISE_CONF_PATH;
00060 
00061   char pathFile[100];
00062   //sprintf(pathFile,"%s%s",path.c_str(),file.c_str());
00063   sprintf(pathFile,"%s",file.c_str());
00064   itsReadConfig.openFile(pathFile);
00065 
00066   // get basic information and biases
00067   itsAxisBiasX   = itsReadConfig.getItemValueF("itsAxisBiasX");
00068   itsAxisBiasY   = itsReadConfig.getItemValueF("itsAxisBiasY");
00069   itsAxisBiasZ   = itsReadConfig.getItemValueF("itsAxisBiasZ");
00070   itsINBias      = itsReadConfig.getItemValueF("itsINbias");
00071   itsDRBias      = itsReadConfig.getItemValueF("itsDRbias");
00072   itsFLBias      = itsReadConfig.getItemValueF("itsFLbias");
00073   itsGABias      = itsReadConfig.getItemValueF("itsGAbias");
00074   itsRGBias      = itsReadConfig.getItemValueF("itsRGbias");
00075   itsBYBias      = itsReadConfig.getItemValueF("itsBYbias");
00076   itsLambda      = itsReadConfig.getItemValueF("itsLambda");
00077   itsStdSize     = itsReadConfig.getItemValueF("itsStdSize");
00078   itsZSigma      = itsReadConfig.getItemValueF("itsZSigma");
00079   itsUseKalman   = itsReadConfig.getItemValueB("itsUseKalman");
00080   itsUseMaxLevel = itsReadConfig.getItemValueB("itsUseMaxLevel");
00081   itsH1bias      = itsReadConfig.getItemValueF("itsH1bias");
00082   itsH2bias      = itsReadConfig.getItemValueF("itsH2bias");
00083   itsSbias       = itsReadConfig.getItemValueF("itsSbias");
00084   itsVbias       = itsReadConfig.getItemValueF("itsVbias");
00085 
00086   itsBaseFilterSize = (ushort)itsReadConfig.getItemValueF("itsBaseFilterSize");
00087 
00088   // get LevelSpec information
00089   itsLevMin    = (ushort)itsReadConfig.getItemValueF("itsLevMin");
00090   itsLevMax    = (ushort)itsReadConfig.getItemValueF("itsLevMax");
00091   itsDelMin    = (ushort)itsReadConfig.getItemValueF("itsDelMin");
00092   itsDelMax    = (ushort)itsReadConfig.getItemValueF("itsDelMax");
00093   itsMapLevel  = (ushort)itsReadConfig.getItemValueF("itsMapLevel");
00094   itsMaxIndex  = (ushort)itsReadConfig.getItemValueF("itsMaxIndex");
00095   itsMaxDepth  = (ushort)itsReadConfig.getItemValueF("itsMaxDepth");
00096 
00097   itsScaleBias.resize(itsMaxIndex,0.0F);
00098 
00099   std::string baseScale = "itsScaleBias_";
00100 
00101   // read in each scale bias
00102   for(ushort i = 0; i < itsMaxIndex; i++)
00103   {
00104     char temp[100];
00105     sprintf(temp,"%s%d",baseScale.c_str(),i);
00106     itsScaleBias[i] = itsReadConfig.getItemValueF(static_cast<string>(temp));
00107   }
00108 
00109   itsScalePower.resize(itsMaxIndex,0.0F);
00110   baseScale = "itsScalePower_";
00111 
00112   // read in each scale power
00113   for(ushort i = 0; i < itsMaxIndex; i++)
00114   {
00115     char temp[100];
00116     sprintf(temp,"%s%d",baseScale.c_str(),i);
00117     itsScalePower[i] = itsReadConfig.getItemValueF(static_cast<string>(temp));
00118   }
00119 
00120   itsDesatBias.resize(itsMaxIndex,0.0F);
00121   baseScale = "itsDesatBias_";
00122 
00123   // read in each scale power
00124   for(ushort i = 0; i < itsMaxIndex; i++)
00125   {
00126     char temp[100];
00127     sprintf(temp,"%s%d",baseScale.c_str(),i);
00128     itsDesatBias[i] = itsReadConfig.getItemValueF(static_cast<string>(temp));
00129   }
00130 
00131   SRSinit(sizeX,sizeY);
00132 }
00133 
00134 /*************************************************************************/
00135 
00136 template <class FLOAT>
00137 ScaleRemoveSurprise<FLOAT>::~ScaleRemoveSurprise()
00138 {}
00139 
00140 /*************************************************************************/
00141 
00142 template <class FLOAT>
00143 void ScaleRemoveSurprise<FLOAT>::SRSinit(const ushort sizeX,
00144                                          const ushort sizeY)
00145 {
00146   LINFO("INIT");
00147   itsImageSizeX = sizeX;
00148   itsImageSizeY = sizeY;
00149 
00150   // create a RemoveSurprise for each scale
00151   LINFO("Creating temp object");
00152   RemoveSurprise<PIX_H2SV_TYPE<FLOAT>,PixHyper<FLOAT,6>,FLOAT> tempRS(sizeX,sizeY);
00153   itsRemoveSurprise.resize(itsMaxIndex,tempRS);
00154   itsFinalImage.resize(sizeX,sizeY);
00155 
00156   itsImageSizesX.resize(itsMaxIndex,0);
00157   itsImageSizesY.resize(itsMaxIndex,0);
00158   itsFilterSizesX.resize(itsMaxIndex,0);
00159   itsFilterSizesY.resize(itsMaxIndex,0);
00160   itsFilterSizesZ.resize(itsMaxIndex,0);
00161   itsResultImages.resize(itsMaxIndex,itsFinalImage);
00162 
00163   itsImageBaseX = itsImageSizeX/(ushort)(pow(2.0F,(FLOAT)itsLevMin));
00164   itsImageBaseY = itsImageSizeY/(ushort)(pow(2.0F,(FLOAT)itsLevMin));
00165 
00166   LINFO("Base Image Size %d x %d",itsImageBaseX,itsImageBaseY);
00167 
00168   uint indx = 0;
00169 
00170   // determine the pyramid sizes used and store
00171   // also determin how large the feature filter would be on a non-reduced image
00172   LINFO("Setting up filters");
00173   for(ushort i = 0; i < (itsDelMax - itsDelMin + 1); i++)
00174   {
00175     ushort bx = itsImageBaseX;
00176     ushort by = itsImageBaseY;
00177     FLOAT fz  = itsZSigma;
00178     for(ushort j = 0; j < (itsLevMax - itsLevMin + 1); j++)
00179     {
00180       itsImageSizesX[indx]  = bx;
00181       itsFilterSizesX[indx] = (ushort)round(((FLOAT)itsBaseFilterSize/
00182                                (FLOAT)itsImageSizesX[indx]) *
00183                                 (FLOAT)itsImageSizeX);
00184       LINFO("%d : Filter Size X %d",indx,itsFilterSizesX[indx]);
00185       itsImageSizesY[indx]  = by;
00186       itsFilterSizesY[indx] = (ushort)round(((FLOAT)itsBaseFilterSize/
00187                                (FLOAT)itsImageSizesY[indx]) *
00188                                (FLOAT)itsImageSizeY);
00189       LINFO("%d : Filter Size Y %d",indx,itsFilterSizesY[indx]);
00190       itsFilterSizesZ[indx] = fz;
00191       LINFO("%d : Filter Size Z %f",indx,itsFilterSizesZ[indx]);
00192       bx = bx/2; by = by/2; fz = fz*2;
00193       indx++;
00194     }
00195   }
00196 
00197   // set up each RemoveSurprise
00198   for(ushort i = 0; i < itsMaxIndex; i++)
00199   {
00200     LINFO("Setting up RemoveSaliency for scale %d",i);
00201     itsRemoveSurprise[i].RSsetAxisBias(itsAxisBiasX,
00202                                        itsAxisBiasY,
00203                                        itsAxisBiasZ);
00204     // we try to fit something close to the orignal filters used
00205     const FLOAT sigma   = itsFilterSizesX[i]/4;
00206     const FLOAT z_sigma = itsFilterSizesZ[i];
00207     LINFO("%d Desat Bias %f",i,itsDesatBias[i]);
00208     itsRemoveSurprise[i].RSsetDesatBias(itsDesatBias[i]);
00209     LINFO("%d Sigma %f Z Sigma %f StdDev %f",i,sigma,z_sigma,itsStdSize);
00210     itsRemoveSurprise[i].RScreateSepFilters(sigma,z_sigma,itsStdSize);
00211     itsRemoveSurprise[i].RSfindConvolutionEndPoints();
00212     LINFO("%d IN Bias %f DR Bias %f FL Bias %f",i,itsINBias,itsDRBias,
00213           itsFLBias);
00214     LINFO("%d GA Bias %f RG Bias %f BY Bias %f",i,itsGABias,itsRGBias,
00215           itsBYBias);
00216     LINFO("%d Scale Power %f",i,itsScalePower[i]);
00217     itsRemoveSurprise[i].RSsetConspicBias(itsINBias * itsScalePower[i],
00218                                           itsDRBias * itsScalePower[i],
00219                                           itsFLBias * itsScalePower[i],
00220                                           itsGABias * itsScalePower[i],
00221                                           itsRGBias * itsScalePower[i],
00222                                           itsBYBias * itsScalePower[i]);
00223     LINFO("%d Bias H1 %f H2 %f S %f V %f",i,
00224           itsH1bias,itsH2bias,itsSbias,itsVbias);
00225     itsRemoveSurprise[i].RSsetH2SVBias(itsH1bias,itsH2bias,itsSbias,itsVbias);
00226     itsRemoveSurprise[i].RSuseTrueKalman(false);
00227     itsRemoveSurprise[i].RSuseMaxLevel(itsUseMaxLevel);
00228     LINFO("%d Lambda %f",i,itsLambda);
00229     itsRemoveSurprise[i].RSsetLambda(itsLambda);
00230   }
00231 }
00232 
00233 /*************************************************************************/
00234 
00235 template <class FLOAT>
00236 void ScaleRemoveSurprise<FLOAT>::SRSinputRawImage(
00237                                      const Image<PixRGB<FLOAT> >& rawImage,
00238                                      const uint frame)
00239 {
00240   itsRawImage = rawImage;
00241   itsFrame    = frame;
00242 }
00243 
00244 /*************************************************************************/
00245 
00246 template <class FLOAT>
00247 void ScaleRemoveSurprise<FLOAT>::SRSinputSalMap(const Image<FLOAT>& salMap)
00248 {
00249   itsSalMap = salMap;
00250 }
00251 
00252 /*************************************************************************/
00253 
00254 template <class FLOAT>
00255 void ScaleRemoveSurprise<FLOAT>::SRSsetAntiWeights()
00256 {
00257   for(ushort i = 0; i < itsMaxIndex; i++)
00258   {
00259     char fileName[100];
00260     FLOAT mean      = 0;
00261     int   N         = 0;
00262 
00263     FLOAT mean2     = 0;
00264     int   N2        = 0;
00265 
00266     sprintf(fileName,"../ANTI/IntensitySurprise.000000.%d.SCSimage.float.pfz",i);
00267     string fnameS = fileName;
00268     const Image<FLOAT> INimage = Raster::ReadFloat(fnameS);
00269 
00270     for(int ii = 0; ii < INimage.getWidth(); ii++)
00271     {
00272       for(int j = 0; j < INimage.getHeight(); j++)
00273       {
00274         mean += INimage.getVal(ii,j);
00275         N++;
00276       }
00277     }
00278     FLOAT INmean      = (mean/N);
00279     sprintf(fileName,"../BASE/IntensitySurprise.000000.%d.SCSimage.float.pfz",i);
00280     fnameS = fileName;
00281     const Image<FLOAT> INimage2 = Raster::ReadFloat(fnameS);
00282     for(int ii = 0; ii < INimage2.getWidth(); ii++)
00283     {
00284       for(int j = 0; j < INimage2.getHeight(); j++)
00285       {
00286         mean2 += INimage2.getVal(ii,j);
00287         N2++;
00288       }
00289     }
00290     FLOAT INmean2      = (mean2/N2);
00291 
00292     mean = 0;
00293     N    = 0;
00294     mean2 = 0;
00295     N2    = 0;
00296     sprintf(fileName,"../ANTI/GaborSurprise.000000.%d.SCSimage.float.pfz",i);
00297     fnameS = fileName;
00298     const Image<FLOAT> GAimage = Raster::ReadFloat(fnameS);
00299 
00300     for(int ii = 0; ii < GAimage.getWidth(); ii++)
00301     {
00302       for(int j = 0; j < GAimage.getHeight(); j++)
00303       {
00304         mean += GAimage.getVal(ii,j);
00305         N++;
00306       }
00307     }
00308     FLOAT GAmean      = (mean/N);
00309     sprintf(fileName,"../BASE/GaborSurprise.000000.%d.SCSimage.float.pfz",i);
00310     fnameS = fileName;
00311     const Image<FLOAT> GAimage2 = Raster::ReadFloat(fnameS);
00312 
00313     for(int ii = 0; ii < GAimage2.getWidth(); ii++)
00314     {
00315       for(int j = 0; j < GAimage2.getHeight(); j++)
00316       {
00317         mean2 += GAimage2.getVal(ii,j);
00318         N2++;
00319       }
00320     }
00321     FLOAT GAmean2      = (mean2/N2);
00322 
00323     mean = 0;
00324     N    = 0;
00325     mean2 = 0;
00326     N2    = 0;
00327     sprintf(fileName,"../ANTI/RedGreenSurprise.000000.%d.SCSimage.float.pfz",i);
00328     fnameS = fileName;
00329     const Image<FLOAT> RGimage = Raster::ReadFloat(fnameS);
00330 
00331     for(int ii = 0; ii < RGimage.getWidth(); ii++)
00332     {
00333       for(int j = 0; j < RGimage.getHeight(); j++)
00334       {
00335         mean += RGimage.getVal(ii,j);
00336         N++;
00337       }
00338     }
00339     FLOAT RGmean      = (mean/N);
00340     sprintf(fileName,"../BASE/RedGreenSurprise.000000.%d.SCSimage.float.pfz",i);
00341     fnameS = fileName;
00342     const Image<FLOAT> RGimage2 = Raster::ReadFloat(fnameS);
00343 
00344     for(int ii = 0; ii < RGimage2.getWidth(); ii++)
00345     {
00346       for(int j = 0; j < RGimage2.getHeight(); j++)
00347       {
00348         mean2 += RGimage2.getVal(ii,j);
00349         N2++;
00350       }
00351     }
00352     FLOAT RGmean2      = (mean2/N2);
00353 
00354     mean = 0;
00355     N    = 0;
00356     mean2 = 0;
00357     N2    = 0;
00358     sprintf(fileName,"../ANTI/BlueYellowSurprise.000000.%d.SCSimage.float.pfz",i);
00359     fnameS = fileName;
00360     const Image<FLOAT> BYimage = Raster::ReadFloat(fnameS);
00361 
00362     for(int ii = 0; ii < BYimage.getWidth(); ii++)
00363     {
00364       for(int j = 0; j < BYimage.getHeight(); j++)
00365       {
00366         mean += BYimage.getVal(ii,j);
00367         N++;
00368       }
00369     }
00370     FLOAT BYmean      = (mean/N);
00371     sprintf(fileName,"../BASE/BlueYellowSurprise.000000.%d.SCSimage.float.pfz",i);
00372     fnameS = fileName;
00373     const Image<FLOAT> BYimage2 = Raster::ReadFloat(fnameS);
00374 
00375     for(int ii = 0; ii < BYimage2.getWidth(); ii++)
00376     {
00377       for(int j = 0; j < BYimage2.getHeight(); j++)
00378       {
00379         mean2 += BYimage2.getVal(ii,j);
00380         N2++;
00381       }
00382     }
00383     FLOAT BYmean2      = (mean2/N2);
00384 
00385     FLOAT norm  = INmean  + GAmean  + RGmean  + BYmean;
00386     FLOAT norm2 = INmean2 + GAmean2 + RGmean2 + BYmean2;
00387 
00388     INmean = (INmean/norm) * 4; GAmean = (GAmean/norm) * 4;
00389     RGmean = (RGmean/norm) * 4; RGmean = (BYmean/norm) * 4;
00390 
00391     INmean2 = (INmean2/norm2) * 4; GAmean2 = (GAmean2/norm2) * 4;
00392     RGmean2 = (RGmean2/norm2) * 4; BYmean2 = (BYmean2/norm2) * 4;
00393 
00394     LINFO("%d Old RG val %f",i,itsRGBias);
00395     LINFO("Base Mean %f Anti Mean %f",RGmean2,RGmean);
00396     const FLOAT itsNewRGBias = itsRGBias * (RGmean2/RGmean);
00397     LINFO("%d New RG val %f",i,itsNewRGBias);
00398 
00399     LINFO("%d Old BY val %f",i,itsBYBias);
00400     LINFO("Base Mean %f Anti Mean %f",BYmean2,BYmean);
00401     const FLOAT itsNewBYBias = itsBYBias * (BYmean2/BYmean);
00402     LINFO("%d New BY val %f",i,itsNewBYBias);
00403 
00404     LINFO("%d Old GA val %f",i,itsGABias);
00405     LINFO("Base Mean %f Anti Mean %f",GAmean2,GAmean);
00406     const FLOAT itsNewGABias = itsGABias * (GAmean2/GAmean);
00407     LINFO("%d New GA val %f",i,itsNewGABias);
00408 
00409     LINFO("%d Old IN val %f",i,itsINBias);
00410     LINFO("Base Mean %f Anti Mean %f",INmean2,INmean);
00411     const FLOAT itsNewINBias = itsINBias * (INmean2/INmean);
00412     LINFO("%d New IN val %f",i,itsNewINBias);
00413 
00414     const FLOAT itsNewDRBias = itsDRBias;
00415     const FLOAT itsNewFLBias = itsFLBias;
00416 
00417     itsRemoveSurprise[i].RSsetConspicBias(itsNewINBias * itsScalePower[i],
00418                                           itsNewDRBias * itsScalePower[i],
00419                                           itsNewFLBias * itsScalePower[i],
00420                                           itsNewGABias * itsScalePower[i],
00421                                           itsNewRGBias * itsScalePower[i],
00422                                           itsNewBYBias * itsScalePower[i]);
00423   }
00424 }
00425 
00426 /*************************************************************************/
00427 
00428 template <class FLOAT>
00429 void ScaleRemoveSurprise<FLOAT>::SRSsetAntiWeightsInteract(const uint aframes,
00430                                                            const uint bframes)
00431 {
00432   for(ushort i = 0; i < itsMaxIndex; i++)
00433   {
00434     char fileName[100];
00435     std::vector<bool> active(6,true);
00436     std::vector<FLOAT> blankVec(6,0.0);
00437     std::vector<FLOAT> MEAN(6,1.0);
00438     std::vector<FLOAT> MEAN2(6,1.0);
00439     std::vector<FLOAT> STD(6,1.0);
00440     std::vector<FLOAT> STD2(6,1.0);
00441     std::vector<std::vector<FLOAT> > COR(6,blankVec);
00442     std::vector<std::vector<FLOAT> > COR2(6,blankVec);
00443 
00444     Image<FLOAT> blank;
00445     std::vector<Image<FLOAT> > INimage(aframes,blank);
00446     std::vector<Image<FLOAT> > GAimage(aframes,blank);
00447     std::vector<Image<FLOAT> > RGimage(aframes,blank);
00448     std::vector<Image<FLOAT> > BYimage(aframes,blank);
00449 
00450     std::vector<Image<FLOAT> > INimage2(bframes,blank);
00451     std::vector<Image<FLOAT> > GAimage2(bframes,blank);
00452     std::vector<Image<FLOAT> > RGimage2(bframes,blank);
00453     std::vector<Image<FLOAT> > BYimage2(bframes,blank);
00454 
00455     FLOAT N    = 0, N2    = 0;
00456     FLOAT Norm = 0, Norm2 = 0;
00457     FLOAT INmean  = 0, GAmean  = 0, RGmean  = 0, BYmean  = 0;
00458     FLOAT INmean2 = 0, GAmean2 = 0, RGmean2 = 0, BYmean2 = 0;
00459     FLOAT INss    = 0, GAss    = 0, RGss    = 0, BYss    = 0;
00460     FLOAT INss2   = 0, GAss2   = 0, RGss2   = 0, BYss2   = 0;
00461 
00462     for(uint t = 0; t < aframes; t++)
00463     {
00464       int frameNumber = (int)t;
00465       char c[100];
00466       if(frameNumber < 10)
00467         sprintf(c,"00000%d",frameNumber);
00468       else if(frameNumber < 100)
00469         sprintf(c,"0000%d",frameNumber);
00470       else if(frameNumber < 1000)
00471         sprintf(c,"000%d",frameNumber);
00472       else if(frameNumber < 10000)
00473         sprintf(c,"00%d",frameNumber);
00474       else if(frameNumber < 100000)
00475         sprintf(c,"0%d",frameNumber);
00476       else
00477         sprintf(c,"%d",frameNumber);
00478       sprintf(fileName,"../ANTI/IntensitySurprise.%s.%d.SCSimage.float.pfz"
00479               ,c,i);
00480       string fnameS = fileName;
00481       INimage[t] = Raster::ReadFloat(fnameS);
00482 
00483       sprintf(fileName,"../ANTI/GaborSurprise.%s.%d.SCSimage.float.pfz"
00484               ,c,i);
00485       fnameS = fileName;
00486       GAimage[t] = Raster::ReadFloat(fnameS);
00487 
00488       sprintf(fileName,"../ANTI/RedGreenSurprise.%s.%d.SCSimage.float.pfz"
00489               ,c,i);
00490       fnameS = fileName;
00491       RGimage[t] = Raster::ReadFloat(fnameS);
00492 
00493 
00494       sprintf(fileName,"../ANTI/BlueYellowSurprise.%s.%d.SCSimage.float.pfz"
00495               ,c,i);
00496       fnameS = fileName;
00497       BYimage[t] = Raster::ReadFloat(fnameS);
00498 
00499     }
00500 
00501     for(uint t = 0; t < bframes; t++)
00502     {
00503       int frameNumber = (int)t;
00504       char c[100];
00505       if(frameNumber < 10)
00506         sprintf(c,"00000%d",frameNumber);
00507       else if(frameNumber < 100)
00508         sprintf(c,"0000%d",frameNumber);
00509       else if(frameNumber < 1000)
00510         sprintf(c,"000%d",frameNumber);
00511       else if(frameNumber < 10000)
00512         sprintf(c,"00%d",frameNumber);
00513       else if(frameNumber < 100000)
00514         sprintf(c,"0%d",frameNumber);
00515       else
00516         sprintf(c,"%d",frameNumber);
00517 
00518       sprintf(fileName,"../BASE/IntensitySurprise.%s.%d.SCSimage.float.pfz"
00519               ,c,i);
00520       string fnameS = fileName;
00521       INimage2[t] = Raster::ReadFloat(fnameS);
00522 
00523       sprintf(fileName,"../BASE/GaborSurprise.%s.%d.SCSimage.float.pfz"
00524               ,c,i);
00525       fnameS = fileName;
00526       GAimage2[t] = Raster::ReadFloat(fnameS);
00527 
00528       sprintf(fileName,"../BASE/RedGreenSurprise.%s.%d.SCSimage.float.pfz"
00529               ,c,i);
00530       fnameS = fileName;
00531       RGimage2[t] = Raster::ReadFloat(fnameS);
00532 
00533       sprintf(fileName,"../BASE/BlueYellowSurprise.%s.%d.SCSimage.float.pfz"
00534               ,c,i);
00535       fnameS = fileName;
00536       BYimage2[t] = Raster::ReadFloat(fnameS);
00537     }
00538 
00539     active[1] = false; active[2] = false;
00540 
00541     for(uint t = 0; t < bframes; t++)
00542     {
00543       for(int ii = 0; ii < BYimage2[t].getWidth(); ii++)
00544       {
00545         for(int jj = 0; jj < BYimage2[t].getHeight(); jj++)
00546         {
00547           INmean2 += INimage2[t].getVal(ii,jj);
00548           INss2   += pow(INimage2[t].getVal(ii,jj),2);
00549 
00550           GAmean2 += GAimage2[t].getVal(ii,jj);
00551           GAss2   += pow(GAimage2[t].getVal(ii,jj),2);
00552 
00553           RGmean2 += RGimage2[t].getVal(ii,jj);
00554           RGss2   += pow(RGimage2[t].getVal(ii,jj),2);
00555 
00556           BYmean2 += BYimage2[t].getVal(ii,jj);
00557           BYss2   += pow(BYimage2[t].getVal(ii,jj),2);
00558           N2++;
00559         }
00560       }
00561     }
00562     INmean2 = INmean2/N2;  GAmean2 = GAmean2/N2;
00563     RGmean2 = RGmean2/N2;  BYmean2 = BYmean2/N2;
00564     MEAN2[0] = INmean2; MEAN2[3] = GAmean2;
00565     MEAN2[4] = RGmean2; MEAN2[5] = BYmean2;
00566     STD2[0] = sqrt(INss2/N2 - pow(INmean2,2));
00567     STD2[3] = sqrt(GAss2/N2 - pow(GAmean2,2));
00568     STD2[4] = sqrt(RGss2/N2 - pow(RGmean2,2));
00569     STD2[5] = sqrt(BYss2/N2 - pow(BYmean2,2));
00570 
00571     for(uint t = 0; t < aframes; t++)
00572     {
00573       for(int ii = 0; ii < BYimage[t].getWidth(); ii++)
00574       {
00575         for(int jj = 0; jj < BYimage[t].getHeight(); jj++)
00576         {
00577           INmean += INimage[t].getVal(ii,jj);
00578           INss   += pow(INimage[t].getVal(ii,jj),2);
00579 
00580           GAmean += GAimage[t].getVal(ii,jj);
00581           GAss   += pow(GAimage[t].getVal(ii,jj),2);
00582 
00583           RGmean += RGimage[t].getVal(ii,jj);
00584           RGss   += pow(RGimage[t].getVal(ii,jj),2);
00585 
00586           BYmean += BYimage[t].getVal(ii,jj);
00587           BYss   += pow(BYimage[t].getVal(ii,jj),2);
00588           N++;
00589         }
00590       }
00591     }
00592 
00593     INmean = INmean/N;  GAmean = GAmean/N;
00594     RGmean = RGmean/N;  BYmean = BYmean/N;
00595     MEAN[0] = INmean; MEAN[3] = GAmean;
00596     MEAN[4] = RGmean; MEAN[5] = BYmean;
00597     STD[0] = sqrt(INss/N - pow(INmean,2));
00598     STD[3] = sqrt(GAss/N - pow(GAmean,2));
00599     STD[4] = sqrt(RGss/N - pow(RGmean,2));
00600     STD[5] = sqrt(BYss/N - pow(BYmean,2));
00601 
00602     for(uint t = 0; t < bframes; t++)
00603     {
00604       for(int ii = 0; ii < BYimage2[t].getWidth(); ii++)
00605       {
00606         for(int jj = 0; jj < BYimage2[t].getHeight(); jj++)
00607         {
00608           COR2[0][0] += pow(INimage2[t].getVal(ii,jj),2);
00609           COR2[0][1] = 0;
00610           COR2[0][2] = 0;
00611           COR2[0][3] += INimage2[t].getVal(ii,jj)*GAimage2[t].getVal(ii,jj);
00612           COR2[0][4] += INimage2[t].getVal(ii,jj)*RGimage2[t].getVal(ii,jj);
00613           COR2[0][5] += INimage2[t].getVal(ii,jj)*BYimage2[t].getVal(ii,jj);
00614 
00615           COR2[1][0] = 0;
00616           COR2[1][1] = 0;
00617           COR2[1][2] = 0;
00618           COR2[1][3] = 0;
00619           COR2[1][4] = 0;
00620           COR2[1][5] = 0;
00621 
00622           COR2[2][0] = 0;
00623           COR2[2][1] = 0;
00624           COR2[2][2] = 0;
00625           COR2[2][3] = 0;
00626           COR2[2][4] = 0;
00627           COR2[2][5] = 0;
00628 
00629           COR2[3][0] += GAimage2[t].getVal(ii,jj)*INimage2[t].getVal(ii,jj);
00630           COR2[3][1] = 0;
00631           COR2[3][2] = 0;
00632           COR2[3][3] += pow(GAimage2[t].getVal(ii,jj),2);
00633           COR2[3][4] += GAimage2[t].getVal(ii,jj)*RGimage2[t].getVal(ii,jj);
00634           COR2[3][5] += GAimage2[t].getVal(ii,jj)*BYimage2[t].getVal(ii,jj);
00635 
00636           COR2[4][0] += RGimage2[t].getVal(ii,jj)*INimage2[t].getVal(ii,jj);
00637           COR2[4][1] = 0;
00638           COR2[4][2] = 0;
00639           COR2[4][3] += RGimage2[t].getVal(ii,jj)*GAimage2[t].getVal(ii,jj);
00640           COR2[4][4] += pow(RGimage2[t].getVal(ii,jj),2);
00641           COR2[4][5] += RGimage2[t].getVal(ii,jj)*BYimage2[t].getVal(ii,jj);
00642 
00643           COR2[5][0] += BYimage2[t].getVal(ii,jj)*INimage2[t].getVal(ii,jj);
00644           COR2[5][1] = 0;
00645           COR2[5][2] = 0;
00646           COR2[5][3] += BYimage2[t].getVal(ii,jj)*GAimage2[t].getVal(ii,jj);
00647           COR2[5][4] += BYimage2[t].getVal(ii,jj)*RGimage2[t].getVal(ii,jj);
00648           COR2[5][5] += pow(BYimage2[t].getVal(ii,jj),2);
00649         }
00650       }
00651     }
00652     for(uint t = 0; t < aframes; t++)
00653     {
00654       for(int ii = 0; ii < BYimage[t].getWidth(); ii++)
00655       {
00656         for(int jj = 0; jj < BYimage[t].getHeight(); jj++)
00657         {
00658           COR[0][0] += pow(INimage[t].getVal(ii,jj),2);
00659           COR[0][1] = 0;
00660           COR[0][2] = 0;
00661           COR[0][3] += INimage[t].getVal(ii,jj)*GAimage[t].getVal(ii,jj);
00662           COR[0][4] += INimage[t].getVal(ii,jj)*RGimage[t].getVal(ii,jj);
00663           COR[0][5] += INimage[t].getVal(ii,jj)*BYimage[t].getVal(ii,jj);
00664 
00665           COR[1][0] = 0;
00666           COR[1][1] = 0;
00667           COR[1][2] = 0;
00668           COR[1][3] = 0;
00669           COR[1][4] = 0;
00670           COR[1][5] = 0;
00671 
00672           COR[2][0] = 0;
00673           COR[2][1] = 0;
00674           COR[2][2] = 0;
00675           COR[2][3] = 0;
00676           COR[2][4] = 0;
00677           COR[2][5] = 0;
00678 
00679           COR[3][0] += GAimage[t].getVal(ii,jj)*INimage[t].getVal(ii,jj);
00680           COR[3][1] = 0;
00681           COR[3][2] = 0;
00682           COR[3][3] += pow(GAimage[t].getVal(ii,jj),2);
00683           COR[3][4] += GAimage[t].getVal(ii,jj)*RGimage[t].getVal(ii,jj);
00684           COR[3][5] += GAimage[t].getVal(ii,jj)*BYimage[t].getVal(ii,jj);
00685 
00686           COR[4][0] += RGimage[t].getVal(ii,jj)*INimage[t].getVal(ii,jj);
00687           COR[4][1] = 0;
00688           COR[4][2] = 0;
00689           COR[4][3] += RGimage[t].getVal(ii,jj)*GAimage[t].getVal(ii,jj);
00690           COR[4][4] += pow(RGimage[t].getVal(ii,jj),2);
00691           COR[4][5] += RGimage[t].getVal(ii,jj)*BYimage[t].getVal(ii,jj);
00692 
00693           COR[5][0] += BYimage[t].getVal(ii,jj)*INimage[t].getVal(ii,jj);
00694           COR[5][1] = 0;
00695           COR[5][2] = 0;
00696           COR[5][3] += BYimage[t].getVal(ii,jj)*GAimage[t].getVal(ii,jj);
00697           COR[5][4] += BYimage[t].getVal(ii,jj)*RGimage[t].getVal(ii,jj);
00698           COR[5][5] += pow(BYimage[t].getVal(ii,jj),2);
00699         }
00700       }
00701     }
00702 
00703     for(int ii = 0; ii < 6; ii++)
00704     {
00705       if(active[ii])
00706       {
00707         for(int jj = 0; jj < 6; jj++)
00708         {
00709           if(active[jj])
00710           {
00711             //COR[ii][jj]  = sqrt(COR[ii][jj]/N)/(STD[ii]*STD[jj]);
00712             //COR[ii][jj]  = (COR[ii][jj]/N)/(STD[ii]*STD[jj]);
00713             //COR[ii][jj]  = COR[ii][jj]/N;
00714             //COR[ii][jj]  = pow(sqrt(COR[ii][jj]/N)/(STD[ii]*STD[jj]),4);
00715             COR[ii][jj] = (((COR[ii][jj]/N) - (MEAN[ii]*MEAN[jj]))/
00716                           (STD[ii]*STD[jj])) * MEAN[ii];
00717             Norm  += fabs(COR[ii][jj]);
00718 
00719             //COR2[ii][jj] = sqrt(COR2[ii][jj]/N2)/(STD2[ii]*STD2[jj]);
00720             //COR2[ii][jj] = (COR2[ii][jj]/N2)/(STD2[ii]*STD2[jj]);
00721             //COR2[ii][jj] = COR2[ii][jj]/N2;
00722             //COR2[ii][jj] = pow(sqrt(COR2[ii][jj]/N2)/(STD2[ii]*STD2[jj]),4);
00723             COR2[ii][jj] = (((COR2[ii][jj]/N2) - (MEAN2[ii]*MEAN2[jj]))/
00724                            (STD2[ii]*STD2[jj])) * MEAN2[ii];
00725             Norm2 += fabs(COR2[ii][jj]);
00726           }
00727         }
00728       }
00729     }
00730 
00731     FLOAT max  = 0;
00732     FLOAT min  = 10;
00733     FLOAT max2 = 0;
00734     FLOAT min2 = 10;
00735 
00736 
00737     for(int ii = 0; ii < 6; ii++)
00738     {
00739       if(active[ii])
00740       {
00741         for(int jj = 0; jj < 6; jj++)
00742         {
00743           if(active[jj])
00744           {
00745             COR[ii][jj]  = COR[ii][jj]/Norm;
00746             //COR[ii][jj] += 1;
00747             if(COR[ii][jj] > max)
00748               max = COR[ii][jj];
00749             if(COR[ii][jj] < min)
00750               min = COR[ii][jj];
00751 
00752             COR2[ii][jj] = COR2[ii][jj]/Norm2;
00753             //COR2[ii][jj] += 1;
00754             if(COR2[ii][jj] > max2)
00755               max2 = COR2[ii][jj];
00756             if(COR2[ii][jj] < min2)
00757               min2 = COR2[ii][jj];
00758           }
00759         }
00760       }
00761     }
00762 
00763     // normalize to range between 0 and 1
00764     // This stretched the correlation matrix artificially
00765     /*
00766     for(int ii = 0; ii < 6; ii++)
00767     {
00768       if(active[ii])
00769       {
00770         for(int jj = 0; jj < 6; jj++)
00771         {
00772           if(active[jj])
00773           {
00774               COR[ii][jj]  = (COR[ii][jj]  - min)  * (1/(max - min));
00775               COR2[ii][jj] = (COR2[ii][jj] - min2) * (1/(max2 - min2));
00776           }
00777         }
00778       }
00779     }
00780     */
00781     COR2[1][1] = 1;
00782     COR2[2][2] = 1;
00783     COR[1][1]  = 1;
00784     COR[2][2]  = 1;
00785 
00786     LINFO("Correlation Base Biasing Matrix");
00787     for(int ii = 0; ii < 6; ii++)
00788     {
00789       for(int jj = 0; jj < 6; jj++)
00790       {
00791         std::cerr << COR2[ii][jj] << "\t";
00792       }
00793       std::cerr << "\n";
00794     }
00795 
00796     LINFO("Correlation Anti Biasing Matrix");
00797     for(int ii = 0; ii < 6; ii++)
00798     {
00799       for(int jj = 0; jj < 6; jj++)
00800       {
00801         std::cerr << COR[ii][jj] << "\t";
00802       }
00803       std::cerr << "\n";
00804     }
00805 
00806     itsRemoveSurprise[i].RSsetCorrWeightMat(COR,COR2);
00807   }
00808 }
00809 
00810 /*************************************************************************/
00811 
00812 template <class FLOAT>
00813 void ScaleRemoveSurprise<FLOAT>::SRScomputeBayesFeatureBias(
00814                                            const uint frames,
00815                                            const string baseFileNamePrefix,
00816                                            const string antiFileNamePrefix)
00817 {
00818   const uint maps        = itsLevMax + itsDelMax;
00819   const uint features    = 7;
00820   const uint featureDims = maps * features;
00821 
00822   Image<FLOAT> baseImage;
00823   std::vector<Image<FLOAT> > baseVec(featureDims,baseImage);
00824   std::vector<std::vector<Image<FLOAT> > > imageSetBase(frames,baseVec);
00825   std::vector<std::vector<Image<FLOAT> > > imageSetAnti(frames,baseVec);
00826 
00827   string dash  = "-";
00828   string dot   = ".";
00829   string ftype = ".pnm";
00830   string ANTI  = "../ANTI/";
00831   string BASE  = "../BASE/";
00832   string basePrefix = BASE + baseFileNamePrefix;
00833   string antiPrefix = ANTI + antiFileNamePrefix;
00834 
00835   for(uint i = 0; i < frames; i++)
00836   {
00837     uint fnum = 0;
00838     // for file opening ...
00839     char frameChar[100];
00840     const uint itsFrame = i;
00841 
00842     if(itsFrame < 10)
00843       sprintf(frameChar,"00000%d",itsFrame);
00844     else if(itsFrame < 100)
00845       sprintf(frameChar,"0000%d",itsFrame);
00846     else if(itsFrame < 1000)
00847       sprintf(frameChar,"000%d",itsFrame);
00848     else if(itsFrame < 10000)
00849       sprintf(frameChar,"00%d",itsFrame);
00850     else if(itsFrame < 100000)
00851       sprintf(frameChar,"0%d",itsFrame);
00852     else
00853       sprintf(frameChar,"%d",itsFrame);
00854 
00855     string feature = "SRby";
00856     string fenameB = basePrefix + dash + feature + dash;
00857     string fenameA = antiPrefix + dash + feature + dash;
00858     for(uint j = 0; j < maps; j++)
00859     {
00860       char cmap[10]; sprintf(cmap,"%d",j);
00861       string file = fenameB + cmap + dash + frameChar + ftype;
00862       imageSetBase[i][fnum] = Raster::ReadGray(file);
00863       file        = fenameA + cmap + dash + frameChar + ftype;
00864       imageSetAnti[i][fnum] = Raster::ReadGray(file);
00865       fnum++;
00866     }
00867     /*
00868     feature = "SRdir_0";
00869     fenameB  = basePrefix + dash + feature + dash;
00870     fenameA = antiPrefix + dash + feature + dash;
00871     for(uint j = 0; j < maps; j++)
00872     {
00873       char cmap[10]; sprintf(cmap,"%d",j);
00874       string file = fenameB + cmap + dash + frameChar + ftype;
00875       imageSetBase[i][fnum] = Raster::ReadGray(file);
00876       file        = fenameA + cmap + dash + frameChar + ftype;
00877       imageSetAnti[i][fnum] = Raster::ReadGray(file);
00878       fnum++;
00879     }
00880 
00881     feature = "SRdir_1";
00882     fenameB  = basePrefix + dash + feature + dash;
00883     fenameA = antiPrefix + dash + feature + dash;
00884     for(uint j = 0; j < maps; j++)
00885     {
00886       char cmap[10]; sprintf(cmap,"%d",j);
00887       string file = fenameB + cmap + dash + frameChar + ftype;
00888       imageSetBase[i][fnum] = Raster::ReadGray(file);
00889       file        = fenameA + cmap + dash + frameChar + ftype;
00890       imageSetAnti[i][fnum] = Raster::ReadGray(file);
00891       fnum++;
00892     }
00893 
00894     feature = "SRdir_2";
00895     fenameB  = basePrefix + dash + feature + dash;
00896     fenameA = antiPrefix + dash + feature + dash;
00897     for(uint j = 0; j < maps; j++)
00898     {
00899       char cmap[10]; sprintf(cmap,"%d",j);
00900       string file = fenameB + cmap + dash + frameChar + ftype;
00901       imageSetBase[i][fnum] = Raster::ReadGray(file);
00902       file        = fenameA + cmap + dash + frameChar + ftype;
00903       imageSetAnti[i][fnum] = Raster::ReadGray(file);
00904       fnum++;
00905     }
00906 
00907     feature = "SRdir_3";
00908     fenameB  = basePrefix + dash + feature + dash;
00909     fenameA = antiPrefix + dash + feature + dash;
00910     for(uint j = 0; j < maps; j++)
00911     {
00912       char cmap[10]; sprintf(cmap,"%d",j);
00913       string file = fenameB + cmap + dash + frameChar + ftype;
00914       imageSetBase[i][fnum] = Raster::ReadGray(file);
00915       file        = fenameA + cmap + dash + frameChar + ftype;
00916       imageSetAnti[i][fnum] = Raster::ReadGray(file);
00917       fnum++;
00918     }
00919 
00920     feature = "SRflicker";
00921     fenameB  = basePrefix + dash + feature + dash;
00922     fenameA = antiPrefix + dash + feature + dash;
00923     for(uint j = 0; j < maps; j++)
00924     {
00925       char cmap[10]; sprintf(cmap,"%d",j);
00926       string file = fenameB + cmap + dash + frameChar + ftype;
00927       imageSetBase[i][fnum] = Raster::ReadGray(file);
00928       file        = fenameA + cmap + dash + frameChar + ftype;
00929       imageSetAnti[i][fnum] = Raster::ReadGray(file);
00930       fnum++;
00931     }
00932     */
00933     feature = "SRintensity";
00934     fenameB  = basePrefix + dash + feature + dash;
00935     fenameA = antiPrefix + dash + feature + dash;
00936     for(uint j = 0; j < maps; j++)
00937     {
00938       char cmap[10]; sprintf(cmap,"%d",j);
00939       string file = fenameB + cmap + dash + frameChar + ftype;
00940       imageSetBase[i][fnum] = Raster::ReadGray(file);
00941       file        = fenameA + cmap + dash + frameChar + ftype;
00942       imageSetAnti[i][fnum] = Raster::ReadGray(file);
00943       fnum++;
00944     }
00945 
00946     feature = "SRori_0";
00947     fenameB  = basePrefix + dash + feature + dash;
00948     fenameA = antiPrefix + dash + feature + dash;
00949     for(uint j = 0; j < maps; j++)
00950     {
00951       char cmap[10]; sprintf(cmap,"%d",j);
00952       string file = fenameB + cmap + dash + frameChar + ftype;
00953       imageSetBase[i][fnum] = Raster::ReadGray(file);
00954       file        = fenameA + cmap + dash + frameChar + ftype;
00955       imageSetAnti[i][fnum] = Raster::ReadGray(file);
00956       fnum++;
00957     }
00958 
00959     feature = "SRori_1";
00960     fenameB  = basePrefix + dash + feature + dash;
00961     fenameA = antiPrefix + dash + feature + dash;
00962     for(uint j = 0; j < maps; j++)
00963     {
00964       char cmap[10]; sprintf(cmap,"%d",j);
00965       string file = fenameB + cmap + dash + frameChar + ftype;
00966       imageSetBase[i][fnum] = Raster::ReadGray(file);
00967       file        = fenameA + cmap + dash + frameChar + ftype;
00968       imageSetAnti[i][fnum] = Raster::ReadGray(file);
00969       fnum++;
00970     }
00971 
00972     feature = "SRori_2";
00973     fenameB  = basePrefix + dash + feature + dash;
00974     fenameA = antiPrefix + dash + feature + dash;
00975     for(uint j = 0; j < maps; j++)
00976     {
00977       char cmap[10]; sprintf(cmap,"%d",j);
00978       string file = fenameB + cmap + dash + frameChar + ftype;
00979       imageSetBase[i][fnum] = Raster::ReadGray(file);
00980       file        = fenameA + cmap + dash + frameChar + ftype;
00981       imageSetAnti[i][fnum] = Raster::ReadGray(file);
00982       fnum++;
00983     }
00984 
00985     feature = "SRori_3";
00986     fenameB  = basePrefix + dash + feature + dash;
00987     fenameA = antiPrefix + dash + feature + dash;
00988     for(uint j = 0; j < maps; j++)
00989     {
00990       char cmap[10]; sprintf(cmap,"%d",j);
00991       string file = fenameB + cmap + dash + frameChar + ftype;
00992       imageSetBase[i][fnum] = Raster::ReadGray(file);
00993       file        = fenameA + cmap + dash + frameChar + ftype;
00994       imageSetAnti[i][fnum] = Raster::ReadGray(file);
00995       fnum++;
00996     }
00997 
00998     feature = "SRrg";
00999     fenameB  = basePrefix + dash + feature + dash;
01000     fenameA = antiPrefix + dash + feature + dash;
01001     for(uint j = 0; j < maps; j++)
01002     {
01003       char cmap[10]; sprintf(cmap,"%d",j);
01004       string file = fenameB + cmap + dash + frameChar + ftype;
01005       imageSetBase[i][fnum] = Raster::ReadGray(file);
01006       file        = fenameA + cmap + dash + frameChar + ftype;
01007       imageSetAnti[i][fnum] = Raster::ReadGray(file);
01008       fnum++;
01009     }
01010   }
01011 
01012   string base = "base";
01013   string anti = "anti";
01014 
01015   LINFO("RUNNING: corrEigenMatrix");
01016   corrEigenMatrix(imageSetBase,itsBaseCorr,itsBaseMean,itsBaseSTD,itsBaseSS,
01017                   itsBaseN,false);
01018 
01019   LINFO("****************************************************");
01020   LINFO("BaseCorr");
01021   // look at output if wanted
01022   for(uint i = 0; i < (uint)itsBaseCorr.getWidth(); i++)
01023   {
01024     for(uint j = 0; j < (uint)itsBaseCorr.getHeight(); j++)
01025     {
01026       std::cerr << itsBaseCorr.getVal(i,j) << "\t";
01027     }
01028     std::cerr << "\n";
01029   }
01030 
01031   itsBaseR = getPearsonRMatrix(itsBaseCorr,itsBaseSTD);
01032 
01033   for(uint i = 0; i < (uint)itsBaseR.getWidth(); i++)
01034   {
01035     for(uint j = 0; j < (uint)itsBaseR.getHeight(); j++)
01036     {
01037       std::cerr << itsBaseR.getVal(i,j) << "\t";
01038     }
01039     std::cerr << "\n";
01040   }
01041 
01042   LINFO("****************************************************");
01043   LINFO("BaseMean");
01044   for(uint i = 0; i < (uint)itsBaseMean.getWidth(); i++)
01045   {
01046     for(uint j = 0; j < (uint)itsBaseMean.getHeight(); j++)
01047     {
01048       std::cerr << itsBaseMean.getVal(i,j) << "\t";
01049     }
01050     std::cerr << "\n";
01051   }
01052 
01053   LINFO("****************************************************");
01054   LINFO("BaseSTD");
01055   for(uint i = 0; i < (uint)itsBaseSTD.getWidth(); i++)
01056   {
01057     for(uint j = 0; j < (uint)itsBaseSTD.getHeight(); j++)
01058     {
01059       std::cerr << itsBaseSTD.getVal(i,j) << "\t";
01060     }
01061     std::cerr << "\n";
01062   }
01063 
01064 
01065   LINFO("****************************************************");
01066   LINFO("BaseSS");
01067   for(uint i = 0; i < (uint)itsBaseSS.getWidth(); i++)
01068   {
01069     for(uint j = 0; j < (uint)itsBaseSS.getHeight(); j++)
01070     {
01071       std::cerr << itsBaseSS.getVal(i,j) << "\t";
01072     }
01073     std::cerr << "\n";
01074   }
01075 
01076   string type        = "corr.pfz";
01077   string filenamePFZ = baseFileNamePrefix + dot + base + dot + type;
01078   Raster::WriteFloat(itsBaseCorr,FLOAT_NORM_PRESERVE,filenamePFZ);
01079   type        = "mean.pfz";
01080   filenamePFZ = baseFileNamePrefix + dot + base + dot + type;
01081   Raster::WriteFloat(itsBaseMean,FLOAT_NORM_PRESERVE,filenamePFZ);
01082   type        = "STD.pfz";
01083   filenamePFZ = baseFileNamePrefix + dot + base + dot + type;
01084   Raster::WriteFloat(itsBaseSTD,FLOAT_NORM_PRESERVE,filenamePFZ);
01085   type        = "SS.pfz";
01086   filenamePFZ = baseFileNamePrefix + dot + base + dot + type;
01087   Raster::WriteFloat(itsBaseSTD,FLOAT_NORM_PRESERVE,filenamePFZ);
01088 
01089   type        = "R.png";
01090   filenamePFZ = baseFileNamePrefix + dot + base + dot + type;
01091   Image<FLOAT> normBaseR = normalizeFloat(itsBaseR,FLOAT_NORM_0_255);
01092   Image<byte>  byteBaseR = normBaseR;
01093   Raster::WriteGray(byteBaseR,filenamePFZ);
01094 
01095   corrEigenMatrix(imageSetAnti,itsAntiCorr,itsAntiMean,itsAntiSTD,itsAntiSS,
01096                   itsAntiN,false);
01097 
01098   // look at output if wanted
01099   for(uint i = 0; i < (uint)itsAntiCorr.getWidth(); i++)
01100   {
01101     for(uint j = 0; j < (uint)itsAntiCorr.getHeight(); j++)
01102     {
01103       std::cerr << itsAntiCorr.getVal(i,j) << "\t";
01104     }
01105     std::cerr << "\n";
01106   }
01107 
01108   itsAntiR = getPearsonRMatrix(itsAntiCorr,itsAntiSTD);
01109 
01110   for(uint i = 0; i < (uint)itsAntiR.getWidth(); i++)
01111   {
01112     for(uint j = 0; j < (uint)itsAntiR.getHeight(); j++)
01113     {
01114       std::cerr << itsAntiR.getVal(i,j) << "\t";
01115     }
01116     std::cerr << "\n";
01117   }
01118 
01119   type        = "corr.pfz";
01120   filenamePFZ = antiFileNamePrefix + dot + anti + dot + type;
01121   Raster::WriteFloat(itsAntiCorr,FLOAT_NORM_PRESERVE,filenamePFZ);
01122   type        = "mean.pfz";
01123   filenamePFZ = antiFileNamePrefix + dot + anti + dot + type;
01124   Raster::WriteFloat(itsAntiMean,FLOAT_NORM_PRESERVE,filenamePFZ);
01125   type        = "STD.pfz";
01126   filenamePFZ = antiFileNamePrefix + dot + anti + dot + type;
01127   Raster::WriteFloat(itsAntiSTD,FLOAT_NORM_PRESERVE,filenamePFZ);
01128   type        = "SS.pfz";
01129   filenamePFZ = antiFileNamePrefix + dot + anti + dot + type;
01130   Raster::WriteFloat(itsAntiSS,FLOAT_NORM_PRESERVE,filenamePFZ);
01131 
01132   type        = "R.png";
01133   filenamePFZ = antiFileNamePrefix + dot + anti + dot + type;
01134   Image<FLOAT> normAntiR = normalizeFloat(itsAntiR,FLOAT_NORM_0_255);
01135   Image<byte>  byteAntiR = normAntiR;
01136   Raster::WriteGray(byteAntiR,filenamePFZ);
01137 
01138   Image<FLOAT> DiffR;
01139   DiffR.resize(itsAntiR.getWidth(),itsAntiR.getHeight());
01140 
01141   typename Image<FLOAT>::iterator iAntiR = itsAntiR.beginw();
01142   typename Image<FLOAT>::iterator iBaseR = itsBaseR.beginw();
01143   typename Image<FLOAT>::iterator iDiffR = DiffR.beginw();
01144 
01145   while(iAntiR != itsAntiR.endw())
01146   {
01147     *iDiffR = *iAntiR - *iBaseR;
01148     ++iDiffR; ++iAntiR; ++iBaseR;
01149   }
01150 
01151   Image<PixRGB<FLOAT> > RGDiffR;
01152   RGDiffR.resize(itsAntiR.getWidth(),itsAntiR.getHeight());
01153   RGDiffR = normalizeRGPolarAuto(DiffR);
01154 
01155   type = "diffR.png";
01156   filenamePFZ = baseFileNamePrefix + dot + type;
01157   Raster::WriteRGB(RGDiffR,filenamePFZ);
01158 }
01159 
01160 /*************************************************************************/
01161 
01162 template <class FLOAT>
01163 void ScaleRemoveSurprise<FLOAT>::SRSopenBayesFeatureBias(
01164                                            const string baseFileNamePrefix,
01165                                            const string antiFileNamePrefix)
01166 {
01167   string dash        = "-";
01168   string dot         = ".";
01169   string base        = "base";
01170   string anti        = "anti";
01171   string type        = "corr.pfz";
01172   string filenamePFZ = baseFileNamePrefix + dot + base + dot + type;
01173   itsBaseCorr = Raster::ReadFloat(filenamePFZ);
01174   type        = "mean.pfz";
01175   filenamePFZ = baseFileNamePrefix + dot + base + dot + type;
01176   itsBaseMean = Raster::ReadFloat(filenamePFZ);
01177   type        = "STD.pfz";
01178   filenamePFZ = baseFileNamePrefix + dot + base + dot + type;
01179   itsBaseSTD  = Raster::ReadFloat(filenamePFZ);
01180   type        = "SS.pfz";
01181   filenamePFZ = baseFileNamePrefix + dot + base + dot + type;
01182   itsBaseSS   = Raster::ReadFloat(filenamePFZ);
01183 
01184   itsBaseR = getPearsonRMatrix(itsBaseCorr,itsBaseSTD);
01185 
01186   type        = "corr.pfz";
01187   filenamePFZ = antiFileNamePrefix + dot + anti + dot + type;
01188   itsAntiCorr = Raster::ReadFloat(filenamePFZ);
01189   type        = "mean.pfz";
01190   filenamePFZ = antiFileNamePrefix + dot + anti + dot + type;
01191   itsAntiMean = Raster::ReadFloat(filenamePFZ);
01192   type        = "STD.pfz";
01193   filenamePFZ = antiFileNamePrefix + dot + anti + dot + type;
01194   itsAntiSTD  = Raster::ReadFloat(filenamePFZ);
01195   type        = "SS.pfz";
01196   filenamePFZ = antiFileNamePrefix + dot + anti + dot + type;
01197   itsAntiSS   = Raster::ReadFloat(filenamePFZ);
01198 
01199   itsAntiR = getPearsonRMatrix(itsAntiCorr,itsAntiSTD);
01200 
01201   Image<FLOAT> DiffR;
01202   DiffR.resize(itsAntiR.getWidth(),itsAntiR.getHeight());
01203 
01204   typename Image<FLOAT>::iterator iAntiR = itsAntiR.beginw();
01205   typename Image<FLOAT>::iterator iBaseR = itsBaseR.beginw();
01206   typename Image<FLOAT>::iterator iDiffR = DiffR.beginw();
01207 
01208   while(iAntiR != itsAntiR.endw())
01209   {
01210     *iDiffR = *iAntiR - *iBaseR;
01211     ++iDiffR; ++iAntiR; ++iBaseR;
01212   }
01213 
01214   Image<PixRGB<FLOAT> > RGDiffR;
01215   RGDiffR.resize(itsAntiR.getWidth(),itsAntiR.getHeight());
01216   RGDiffR = normalizeRGPolarAuto(DiffR);
01217 
01218   type = "diffR.png";
01219   filenamePFZ = baseFileNamePrefix + dot + type;
01220   Raster::WriteRGB(RGDiffR,filenamePFZ);
01221 }
01222 
01223 /*************************************************************************/
01224 
01225 template <class FLOAT>
01226 void ScaleRemoveSurprise<FLOAT>::SRScomputeBayesFeatureCurrent(
01227                                      const uint frame,
01228                                      const string fileNamePrefix)
01229 {
01230   const uint maps        = itsLevMax + itsDelMax;
01231   const uint features    = 7;
01232   const uint featureDims = maps * features;
01233 
01234   Image<FLOAT> baseImage;
01235   std::vector<Image<FLOAT> > imageSetBase(featureDims,baseImage);
01236 
01237   string dot   = ".";
01238   string dash  = "-";
01239   string ftype = ".pnm";
01240   string basePrefix = fileNamePrefix;
01241 
01242   uint fnum = 0;
01243   // for file opening ...
01244   char frameChar[100];
01245   const uint itsFrame = frame;
01246 
01247   if(itsFrame < 10)
01248     sprintf(frameChar,"00000%d",itsFrame);
01249   else if(itsFrame < 100)
01250     sprintf(frameChar,"0000%d",itsFrame);
01251   else if(itsFrame < 1000)
01252     sprintf(frameChar,"000%d",itsFrame);
01253   else if(itsFrame < 10000)
01254     sprintf(frameChar,"00%d",itsFrame);
01255   else if(itsFrame < 100000)
01256     sprintf(frameChar,"0%d",itsFrame);
01257   else
01258     sprintf(frameChar,"%d",itsFrame);
01259 
01260   string feature = "SRby";
01261   string fenameB = basePrefix + dash + feature + dash;
01262   for(uint j = 0; j < maps; j++)
01263   {
01264     char cmap[10]; sprintf(cmap,"%d",j);
01265     string file = fenameB + cmap + dash + frameChar + ftype;
01266     imageSetBase[fnum] = Raster::ReadGray(file);
01267     fnum++;
01268   }
01269   /*
01270   feature = "SRdir_0";
01271   fenameB  = basePrefix + dash + feature + dash;
01272   for(uint j = 0; j < maps; j++)
01273   {
01274     char cmap[10]; sprintf(cmap,"%d",j);
01275     string file = fenameB + cmap + dash + frameChar + ftype;
01276     imageSetBase[fnum] = Raster::ReadGray(file);
01277     fnum++;
01278   }
01279 
01280   feature = "SRdir_1";
01281   fenameB  = basePrefix + dash + feature + dash;
01282   for(uint j = 0; j < maps; j++)
01283   {
01284     char cmap[10]; sprintf(cmap,"%d",j);
01285     string file = fenameB + cmap + dash + frameChar + ftype;
01286     imageSetBase[fnum] = Raster::ReadGray(file);
01287     fnum++;
01288   }
01289 
01290   feature = "SRdir_2";
01291   fenameB  = basePrefix + dash + feature + dash;
01292   for(uint j = 0; j < maps; j++)
01293   {
01294     char cmap[10]; sprintf(cmap,"%d",j);
01295     string file = fenameB + cmap + dash + frameChar + ftype;
01296     imageSetBase[fnum] = Raster::ReadGray(file);
01297     fnum++;
01298   }
01299 
01300   feature = "SRdir_3";
01301   fenameB  = basePrefix + dash + feature + dash;
01302   for(uint j = 0; j < maps; j++)
01303   {
01304     char cmap[10]; sprintf(cmap,"%d",j);
01305     string file = fenameB + cmap + dash + frameChar + ftype;
01306     imageSetBase[fnum] = Raster::ReadGray(file);
01307     fnum++;
01308   }
01309 
01310   feature = "SRflicker";
01311   fenameB  = basePrefix + dash + feature + dash;
01312   for(uint j = 0; j < maps; j++)
01313   {
01314     char cmap[10]; sprintf(cmap,"%d",j);
01315     string file = fenameB + cmap + dash + frameChar + ftype;
01316     imageSetBase[fnum] = Raster::ReadGray(file);
01317     fnum++;
01318   }
01319   */
01320   feature = "SRintensity";
01321   fenameB  = basePrefix + dash + feature + dash;
01322   for(uint j = 0; j < maps; j++)
01323   {
01324     char cmap[10]; sprintf(cmap,"%d",j);
01325     string file = fenameB + cmap + dash + frameChar + ftype;
01326     imageSetBase[fnum] = Raster::ReadGray(file);
01327     fnum++;
01328   }
01329 
01330   feature = "SRori_0";
01331   fenameB  = basePrefix + dash + feature + dash;
01332   for(uint j = 0; j < maps; j++)
01333   {
01334     char cmap[10]; sprintf(cmap,"%d",j);
01335     string file = fenameB + cmap + dash + frameChar + ftype;
01336     imageSetBase[fnum] = Raster::ReadGray(file);
01337     fnum++;
01338   }
01339 
01340   feature = "SRori_1";
01341   fenameB  = basePrefix + dash + feature + dash;
01342   for(uint j = 0; j < maps; j++)
01343   {
01344     char cmap[10]; sprintf(cmap,"%d",j);
01345     string file = fenameB + cmap + dash + frameChar + ftype;
01346     imageSetBase[fnum] = Raster::ReadGray(file);
01347     fnum++;
01348   }
01349 
01350   feature = "SRori_2";
01351   fenameB  = basePrefix + dash + feature + dash;
01352   for(uint j = 0; j < maps; j++)
01353   {
01354     char cmap[10]; sprintf(cmap,"%d",j);
01355     string file = fenameB + cmap + dash + frameChar + ftype;
01356     imageSetBase[fnum] = Raster::ReadGray(file);
01357     fnum++;
01358   }
01359 
01360   feature = "SRori_3";
01361   fenameB  = basePrefix + dash + feature + dash;
01362   for(uint j = 0; j < maps; j++)
01363   {
01364     char cmap[10]; sprintf(cmap,"%d",j);
01365     string file = fenameB + cmap + dash + frameChar + ftype;
01366     imageSetBase[fnum] = Raster::ReadGray(file);
01367     fnum++;
01368   }
01369 
01370   feature = "SRrg";
01371   fenameB  = basePrefix + dash + feature + dash;
01372 
01373   for(uint j = 0; j < maps; j++)
01374   {
01375     char cmap[10]; sprintf(cmap,"%d",j);
01376     string file = fenameB + cmap + dash + frameChar + ftype;
01377     imageSetBase[fnum] = Raster::ReadGray(file);
01378     fnum++;
01379   }
01380 
01381   getLikelyhoodImage(imageSetBase,itsBaseCorr,itsBaseMean,true,
01382                      itsBaseLikelyhood,itsNonNormalizedBaseL);
01383 
01384   string post        = "base.likelyhood.png";
01385   string file        = basePrefix + dot + frameChar + dot + post;
01386   Image<FLOAT> nbase = normalizeFloat(itsBaseLikelyhood,FLOAT_NORM_0_255);
01387   Image<byte> bnbase = nbase;
01388   Raster::WriteGray(bnbase,file);
01389 
01390   getLikelyhoodImage(imageSetBase,itsAntiCorr,itsAntiMean,true,
01391                      itsAntiLikelyhood,itsNonNormalizedAntiL);
01392 
01393   post   = "anti.likelyhood.png";
01394   file   = basePrefix + dot + frameChar + dot + post;
01395   nbase  = normalizeFloat(itsAntiLikelyhood,FLOAT_NORM_0_255);
01396   bnbase = nbase;
01397   Raster::WriteGray(bnbase,file);
01398 
01399   FLOAT one  = 1.0;
01400   FLOAT two  = 2.0;
01401   FLOAT beta = 0.075;
01402 
01403   itsBayesImage     = getNormalizedBayesImage(itsBaseLikelyhood,
01404                                               itsAntiLikelyhood,true,beta,
01405                                               one,one,two);
01406 
01407   post   = "bayes.likelyhood.png";
01408   file   = basePrefix  + dot + frameChar + dot + post;
01409   nbase  = normalizeFloat(itsBayesImage,FLOAT_NORM_0_255);
01410   bnbase = nbase;
01411   Raster::WriteGray(bnbase,file);
01412 
01413   Image<FLOAT> beliefValues;
01414   getAugmentedBeliefBayesImage(itsBayesImage,itsNonNormalizedBaseL,
01415                                itsNonNormalizedAntiL,one,itsBeliefImage,
01416                                beliefValues);
01417 
01418   post   = "belief.likelyhood.png";
01419   file   = basePrefix  + dot + frameChar + dot + post;
01420   nbase  = normalizeFloat(itsBeliefImage,FLOAT_NORM_0_255);
01421   bnbase = nbase;
01422   Raster::WriteGray(bnbase,file);
01423 
01424   post   = "belief.likelyhood.NN.png";
01425   file   = basePrefix  + dot + frameChar + dot + post;
01426   for(int i = 0; i < itsBeliefImage.getWidth(); i++)
01427   {
01428     for(int j = 0; j < itsBeliefImage.getHeight(); j++)
01429     {
01430       //std::cerr << itsBeliefImage.getVal(i,j) << "\n";
01431       nbase.setVal(i,j,itsBeliefImage.getVal(i,j) * 128.0);
01432     }
01433   }
01434   bnbase = nbase;
01435   Raster::WriteGray(bnbase,file);
01436 
01437   post   = "belief.values.png";
01438   file   = basePrefix  + dot + frameChar + dot + post;
01439   nbase  = normalizeFloat(beliefValues,FLOAT_NORM_0_255);
01440   bnbase = nbase;
01441   Raster::WriteGray(bnbase,file);
01442 
01443   for(ushort i = 0; i < itsMaxIndex; i++)
01444   {
01445     itsRemoveSurprise[i].RSinputBayesWeightImage(itsBeliefImage);
01446   }
01447 }
01448 
01449 /*************************************************************************/
01450 
01451 template <class FLOAT>
01452 void ScaleRemoveSurprise<FLOAT>::SRSprocessFrame()
01453 {
01454   // for file opening ...
01455   char frameChar[100];
01456 
01457   if(itsFrame < 10)
01458     sprintf(frameChar,"00000%d",itsFrame);
01459   else if(itsFrame < 100)
01460     sprintf(frameChar,"0000%d",itsFrame);
01461   else if(itsFrame < 1000)
01462     sprintf(frameChar,"000%d",itsFrame);
01463   else if(itsFrame < 10000)
01464     sprintf(frameChar,"00%d",itsFrame);
01465   else if(itsFrame < 100000)
01466     sprintf(frameChar,"0%d",itsFrame);
01467   else
01468     sprintf(frameChar,"%d",itsFrame);
01469 
01470 
01471   // process over each scale type from the image pyramid
01472 
01473   //typename Image<PixRGB<FLOAT> >::iterator temp;
01474 
01475   // std::vector<typename Image<PixRGB<FLOAT> >::iterator>
01476   //  imageItrs(itsMaxIndex,temp);
01477 
01478   for(ushort i = 0; i < itsMaxIndex; i++)
01479   {
01480 
01481     //char foo[100];
01482     // sprintf(foo,"%d",i);
01483     //string scale = foo;
01484     //string temp  = "temp";
01485     //string rtemp = "raw";
01486     //string png   = "png";
01487     //string dot   = ".";
01488     //string frame = frameChar;
01489 
01490     //string rname  = rtemp + dot + scale + dot + frame + dot + png;
01491 
01492     //Raster::VisuRGB(itsRawImage,rname);
01493 
01494     char fileName[100];
01495 
01496     itsRemoveSurprise[i].RSinputRawImage(itsRawImage,itsFrame);
01497 
01498     itsRemoveSurprise[i].RSinputSalMap(itsSalMap);
01499 
01500     sprintf(fileName,"IntensitySurprise.%s.%d.SCSimage.float.pfz",frameChar,i);
01501     string fnameS = fileName;
01502     const Image<FLOAT> INimage = Raster::ReadFloat(fnameS);
01503     itsRemoveSurprise[i].RSinputConspicIN(INimage);
01504 
01505     sprintf(fileName,"DirectionSurprise.%s.%d.SCSimage.float.pfz",frameChar,i);
01506     fnameS = fileName;
01507     const Image<FLOAT> DRimage = Raster::ReadFloat(fnameS);
01508     itsRemoveSurprise[i].RSinputConspicDR(DRimage);
01509 
01510     sprintf(fileName,"FlickerSurprise.%s.%d.SCSimage.float.pfz",frameChar,i);
01511     fnameS = fileName;
01512     const Image<FLOAT> FLimage = Raster::ReadFloat(fnameS);
01513     itsRemoveSurprise[i].RSinputConspicFL(FLimage);
01514 
01515     sprintf(fileName,"GaborSurprise.%s.%d.SCSimage.float.pfz",frameChar,i);
01516     fnameS = fileName;
01517     const Image<FLOAT> GAimage = Raster::ReadFloat(fnameS);
01518     itsRemoveSurprise[i].RSinputConspicGA(GAimage);
01519 
01520     sprintf(fileName,"RedGreenSurprise.%s.%d.SCSimage.float.pfz",frameChar,i);
01521     fnameS = fileName;
01522     const Image<FLOAT> RGimage = Raster::ReadFloat(fnameS);
01523     itsRemoveSurprise[i].RSinputConspicRG(RGimage);
01524 
01525     sprintf(fileName,"BlueYellowSurprise.%s.%d.SCSimage.float.pfz",frameChar,i);
01526     fnameS = fileName;
01527     const Image<FLOAT> BYimage = Raster::ReadFloat(fnameS);
01528     itsRemoveSurprise[i].RSinputConspicBY(BYimage);
01529 
01530     // process this scale
01531     itsRemoveSurprise[i].RSprocessFrameSeperable();
01532 
01533     // get result image for this scale
01534     itsResultImages[i] = itsRemoveSurprise[i].RSgetFrame();
01535     //LINFO("Setting iterator");
01536     //imageItrs[i]       = itsResultImages[i].beginw();
01537     LINFO("done");
01538 
01539     //string name  = temp + dot + scale + dot + frame + dot + png;
01540     //Raster::VisuRGB(itsResultImages[i],name);
01541   }
01542 
01543   FLOAT norm = 0.0F;
01544 
01545 
01546 
01547   // first form a biased sum over each scale
01548   for(ushort i = 0; i < itsMaxIndex; i++)
01549   {
01550     typename Image<PixRGB<FLOAT> >::iterator finalImageItr =
01551       itsFinalImage.beginw();
01552     typename Image<PixRGB<FLOAT> >::iterator resultImageItr =
01553       itsResultImages[i].beginw();
01554     const FLOAT bias = itsScaleBias[i];
01555     norm += bias;
01556     while(finalImageItr !=  itsFinalImage.endw())
01557     {
01558       *finalImageItr += (*resultImageItr) * bias;
01559       ++finalImageItr; ++resultImageItr;
01560     }
01561   }
01562 
01563   // then normalize into the final image
01564   for(typename Image<PixRGB<FLOAT> >::iterator finalImageItr =
01565         itsFinalImage.beginw();
01566       finalImageItr != itsFinalImage.endw();
01567       ++finalImageItr)
01568   {
01569     *finalImageItr = (*finalImageItr)/norm;
01570   }
01571 }
01572 
01573 /*************************************************************************/
01574 
01575 template <class FLOAT>
01576 Image<PixRGB<FLOAT> > ScaleRemoveSurprise<FLOAT>::SRSgetFrame() const
01577 {
01578   return itsFinalImage;
01579 }
01580 
01581 /*************************************************************************/
01582 
01583 template <class FLOAT>
01584 Image<PixRGB<FLOAT> > ScaleRemoveSurprise<FLOAT>::SRSgetDiffImage() const
01585 {
01586   Image<PixRGB<float> > diffImage;
01587   diffImage.resize(itsImageSizeX,itsImageSizeY);
01588 
01589   typename Image<PixRGB<float> >::const_iterator finalImageItr =
01590     itsFinalImage.begin();
01591   typename Image<PixRGB<float> >::const_iterator rawImageItr  =
01592     itsRawImage.begin();
01593   typename Image<PixRGB<float> >::iterator diffImageItr =
01594     diffImage.beginw();
01595 
01596   while(rawImageItr != itsRawImage.end())
01597   {
01598     *diffImageItr = abs((*rawImageItr) - (*finalImageItr));
01599     ++diffImageItr; ++rawImageItr; ++finalImageItr;
01600   }
01601   return diffImage;
01602 }
01603 
01604 /*************************************************************************/
01605 
01606 template <class FLOAT> std::vector<Image<PixRGB<FLOAT> > >
01607 ScaleRemoveSurprise<FLOAT>::SRSgetDiffParts() const
01608 {
01609   Image<PIX_H2SV_TYPE<FLOAT> > rawDiffImage;
01610   rawDiffImage.resize(itsImageSizeX,itsImageSizeY);
01611 
01612   for(ushort i = 0; i < itsMaxIndex; i++)
01613   {
01614     const Image<PIX_H2SV_TYPE<FLOAT> > outImage =
01615       itsRemoveSurprise[i].RSgetRawOutImage();
01616     const Image<PIX_H2SV_TYPE<FLOAT> > inImage  =
01617       itsRemoveSurprise[i].RSgetRawInImage();
01618 
01619     typename Image<PIX_H2SV_TYPE<FLOAT> >::const_iterator outImageItr     =
01620       outImage.begin();
01621     typename Image<PIX_H2SV_TYPE<FLOAT> >::const_iterator inImageItr      =
01622       inImage.begin();
01623     typename Image<PIX_H2SV_TYPE<FLOAT> >::iterator rawDiffImageItr       =
01624       rawDiffImage.beginw();
01625 
01626     while(outImageItr != outImage.end())
01627     {
01628       (*rawDiffImageItr) += (*outImageItr) - (*inImageItr);
01629       ++outImageItr; ++inImageItr; ++rawDiffImageItr;
01630     }
01631   }
01632 
01633   typename Image<PIX_H2SV_TYPE<FLOAT> >::iterator rawDiffImageItr =
01634     rawDiffImage.beginw();
01635 
01636   while(rawDiffImageItr != rawDiffImage.end())
01637   {
01638     (*rawDiffImageItr) = (*rawDiffImageItr)/itsMaxIndex;
01639     ++rawDiffImageItr;
01640   }
01641 
01642   Image<FLOAT> baseImage;
01643   baseImage.resize(itsImageSizeX,itsImageSizeY);
01644   std::vector<Image<FLOAT> > outImageVec(4,baseImage);
01645 
01646 
01647   for(ushort x = 0; x < itsImageSizeX; x++)
01648   {
01649     for(ushort y = 0; y < itsImageSizeY; y++)
01650     {
01651       outImageVec[0].setVal(x,y,rawDiffImage.getVal(x,y).p[0]);
01652       outImageVec[1].setVal(x,y,rawDiffImage.getVal(x,y).p[1]);
01653       outImageVec[2].setVal(x,y,rawDiffImage.getVal(x,y).p[2]);
01654       outImageVec[3].setVal(x,y,rawDiffImage.getVal(x,y).p[3]);
01655     }
01656   }
01657 
01658   Image<PixRGB<FLOAT> > baseImageRGB;
01659   baseImageRGB.resize(itsImageSizeX,itsImageSizeY);
01660   std::vector<Image<PixRGB<FLOAT> > > outImageRGVec(4,baseImageRGB);
01661 
01662   (outImageRGVec[0]) = normalizeRGPolarAuto(outImageVec[0]);
01663 
01664   (outImageRGVec[1]) = normalizeRGPolarAuto(outImageVec[1]);
01665 
01666   (outImageRGVec[2]) = normalizeRGPolarAuto(outImageVec[2]);
01667 
01668   (outImageRGVec[3]) = normalizeRGPolarAuto(outImageVec[3]);
01669 
01670   return outImageRGVec;
01671 }
01672 
01673 /*************************************************************************/
01674 
01675 template <class FLOAT>
01676 std::vector<Image<FLOAT> > ScaleRemoveSurprise<FLOAT>::SRSgetBetaParts() const
01677 {
01678   Image<PixHyper<FLOAT,6> > outBetaImage;
01679   outBetaImage.resize(itsImageSizeX,itsImageSizeY);
01680 
01681   for(ushort i = 0; i < itsMaxIndex; i++)
01682   {
01683     const Image<PixHyper<FLOAT,6> > betaImage =
01684       itsRemoveSurprise[i].RSgetBetaImage();
01685 
01686     typename Image<PixHyper<FLOAT,6> >::const_iterator betaImageItr =
01687       betaImage.begin();
01688     typename Image<PixHyper<FLOAT,6> >::iterator outBetaImageItr    =
01689       outBetaImage.beginw();
01690 
01691     PixHyper<FLOAT,6> pIndex((FLOAT)itsMaxIndex);
01692 
01693     while(betaImageItr != betaImage.end())
01694     {
01695       (*outBetaImageItr) += (*betaImageItr)/pIndex;
01696       ++betaImageItr; ++outBetaImageItr;
01697     }
01698   }
01699 
01700   Image<FLOAT> baseImage;
01701   baseImage.resize(itsImageSizeX,itsImageSizeY);
01702   std::vector<Image<FLOAT> > outImageVec(6,baseImage);
01703 
01704   for(ushort x = 0; x < itsImageSizeX; x++)
01705   {
01706     for(ushort y = 0; y < itsImageSizeY; y++)
01707     {
01708       outImageVec[0].setVal(x,y,outBetaImage.getVal(x,y).p[0]);
01709       outImageVec[1].setVal(x,y,outBetaImage.getVal(x,y).p[1]);
01710       outImageVec[2].setVal(x,y,outBetaImage.getVal(x,y).p[2]);
01711       outImageVec[3].setVal(x,y,outBetaImage.getVal(x,y).p[3]);
01712       outImageVec[4].setVal(x,y,outBetaImage.getVal(x,y).p[4]);
01713       outImageVec[5].setVal(x,y,outBetaImage.getVal(x,y).p[5]);
01714     }
01715   }
01716   return outImageVec;
01717 }
01718 
01719 
01720 /*************************************************************************/
01721 template class ScaleRemoveSurprise<float>;
01722 
01723 #endif
Generated on Sun May 8 08:06:52 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3