00001 /*!@file Neuro/SaliencyMap.H Class declarations for saliency map class */ 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: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Neuro/SaliencyMap.H $ 00035 // $Id: SaliencyMap.H 11113 2009-04-14 07:23:37Z itti $ 00036 // 00037 00038 #ifndef SALIENCYMAP_H_DEFINED 00039 #define SALIENCYMAP_H_DEFINED 00040 00041 #include "Component/ModelComponent.H" 00042 #include "Component/ModelParam.H" 00043 #include "Image/Image.H" 00044 #include "Image/LevelSpec.H" 00045 #include "Neuro/IORtypes.H" 00046 #include "Neuro/LeakyIntegrator.H" 00047 #include "Neuro/NeuroSimEvents.H" 00048 #include "Neuro/SpatialMetrics.H" 00049 #include "Simulation/SimModule.H" 00050 #include "Simulation/SimEvents.H" 00051 #include "Util/SimTime.H" 00052 00053 class FrameOstream; 00054 class ModelManager; 00055 class SpatialMetrics; 00056 class WTAwinner; 00057 00058 // ###################################################################### 00059 //! The saliency map base class 00060 // ###################################################################### 00061 /*! This is a 2D salience map. It is just a base class with virtual 00062 function definitions. Various saliency maps are available below, 00063 which provide implementations for these virtual functions. The 00064 saliency map receives input through the input() function, and its 00065 current state (membrane potential of neurons) can be retrieved using 00066 getV(). Various inplementations will typically derive from class 00067 Image and inherit all the standard methods of class Image. */ 00068 class SaliencyMap : public SimModule 00069 { 00070 public: 00071 // ###################################################################### 00072 //! @name Constructor, destructor, and reset 00073 //@{ 00074 00075 //! Ininitialized constructor 00076 SaliencyMap(OptionManager& mgr, 00077 const std::string& descrName = "Saliency Map", 00078 const std::string& tagName = "SaliencyMap"); 00079 00080 //! Destructor 00081 virtual ~SaliencyMap(); 00082 00083 //@} 00084 00085 private: 00086 // forbid assignment and copy-construction: 00087 SaliencyMap& operator=(const SaliencyMap& sm); 00088 SaliencyMap(const SaliencyMap& sm); 00089 }; 00090 00091 // ###################################################################### 00092 //! A do-nothing stub implementation of SaliencyMap 00093 // ###################################################################### 00094 class SaliencyMapStub : public SaliencyMap 00095 { 00096 public: 00097 //! Constructor 00098 SaliencyMapStub(OptionManager& mgr, 00099 const std::string& descrName = "Saliency Map Stub", 00100 const std::string& tagName = "SaliencyMapStub"); 00101 00102 //! Destructor 00103 virtual ~SaliencyMapStub(); 00104 }; 00105 00106 // ###################################################################### 00107 //! A partial implementation of SaliencyMap for further subclasses 00108 // ###################################################################### 00109 class SaliencyMapAdapter : public SaliencyMap 00110 { 00111 public: 00112 //! Constructor 00113 SaliencyMapAdapter(OptionManager& mgr, 00114 const std::string& descrName, 00115 const std::string& tagName); 00116 00117 //! Destructor 00118 virtual ~SaliencyMapAdapter(); 00119 00120 protected: 00121 //! Callback for when a new WTA winner is available 00122 SIMCALLBACK_DECLARE(SaliencyMapAdapter, SimEventWTAwinner); 00123 00124 //! Callback for when a new data from VisualCortex is available 00125 SIMCALLBACK_DECLARE(SaliencyMapAdapter, SimEventVisualCortexOutput); 00126 00127 //! Callback for when a new eye activity is going on 00128 SIMCALLBACK_DECLARE(SaliencyMapAdapter, SimEventSaccadeStatusEye); 00129 00130 //! Callback for every time we should save our outputs 00131 SIMCALLBACK_DECLARE(SaliencyMapAdapter, SimEventSaveOutput); 00132 00133 //! metrics that depend on the input size: 00134 nub::ref<SpatialMetrics> itsMetrics; 00135 00136 //! type of IOR to use. See IORtypes.H 00137 OModelParam<IORtype> itsIORtype; 00138 00139 //! Specification of our image processing center-surround levels 00140 /*! The only thing that we care about here is the saliency map level */ 00141 OModelParam<LevelSpec> itsLevelSpec; 00142 00143 //! Save our internals? 00144 OModelParam<bool> itsSaveResults; 00145 00146 //! Save our cumulative internals when saveResults() is called? 00147 OModelParam<bool> itsSaveCumResults; 00148 00149 //! use saccadic suppression? 00150 OModelParam<bool> itsUseSaccadicSuppression; 00151 00152 //! use blink suppression? 00153 OModelParam<bool> itsUseBlinkSuppression; 00154 00155 /*! If the saliency map voltage at winning location gets higher than 00156 this (in mV), trigger some global inhibition */ 00157 OModelParam<float> itsMaxWinMv; 00158 00159 //! Cumulative map so far. Cumulates each time saveResults() is called 00160 /*! This is computed only if itsSaveCumResults() is true */ 00161 Image<float> itsCumMap; 00162 00163 //! Set new input currents for all neurons 00164 /*! This should initialize and resize the saliency map if the 00165 saliency map is currently uninitialized (e.g., just after 00166 construction or reset()). */ 00167 virtual void input(SimEventQueue& q, const Image<float>& in) = 0; 00168 00169 //! Difference-of-Gaussians inhibition of return 00170 /*! The positive Gaussian is defined by its amplitute pampl and 00171 width psdev; the negative Gaussian by mampl and msdev. Both 00172 centered at winner. */ 00173 virtual void depress(SimEventQueue& q, const Point2D<int>& winner, 00174 const double& pampl, const double& mampl, 00175 const double& psdev, const double& msdev) = 0; 00176 00177 //! Object-based inhibition of return 00178 /*! The object mask defines where in the image the inhibition will 00179 be applied. The winner coordinates and ampl are used to calibrate 00180 the inhibition strength */ 00181 virtual void depress(SimEventQueue& q, const Point2D<int>& winner, const double& ampl, 00182 const Image<byte>& objectMask) = 0; 00183 00184 //! Turn saccadic suppression on/off 00185 virtual void saccadicSuppression(SimEventQueue& q, const bool on) = 0; 00186 00187 //! Turn blink suppression on/off 00188 virtual void blinkSuppression(SimEventQueue& q, const bool on) = 0; 00189 00190 //! Return all our membrane potential voltages as an Image<float> 00191 virtual Image<float> getV() const = 0; 00192 00193 //! Access function using Point2D<int> 00194 virtual float getV(const Point2D<int>& p) const = 0; 00195 }; 00196 00197 // ###################################################################### 00198 //! The standard saliency map: a 2D array of LeakyIntegrator neurons 00199 // ###################################################################### 00200 /*! This is a 2D salience map. It is an Image<LeakyIntegrator> and 00201 inherits all the standard methods of class Image. To avoid 00202 confusion, we here add explicit input() and getV() methods (rather 00203 than providing conversion functions between LeakyIntegrator and 00204 float, which could make the process more transparent but also 00205 possibly more confusing). */ 00206 class SaliencyMapStd : public SaliencyMapAdapter 00207 { 00208 public: 00209 //! Ininitialized constructor 00210 SaliencyMapStd(OptionManager& mgr, 00211 const std::string& descrName = "Saliency Map Std", 00212 const std::string& tagName = "SaliencyMapStd"); 00213 00214 //! Destructor 00215 virtual ~SaliencyMapStd(); 00216 00217 protected: 00218 //! Callback for every clock tick, to run our diff equations in integrate() 00219 SIMCALLBACK_DECLARE(SaliencyMapStd, SimEventClockTick); 00220 00221 OModelParam<float> itsGinhDecay; //!< decay for IOR inhibition 00222 00223 //! Set new input currents for all neurons 00224 virtual void input(SimEventQueue& q, const Image<float>& in); 00225 00226 //! Difference-of-Gaussians inhibition of return 00227 virtual void depress(SimEventQueue& q, const Point2D<int>& winner, 00228 const double& pampl, const double& mampl, 00229 const double& psdev, const double& msdev); 00230 00231 //! Object-based inhibition of return 00232 virtual void depress(SimEventQueue& q, const Point2D<int>& winner, const double& ampl, 00233 const Image<byte>& objectMask); 00234 00235 //! Turn saccadic suppression on/off 00236 virtual void saccadicSuppression(SimEventQueue& q, const bool on); 00237 00238 //! Turn blink suppression on/off 00239 virtual void blinkSuppression(SimEventQueue& q, const bool on); 00240 00241 //! Return all our membrane potential voltages as an Image<float> 00242 virtual Image<float> getV() const; 00243 00244 //! Access function using Point2D<int> 00245 virtual float getV(const Point2D<int>& p) const; 00246 00247 //! Reset to initial state just after construction 00248 virtual void reset1(); 00249 00250 private: 00251 Image<LeakyIntegrator> itsNeurons; 00252 }; 00253 00254 // ###################################################################### 00255 //! The trivial saliency map: a 2D array of floats 00256 // ###################################################################### 00257 /*! This is a 2D salience map. It is an Image<float> and inherits all 00258 the standard methods of class Image. To avoid confusion, we here add 00259 explicit input() and getV() methods. */ 00260 class SaliencyMapTrivial : public SaliencyMapAdapter 00261 { 00262 public: 00263 //! Ininitialized constructor 00264 /*! The SM will be resized and initialized the first time input() is 00265 called */ 00266 SaliencyMapTrivial(OptionManager& mgr, 00267 const std::string& descrName = "Saliency Map Trivial", 00268 const std::string& tagName = "SaliencyMapTrivial"); 00269 00270 //! Destructor 00271 virtual ~SaliencyMapTrivial(); 00272 00273 protected: 00274 //! Coeff to go from current inputs to voltage outputs 00275 OModelParam<float> itsItoVcoeff; 00276 00277 //! Set new input currents for all neurons 00278 virtual void input(SimEventQueue& q, const Image<float>& in); 00279 00280 //! Difference-of-Gaussians inhibition of return 00281 virtual void depress(SimEventQueue& q, const Point2D<int>& winner, 00282 const double& pampl, const double& mampl, 00283 const double& psdev, const double& msdev); 00284 00285 //! Object-based inhibition of return 00286 virtual void depress(SimEventQueue& q, const Point2D<int>& winner, const double& ampl, 00287 const Image<byte>& objectMask); 00288 00289 //! Turn saccadic suppression on/off 00290 virtual void saccadicSuppression(SimEventQueue& q, const bool on); 00291 00292 //! Turn blink suppression on/off 00293 virtual void blinkSuppression(SimEventQueue& q, const bool on); 00294 00295 //! Return all our membrane potential voltages as an Image<float> 00296 virtual Image<float> getV() const; 00297 00298 //! Access function using Point2D<int> 00299 virtual float getV(const Point2D<int>& p) const; 00300 00301 //! Reset to initial state just after construction 00302 virtual void reset1(); 00303 00304 private: 00305 Image<float> itsNeurons; 00306 }; 00307 00308 // ###################################################################### 00309 //! The fast saliency map: a 2D array of floats 00310 // ###################################################################### 00311 /*! This is a 2D salience map. It is an Image<float> and inherits all 00312 the standard methods of class Image. To avoid confusion, we here add 00313 explicit input() and getV() methods. */ 00314 class SaliencyMapFast : public SaliencyMapAdapter 00315 { 00316 public: 00317 //! Ininitialized constructor 00318 SaliencyMapFast(OptionManager& mgr, 00319 const std::string& descrName = "Saliency Map Fast", 00320 const std::string& tagName = "SaliencyMapFast"); 00321 00322 //! Destructor 00323 virtual ~SaliencyMapFast(); 00324 00325 protected: 00326 //! Simulation time step, in seconds 00327 OModelParam<SimTime> itsTimeStep; 00328 00329 //! Coeff by which new inputs replace the current SM at each time step (0..1) 00330 OModelParam<float> itsInputCoeff; 00331 00332 //! Coeff to go from current inputs to voltage outputs 00333 OModelParam<float> itsItoVcoeff; 00334 00335 //! Set new input currents for all neurons 00336 virtual void input(SimEventQueue& q, const Image<float>& in); 00337 00338 //! Difference-of-Gaussians inhibition of return 00339 virtual void depress(SimEventQueue& q, const Point2D<int>& winner, 00340 const double& pampl, const double& mampl, 00341 const double& psdev, const double& msdev); 00342 00343 //! Object-based inhibition of return 00344 virtual void depress(SimEventQueue& q, const Point2D<int>& winner, const double& ampl, 00345 const Image<byte>& objectMask); 00346 00347 //! Integrate our neurons for one time step 00348 virtual void integrate(SimEventQueue& q); 00349 00350 //! Turn saccadic suppression on/off 00351 virtual void saccadicSuppression(SimEventQueue& q, const bool on); 00352 00353 //! Turn blink suppression on/off 00354 virtual void blinkSuppression(SimEventQueue& q, const bool on); 00355 00356 //! Return all our membrane potential voltages as an Image<float> 00357 virtual Image<float> getV() const; 00358 00359 //! Access function using Point2D<int> 00360 virtual float getV(const Point2D<int>& p) const; 00361 00362 //! Reset to initial state just after construction 00363 virtual void reset1(); 00364 00365 private: 00366 Image<float> itsNeurons; 00367 Image<float> itsInputCopy; // copy of inputs 00368 SimTime itsT; // keep track of time 00369 }; 00370 00371 #endif 00372 00373 // ###################################################################### 00374 /* So things look consistent in everyone's emacs... */ 00375 /* Local Variables: */ 00376 /* indent-tabs-mode: nil */ 00377 /* End: */