DirectFeedChannel.H

Go to the documentation of this file.
00001 /*!@file Channels/DirectFeedChannel.H the source for DirectFeedChannel and
00002 MultiDirectFeedChannel */
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2002   //
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/Channels/DirectFeedChannel.H $
00035 // $Id: DirectFeedChannel.H 10746 2009-02-03 07:09:00Z itti $
00036 //
00037 
00038 #ifndef DIRECTFEEDCHANNEL_H_DEFINED
00039 #define DIRECTFEEDCHANNEL_H_DEFINED
00040 
00041 #include "Channels/ChannelBase.H"
00042 #include "Channels/ComplexChannel.H"
00043 #include "Component/ModelParam.H"
00044 #include "Image/ImageSet.H"
00045 #include "Image/fancynorm.H"
00046 #include "Util/SimTime.H"
00047 
00048 //! Direct Feed Channel
00049 class DirectFeedChannel : public ChannelBase
00050 {
00051 public:
00052 
00053   //! Constructor
00054   /*!@param id if given, becomes part of the name of the channel */
00055   DirectFeedChannel(OptionManager& mgr, int id = -1);
00056 
00057   //! Destructor
00058   virtual ~DirectFeedChannel();
00059 
00060   //! Reset SingleChannel
00061   /*! See the base function in ModelComponent.H for info. */
00062   virtual void reset1();
00063 
00064   //! Read params from the ParamMap.
00065   virtual void readFrom(const ParamMap& pmap);
00066 
00067   //! Write params to the ParamMap.
00068   virtual void writeTo(ParamMap& pmap) const;
00069 
00070   //! Clamp the weighting coefficients to the specified range.
00071   void clampCoeffs(const double cmin, const double cmax);
00072 
00073   //! Return the sum of the absolute values of the weighting coefficients.
00074   double absSumCoeffs() const;
00075 
00076   //! set coefficient idx to val
00077   void setCoeff(const uint idx, const double val);
00078 
00079   //! returns coefficient idx
00080   double getCoeff(const uint idx) const;
00081 
00082   //! Normalize the weighting coefficients by dividing by div.
00083   void normalizeCoeffs(const double div);
00084 
00085   //! initialize the coefficients to value val
00086   void initializeCoeffs(const uint numCoeffs, const double val = 1.0);
00087 
00088 
00089   //! Query whether the channel is ready to give yield valid output.
00090   /*! In some cases (e.g. with motion channels), it may take several input
00091       frames before the channel is fully initialized. */
00092   virtual bool outputAvailable() const;
00093 
00094   //! Return the dimensions of the output image.
00095   virtual Dims getMapDims() const;
00096 
00097   //! Return the number of feature maps represented by this channel.
00098   virtual uint numSubmaps() const;
00099 
00100   //! Get the feature map at the given index.
00101   /*! This function is intended to be implemented by subclasses so that it
00102       recurses into any nested channels, mapping nested submaps into a
00103       linear sequence of indices. */
00104   virtual Image<float> getSubmap(const uint index) const;
00105 
00106   //! Get the name/description of the feature map at the given index.
00107   /*! This function is intended to be implemented by subclasses so that it
00108       recurses into any nested channels, mapping nested submaps into a
00109       linear sequence of indices. The output of this function is intended
00110       only to be human-readable (e.g. for labeling image displays), and
00111       does not have to follow any particular parseable syntax. */
00112   virtual std::string getSubmapName(const uint index) const;
00113 
00114   //! not implemented
00115   virtual void getFeatures(const Point2D<int>& locn,
00116                            std::vector<float>& mean) const;
00117 
00118   //! not implemented
00119   virtual void getFeaturesBatch(std::vector<Point2D<int>*> *locn,
00120                                 std::vector<std::vector<float> > *mean,
00121                                 int *count) const;
00122 
00123   //! The output will be the size of the feature map level in the pyramid.
00124   /*! (I.e., the size of the output is given by getMapDims(). */
00125   virtual Image<float> getOutput();
00126 
00127   //! erase all internal caches
00128   virtual void killCaches();
00129 
00130   //! Send an already computed pyramid as input to the channel.
00131   /*! Must be called after each call of input.*/
00132   void inputPyramid(const ImageSet<float>& pyramid, const SimTime& t);
00133 
00134 protected:
00135   virtual void start1();
00136 
00137   //! the actual input routine
00138   /*! Only colimg or bwimg ar needed to obtain the dimensions.
00139     After each call of doinput, inputPyramid must be called.*/
00140   virtual void doInput(const InputFrame& inframe);
00141 
00142   //! computed the output of the channel
00143   virtual void computeOutput();
00144 
00145   //! applies the max norm to map depending on itsNormType
00146   virtual Image<float> applyMaxNorm(Image<float>& map);
00147 
00148   //! the level at which the saliency map lives
00149   OModelParam<uint> itsMapLevel;
00150 
00151   //! the kind of normalization to be applied
00152   OModelParam<MaxNormType> itsNormType;
00153 
00154   OModelParam<bool> itsUseOlderVersion;
00155   OModelParam<float> itsOutputRangeMin;
00156   OModelParam<float> itsOutputRangeMax;
00157 
00158 private:
00159   Dims itsMapDims;
00160   ImageSet<float> itsPyr;
00161   SimTime itsPyrTime;
00162   SimTime itsInputTime;
00163   std::vector<double> itsCoeff;
00164   Image<float> itsOutputCache;
00165 };
00166 
00167 // ######################################################################
00168 // #### MultiDirectFeedChannel
00169 // ######################################################################
00170 
00171 //! A vector of ImageSets - to be used as input to MultiDirectFeedChannel
00172 typedef std::vector< ImageSet<float> > PyrVec;
00173 
00174 //! Multi Direct Feed Channel
00175 class MultiDirectFeedChannel : public ComplexChannel
00176 {
00177 public:
00178   //! Constructor.
00179   /*! @param mgr our ModelManager (see ModelManager.H)
00180     @param num number of sub-channels */
00181   MultiDirectFeedChannel(OptionManager& mgr, uint num = 1);
00182 
00183   //! Virtual destructor.
00184   virtual ~MultiDirectFeedChannel();
00185 
00186   //! reset the number of sub-channels
00187   virtual void setNumChans(uint num);
00188 
00189   //! Send an already computed pyramid as input to the sub-channel num.
00190   void inputPyramid(uint ChanNum,
00191                             const ImageSet<float>& pyramid,
00192                             const SimTime& t);
00193 
00194   //! Send a vector of already computed pyramids as inputs to the channels.
00195   void inputPyramidVector(const PyrVec& pvec,
00196                                   const SimTime& t);
00197 
00198   //! returns sub-channel number num
00199   DirectFeedChannel& directFeed(uint num);
00200 
00201 protected:
00202   //! Combines the outputs of subchannels.
00203   virtual Image<float> combineOutputs();
00204 
00205   //! must be called with either colimg or bwimg to obtain the dims
00206   /*! After each call of input, inputPyramidVector or inputPyramid
00207     must be called.*/
00208   virtual void doInput(const InputFrame& inframe);
00209 
00210 };
00211 
00212 
00213 #endif
00214 
00215 
00216 // ######################################################################
00217 /* So things look consistent in everyone's emacs... */
00218 /* Local Variables: */
00219 /* indent-tabs-mode: nil */
00220 /* End: */
Generated on Sun May 8 08:40:21 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3