score-map-vs-eye.C

Go to the documentation of this file.
00001 /*!@file TIGS/score-map-vs-eye.C */
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: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/TIGS/score-map-vs-eye.C $
00035 // $Id: score-map-vs-eye.C 9412 2008-03-10 23:10:15Z farhan $
00036 //
00037 
00038 #ifndef TIGS_SCORE_MAP_VS_EYE_C_DEFINED
00039 #define TIGS_SCORE_MAP_VS_EYE_C_DEFINED
00040 
00041 #include "Component/ModelManager.H"
00042 #include "Component/ModelOptionDef.H"
00043 #include "Media/FrameSeries.H"
00044 #include "Psycho/EyeSFile.H"
00045 #include "TIGS/Scorer.H"
00046 #include "TIGS/TigsOpts.H"
00047 #include "Util/Pause.H"
00048 #include "Util/csignals.H"
00049 #include "Util/sformat.H"
00050 
00051 #include <fstream>
00052 
00053 // Used by: TigsJob
00054 static const ModelOptionDef OPT_MoviePeriod =
00055   { MODOPT_ARG(SimTime), "MoviePeriod", &MOC_TIGS, OPTEXP_CORE,
00056     "Inter-frame period (or rate) of input movie",
00057     "movie-period", '\0', "<float>{s|ms|us|ns|Hz}", "0.0s" };
00058 
00059 // Used by: TigsJob
00060 static const ModelOptionDef OPT_TimeShift =
00061   { MODOPT_ARG(SimTime), "TimeShift", &MOC_TIGS, OPTEXP_CORE,
00062     "Amount of time shift to use between visual input and eye position",
00063     "time-shift", '\0', "<float>{s|ms|us|ns|Hz}", "0.0s" };
00064 
00065 static void writeStringToFile(const std::string& fname,
00066                               const std::string& msg)
00067 {
00068   std::ofstream ofs(fname.c_str());
00069   if (!ofs.is_open())
00070     LFATAL("couldn't open %s for writing", fname.c_str());
00071   ofs << msg << '\n';
00072   ofs.close();
00073 }
00074 
00075 int submain(int argc, const char** argv)
00076 {
00077   volatile int signum = 0;
00078   catchsignals(&signum);
00079 
00080   ModelManager mgr("map-eye scorer");
00081   OModelParam<SimTime> moviePeriod(&OPT_MoviePeriod, &mgr);
00082   OModelParam<SimTime> timeShift(&OPT_TimeShift, &mgr);
00083 
00084   nub::ref<InputFrameSeries> ifs(new InputFrameSeries(mgr));
00085   mgr.addSubComponent(ifs);
00086 
00087   nub::ref<EyeSFile> eyeS(new EyeSFile(mgr));
00088   mgr.addSubComponent(eyeS);
00089 
00090   mgr.exportOptions(MC_RECURSE);
00091 
00092   if (mgr.parseCommandLine(argc, argv, "outstem", 1, 1) == false)
00093     return 1;
00094 
00095   mgr.start();
00096 
00097   const std::string outstem = mgr.getExtraArg(0);
00098 
00099   if (moviePeriod.getVal() == SimTime::ZERO())
00100     LFATAL("movie period must be non-zero");
00101 
00102   PauseWaiter p;
00103 
00104   int nframes = 0;
00105 
00106   MulticastScorer scorer;
00107 
00108   std::ofstream hist((outstem + ".hist").c_str());
00109   if (!hist.is_open())
00110     LFATAL("couldn't open %s.hist for writing", outstem.c_str());
00111 
00112   while (1)
00113     {
00114       if (signum != 0)
00115         {
00116           LINFO("caught signal %s; quitting", signame(signum));
00117           break;
00118         }
00119 
00120       if (p.checkPause())
00121         continue;
00122 
00123       const SimTime stime =
00124         moviePeriod.getVal() * (nframes+1) - timeShift.getVal();
00125 
00126       ifs->updateNext();
00127       Image<float> map = ifs->readFloat();
00128 
00129       if (!map.initialized())
00130         {
00131           LINFO("input exhausted; quitting");
00132           break;
00133         }
00134 
00135       if (stime > SimTime::ZERO())
00136         {
00137           const Point2D<int> eyepos = eyeS->readUpTo(stime);
00138 
00139           LINFO("simtime %.6fs, movie frame %d, eye sample %d, ratio %f, "
00140                 "eyepos (x=%d, y=%d)",
00141                 stime.secs(), nframes+1, eyeS->lineNumber(),
00142                 double(eyeS->lineNumber())/double(nframes+1),
00143                 eyepos.i, eyepos.j);
00144 
00145           const int p = (eyepos.j / 16) * map.getWidth() + (eyepos.i / 16);
00146 
00147           scorer.score("scorer", map, p);
00148 
00149           hist << scorer.itsNssScorer.getCurrentZscore() << ' '
00150                << scorer.itsPrctileScorer.getCurrentPrctile() << '\n';
00151         }
00152 
00153       ++nframes;
00154     }
00155 
00156   writeStringToFile(outstem + ".zscore",
00157                     sformat("%.5f", scorer.itsNssScorer.getOverallZscore()));
00158 
00159   writeStringToFile(outstem + ".prctile",
00160                     sformat("%.5f", scorer.itsPrctileScorer.getOverallPrctile()));
00161 
00162   mgr.stop();
00163 
00164   return 0;
00165 }
00166 
00167 int main(int argc, const char** argv)
00168 {
00169   try {
00170     submain(argc, argv);
00171   } catch(...) {
00172     REPORT_CURRENT_EXCEPTION;
00173     std::terminate();
00174   }
00175 }
00176 
00177 // ######################################################################
00178 /* So things look consistent in everyone's emacs... */
00179 /* Local Variables: */
00180 /* mode: c++ */
00181 /* indent-tabs-mode: nil */
00182 /* End: */
00183 
00184 #endif // TIGS_SCORE_MAP_VS_EYE_C_DEFINED
Generated on Sun May 8 08:06:56 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3