IntegerSimpleChannel.H

Go to the documentation of this file.
00001 /*!@file Channels/IntegerSimpleChannel.H IntegerSimpleChannel is like SingleChannel, but avoids floating-point arithmetic */
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/Channels/IntegerSimpleChannel.H $
00035 // $Id: IntegerSimpleChannel.H 10983 2009-03-05 07:19:14Z itti $
00036 //
00037 
00038 #ifndef CHANNELS_INTEGERSIMPLECHANNEL_H_DEFINED
00039 #define CHANNELS_INTEGERSIMPLECHANNEL_H_DEFINED
00040 
00041 #include "Channels/ChannelFacet.H"
00042 #include "Channels/IntegerChannel.H"
00043 #include "Component/ModelParam.H"
00044 #include "Image/ImageSet.H"
00045 #include "Image/LevelSpec.H"
00046 #include "Image/PyrBuilder.H"
00047 #include "Image/fancynorm.H" // for MaxNormType
00048 #include "Util/SimTime.H"
00049 #include "rutz/shared_ptr.h"
00050 #include <deque>
00051 
00052 // ######################################################################
00053 //! IntegerSimpleChannel is like SingleChannel, but avoids floating-point arithmetic
00054 class IntegerSimpleChannel : public IntegerChannel, public ChannelFacetMap
00055 {
00056 public:
00057   //! Constructor. See ChannelBase.H
00058   /*! @param mgr our ModelManager (see ModelManager.H)
00059       @param descrName descriptive name for human usage
00060       @param tagName name for ParamMap usage
00061       @param vs The VisualFeature implemented by the channel
00062       @param pyr The type of pyramid that should be used. */
00063   IntegerSimpleChannel(OptionManager& mgr, const std::string& descrName,
00064                        const std::string& tagName, const VisualFeature vs,
00065                        rutz::shared_ptr<PyrBuilder<int> > pyr,
00066                        nub::ref<IntegerMathEngine> eng);
00067 
00068   //! destructor
00069   virtual ~IntegerSimpleChannel();
00070 
00071   //! Reset IntegerSimpleChannel
00072   /*! See the base function in ModelComponent.H for info. */
00073   virtual void reset1();
00074 
00075   virtual void readFrom(const ParamMap& pmap);
00076 
00077   virtual void writeTo(ParamMap& pmap) const;
00078 
00079   virtual bool outputAvailable() const;
00080 
00081   virtual Dims getMapDims() const;
00082 
00083   virtual uint numSubmaps() const;
00084 
00085   virtual Image<int> getSubmapInt(const uint index) const;
00086 
00087   virtual Image<float> getSubmap(const uint index) const
00088   { return Image<float>(getSubmapInt(index)); }
00089 
00090   virtual std::string getSubmapName(const uint index) const;
00091 
00092   virtual std::string getSubmapNameShort(const uint index) const;
00093 
00094   virtual void getFeatures(const Point2D<int>& locn,
00095                            std::vector<float>& mean) const;
00096 
00097   virtual void getFeaturesBatch(std::vector<Point2D<int>*> *locn,
00098                                 std::vector<std::vector<float> > *mean,
00099                                 int *count) const;
00100 
00101   virtual Image<int> getOutputInt();
00102 
00103   //! This is just a caching wrapper around combineSubMaps()
00104   virtual Image<float> getOutput()
00105   { return Image<float>(getOutputInt()); }
00106 
00107   //! Save our various maps using an FrameOstream
00108   /*! Depending on our ModelParam settings, we can save raw pyramid
00109     levels (with name prefix "SR<tagname>-<level>-"), center-surround
00110     feature maps ("SF<tagname>-<ctr>-<surr>-"), and output map
00111     ("SO<tagname>-") */
00112   virtual void saveResults(const nub::ref<FrameOstream>& ofs);
00113 
00114   //! get our the LevelSpec
00115   LevelSpec getLevelSpec() const;
00116 
00117   //! IntegerSimpleChannel implements this to clear its cached output.
00118   virtual void killCaches();
00119 
00120   //! get raw CS map; part of getSubmap()
00121   virtual Image<float> getRawCSmap(const uint idx) const
00122   { return Image<float>(getRawCSmapInt(idx)); }
00123 
00124   //! get raw CS map; part of getSubmap()
00125   virtual Image<int> getRawCSmapInt(const uint idx) const;
00126 
00127   void setTakeAbs(bool val) { itsTakeAbs.setVal(val); }
00128 
00129   void setNormalizeOutput(bool val) { itsNormalizeOutput.setVal(val); }
00130 
00131   const ImageSet<int>& intgPyramid() { return itsPyr; }
00132 
00133   int getMinPyrLevel() const
00134   {
00135     // If we want to save our raw pyramid maps, then let's compute the
00136     // pyramid in full; otherwise, we can skip the levels below our
00137     // LevelSpec's levMin():
00138     return itsSaveRawMaps.getVal() ? 0 : itsLevelSpec.getVal().levMin();
00139   }
00140 
00141   int getMaxPyrLevel() const { return itsLevelSpec.getVal().maxDepth(); }
00142 
00143   /// Install a new PyrBuilder object
00144   void setPyrBuilder(rutz::shared_ptr<PyrBuilder<int> > pbuild);
00145 
00146 protected:
00147 
00148   virtual void doInputInt(const IntegerInput& inp,
00149                           const SimTime& t,
00150                           PyramidCache<int>* cache,
00151                           const Image<byte>& clipMask);
00152 
00153   NModelParam<bool> itsTakeAbs;
00154   NModelParam<bool> itsNormalizeOutput;
00155   NModelParam<bool> itsScaleNoiseToMax;
00156   NModelParam<int> itsLowThresh;
00157   NModelParam<bool> itsRectifyPyramid;
00158   OModelParam<bool> itsUseRandom;
00159   OModelParam<LevelSpec> itsLevelSpec;
00160   OModelParam<MaxNormType> itsNormType;
00161   OModelParam<int> itsQlen;
00162   OModelParam<bool> itsUseOlderVersion;
00163 
00164   //! Save our raw pyramid levels?
00165   OModelParam<bool> itsSaveRawMaps;
00166 
00167   //! Save our center-surround feature maps?
00168   OModelParam<bool> itsSaveFeatureMaps;
00169 
00170   //! Save our output map?
00171   OModelParam<bool> itsSaveOutputMap;
00172 
00173   //! Set a fixed range of values for the raw output
00174   /*! By default, the range is set to [MAXNORMMIN .. MAXNORMMAX] at
00175     construction. If non-zero values are provided here, in getOutput()
00176     we will cumulate our various submaps, apply the provided range,
00177     apply spatial competition for salience, apply our total weight,
00178     and return the result. If a range [0.0 .. 0.0] is provided here,
00179     only spatial competition and weights will be applied, but the
00180     first step of applying the range will be skipped. This must be
00181     called before start(). */
00182   OModelParam<int> itsOutputRangeMin;
00183   OModelParam<int> itsOutputRangeMax;
00184 
00185   /// get us started (see ModelComponent.H)
00186   /*! If you overload this, make sure you call IntegerSimpleChannel::start1()
00187     at the beginning of your overload */
00188   virtual void start1();
00189 
00190   /// get us stopped (see ModelComponent.H)
00191   /*! If you overload this, make sure you call IntegerSimpleChannel::start1()
00192     at the beginning of your overload */
00193   virtual void stop2();
00194 
00195   /// shortcut to the csToIndex function of itsLevelSpec:
00196   /*! If you overload this, make sure you call IntegerSimpleChannel::stop1()
00197     at the beginning of your overload */
00198   uint csToIndex(uint centerlev, uint surroundlev) const;
00199 
00200 private:
00201   IntegerSimpleChannel(const IntegerSimpleChannel&); // not allowed
00202   IntegerSimpleChannel& operator=(const IntegerSimpleChannel&); // not allowed
00203 
00204   ImageSet<int>                  itsPyr;
00205   SimTime                        itsT;
00206   Image<int>                     itsOutputCache;
00207   Image<int>*                    itsSubmapCache;
00208   rutz::shared_ptr<PyrBuilder<int> >  itsPyrBuilder;
00209   ImageSet<int>                  itsClipPyr;
00210 };
00211 
00212 // ######################################################################
00213 /* So things look consistent in everyone's emacs... */
00214 /* Local Variables: */
00215 /* mode: c++ */
00216 /* indent-tabs-mode: nil */
00217 /* End: */
00218 
00219 #endif // CHANNELS_INTEGERSIMPLECHANNEL_H_DEFINED
Generated on Sun May 8 08:04:41 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3