getSubMapData.C

Go to the documentation of this file.
00001 /*!@file AppNeuro/getSubMapData.C program get eye tracking data and compute NSS  */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the 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: Farhan Baluch <fbaluch at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppNeuro/getSubMapData.C $
00035 // $Id: getSubMapData.C 10794 2009-02-08 06:21:09Z itti $
00036 //
00037 
00038 #ifndef APPNEURO_GETSUBMAPDATA_C_DEFINED
00039 #define APPNEURO_GETSUBMAPDATA_C_DEFINED
00040 
00041 #include "Component/ModelManager.H"
00042 #include "Image/Image.H"
00043 #include "Image/Pixels.H"
00044 #include "Image/ShapeOps.H" // for rescale()
00045 #include "Neuro/getSaliency.H"
00046 #include "Raster/Raster.H"
00047 #include "Util/log.H"
00048 #include "Psycho/EyeTrace.H"
00049 #include "Image/MathOps.H"
00050 #include <fstream>
00051 #include <iostream>
00052 //this code will take as input an image file and an eye file and computes NSS for all submaps generated by the model for the image.
00053 
00054 float getNSS(const std::vector<Point2D<int> >& sacTargs, Image<float> salMap);
00055 
00056 
00057 float getNSS(const std::vector<Point2D<int> >& sacTargs, Image<float> salMap)
00058 {
00059 
00060         //first normalize salmap
00061     double m,s;
00062 
00063     m = mean(salMap);
00064     s = stdev(salMap);
00065     std::vector<double> NSS(sacTargs.size());
00066     double NSStotal=0.0;
00067     int Ncnt=0;
00068     float tempX,tempY;
00069     LINFO("\n saccade target size %d",(int)sacTargs.size());
00070 
00071     if (s > 0)
00072     {
00073         for(size_t cnt=0; cnt < sacTargs.size(); cnt++)
00074         {
00075             tempX = (sacTargs[cnt].i)/16;
00076             tempY = (sacTargs[cnt].j)/16;
00077 
00078             if(salMap.coordsOk(tempX,tempY))
00079             {   LINFO("%d ,hello  x%f y:%f", (int)cnt,tempX,tempY);
00080                 //LINFO("%f",salMap.getVal(tempX,tempY));
00081                 NSS[Ncnt] = (salMap.getVal((int)tempX,(int)tempY) - m) / s;
00082                 Ncnt++;
00083             }
00084         }
00085     }
00086 
00087     for (size_t i =0; i < NSS.size(); i++)
00088              {
00089                  NSStotal += NSS[i];
00090                  LINFO("NSS[%d] %f",(int)i,NSS[i]);
00091              }
00092 
00093     if(Ncnt > 1)
00094         NSStotal =  NSStotal/(Ncnt-1);
00095 
00096     return NSStotal;
00097 
00098 //computeNSS
00099 
00100 }
00101 
00102 
00103 
00104 int main(int argc, char** argv)
00105 {
00106   ModelManager manager("test");
00107 
00108   nub::ref<GetSaliency> saliency(new GetSaliency(manager));
00109   manager.addSubComponent(saliency);
00110   if (manager.parseCommandLine(argc, argv, "<input-image><eye-file><save-file>", 3, 3) == false)
00111     return -1;
00112   manager.start();
00113 
00114 
00115   std::string imgFile, eyeFile,saveFile;
00116   imgFile =  manager.getExtraArg(0);
00117   eyeFile =  manager.getExtraArg(1);
00118   saveFile = manager.getExtraArg(2);
00119 
00120 
00121   const Image<PixRGB<byte> > img = Raster::ReadRGB(imgFile);
00122   const int num_salient_spots = saliency->compute(img, SimTime::SECS(0.1));
00123   LINFO("found %d salient spots", num_salient_spots);
00124   const Image<float> salmap = saliency->getSalmap();
00125   const Image<float> resized_salmap = rescale(salmap, img.getDims());
00126   const std::vector<subMap> itsSubMaps = saliency->getSubMaps();
00127 
00128 
00129    rutz::shared_ptr<EyeTrace> et(new EyeTrace(eyeFile, PixRGB<byte>(255)));
00130    rutz::shared_ptr<EyeData> data;
00131    std::vector<Point2D<int> > sacTargets(et->numSaccades());
00132    LINFO("the num sac %d",(int)et->numSaccades());
00133 
00134 
00135        /* char filename[256];
00136    sprintf(filename, "%s",(char*)imgFile);
00137        // filename = imgFile;
00138 
00139        // FILE* outputFile = fopen(filename, "w+");
00140        // if(outputFile==0)
00141        //LFATAL("couldnt open file:%s", filename);
00142        */
00143 
00144    std::ofstream outputFile;
00145    outputFile.open(saveFile.c_str());
00146 
00147    size_t index=0;
00148    int cnt =0;
00149 
00150    while(et->hasData(index))      //lets load the saccade targets and store them in a vec
00151    {
00152       data = et->data(index);
00153       if(data->hasSaccadeTargetData())
00154          {
00155              sacTargets[cnt] = data->saccadeTarget();
00156              LINFO("sacctarget %d  %d,%d",cnt,sacTargets[cnt].i,sacTargets[cnt].j);
00157              cnt++;
00158          }
00159 
00160        index++;
00161 
00162    }
00163 
00164    getNSS(sacTargets,itsSubMaps[0].itsSubMap);
00165 
00166    float temp;
00167    for(int i =0; i < (int)itsSubMaps.size(); i++)
00168    {
00169            //    fprintf(outputFile,"%f\n",getNSS(sacTargets, itsSubMaps[i]));
00170        temp = getNSS(sacTargets, itsSubMaps[i].itsSubMap);
00171        outputFile << temp <<"\n";
00172     }
00173 
00174 
00175   Raster::WriteFloat(resized_salmap, FLOAT_NORM_0_255, "salmap.png");
00176   Raster::WriteFloat(rescale(itsSubMaps[1].itsSubMap,
00177                              img.getDims()), FLOAT_NORM_0_255,"subMap1.png");
00178 
00179   outputFile.close();
00180   manager.stop();
00181 
00182   return 0;
00183 }
00184 
00185 // ######################################################################
00186 /* So things look consistent in everyone's emacs... */
00187 /* Local Variables: */
00188 /* mode: c++ */
00189 /* indent-tabs-mode: nil */
00190 /* End: */
00191 
00192 #endif // APPNEURO_GETSUBMAPDATA_C_DEFINED
Generated on Sun May 8 08:40:08 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3