00001 /*!@file Neuro/SimulationViewerStats.H View/save a bunch of stats */ 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: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Neuro/SimulationViewerStats.H $ 00035 // $Id: SimulationViewerStats.H 10794 2009-02-08 06:21:09Z itti $ 00036 // 00037 00038 #ifndef NEURO_SIMULATIONVIEWERSTATS_H_DEFINED 00039 #define NEURO_SIMULATIONVIEWERSTATS_H_DEFINED 00040 00041 #include "Neuro/SimulationViewer.H" 00042 #include "Simulation/SimEvents.H" 00043 #include <fstream> 00044 00045 //! View/save a bunch of stats about the saliency map 00046 /*! This SimulationViewer's purpose is mainly to save a variety of 00047 stats about the saliency map, including about locations of highest 00048 peak, mean/variance of saliency, number of peaks, etc. */ 00049 class SimulationViewerStats : public SimulationViewer { 00050 public: 00051 // ###################################################################### 00052 /*! @name Constructors and destructors */ 00053 //@{ 00054 00055 //! Constructor. See ModelComponent.H. 00056 SimulationViewerStats(OptionManager& mgr, 00057 const std::string& descrName="Simulation Viewer Stats", 00058 const std::string& tagName="SimulationViewerStats"); 00059 //! Destructor 00060 virtual ~SimulationViewerStats(); 00061 00062 //@} 00063 00064 protected: 00065 //! Callback for every time we should save our outputs 00066 SIMCALLBACK_DECLARE(SimulationViewerStats, SimEventSaveOutput); 00067 00068 OModelParam<std::string> itsStatsFname; //!< Filename for the stats 00069 OModelParam<bool> itsSaveXcombo; //!< Save images too 00070 OModelParam<bool> itsSaveYcombo; //!< Save images too 00071 OModelParam<bool> itsComputeAGStats; //!< Save Attention Gate Stats 00072 OModelParam<int> itsAGTargetFrame; //!< Which frame is the target? 00073 OModelParam<std::string> itsAGMaskFile; //!< Which file has the Ground Truth 00074 OModelParam<std::string> itsAGStatsSaveFile; //!< File save AG stats to 00075 /*! @name Compatable statistics with SingleChannels stats */ 00076 //@{ 00077 00078 //! Save basic single channel stats 00079 /*! we also save final saliency stats using the same format */ 00080 OModelParam<bool> itsGetSingleChannelStats; 00081 00082 //! File name for single channel stats 00083 /*! we also save final saliency stats using the same format */ 00084 OModelParam<std::string> itsGetSingleChannelStatsFile; 00085 00086 //! Should we save frequency information using 2D FFT? 00087 OModelParam<bool> itsSaveStatsPerChannelFreq; 00088 00089 //@} 00090 00091 //! Get started: 00092 virtual void start2(); 00093 00094 //! Get stopped: 00095 virtual void stop2(); 00096 00097 //! apply an advisory lock on a file 00098 void lockFile(const std::string fileName, int &fd, struct flock &fl) const; 00099 00100 //! remove an advisory lock on a file 00101 void unlockFile(const std::string fileName, const int fd, 00102 struct flock &fl) const; 00103 00104 //! Save our various results 00105 virtual void save1(const ModelComponentSaveInfo& sinfo); 00106 00107 //! Compute and save target stats with mask and AttentionGate? 00108 /*! This method requires a mask file for ground truth. If none is 00109 avialable, then use computeLAMStats to save basic attention gate 00110 stats only 00111 */ 00112 virtual void computeAGStats(SimEventQueue& q); 00113 00114 //! Compute Last Attention Map stats from AttentionGate? 00115 virtual void computeLAMStats(const Image<float> &img); 00116 00117 //! Save our various results in a channel compatable format used in SingleChannel.C 00118 virtual void saveCompat(const Image<float>& img, 00119 const std::string suffix = ".final.txt", 00120 const int frameOffset = 0); 00121 //! Save Attention Gate stats if requested 00122 virtual void saveAGMaskStats(const Image<float> &img, 00123 const std::string caller, 00124 const std::string suffix = ".final-AGmask.txt"); 00125 00126 private: 00127 std::ofstream *itsStatsFile; // file to write stats to 00128 uint itsFrameIdx; // for logging purposes 00129 uint itsSizeX, itsSizeY; // Frame image size, local copy 00130 uint itsFrameNumber; // What is the actual frame? 00131 uint itsMaskCount, itsLamCount, itsOverlapCount, itsTotalCount; 00132 00133 Image<bool> itsMask; 00134 Image<bool> itsLamMask; 00135 Image<PixRGB<byte> > itsOverlap; 00136 Image<PixRGB<byte> > itsVisualSegments; 00137 Image<byte> itsVisualCandidates; 00138 }; 00139 00140 00141 // ###################################################################### 00142 /* So things look consistent in everyone's emacs... */ 00143 /* Local Variables: */ 00144 /* mode: c++ */ 00145 /* indent-tabs-mode: nil */ 00146 /* End: */ 00147 00148 #endif // NEURO_SIMULATIONVIEWERSTATS_H_DEFINED