SurpriseMapFFT.H

Go to the documentation of this file.
00001 /*!@file Surprise/SurpriseMapFFT.H a surprise map */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
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/Surprise/SurpriseMapFFT.H $
00035 // $Id: SurpriseMapFFT.H 9412 2008-03-10 23:10:15Z farhan $
00036 //
00037 
00038 #ifndef SURPRISEMAPFFT_H_DEFINED
00039 #define SURPRISEMAPFFT_H_DEFINED
00040 
00041 #ifdef HAVE_FFTW3_H
00042 
00043 #define FFT_TIME_SLICE 32
00044 
00045 #include "Image/Image.H"
00046 #include "Image/ImageCache.H"
00047 #include "Surprise/SurpriseImage.H"
00048 #include "Surprise/SurpriseModel.H"
00049 #include <vector>
00050 #include <math.h>
00051 #include "Image/FFTWWrapper.H"
00052 
00053 // ######################################################################
00054 //! A Surprise Map
00055 /*! This class contains a SurpriseImage of our current models at each
00056   pixel, plus an ImageCache of SurpriseImage objects built to
00057   represent the neighborhood distributions. */
00058 template <class T>
00059 class SurpriseMapFFT
00060 {
00061 public:
00062   //! Constructor; you must call init() before using
00063   SurpriseMapFFT();
00064   //! initialization
00065   /*! @param qlen number of maps
00066     @param updatefac factor by which the current model is combined with
00067     a new model on an update. Valid values are in [0..1]
00068     @param neighupdatefac factor by which local data is combined with
00069     neighborhood models, or 0.0 to use the value of updatefac
00070     @param sampleval the value of the samples previously received.
00071     @param samplevar a variance expressing the intrinsic variability
00072     in the measurement of those samples.
00073     @param neighsigma sigma to use for the neighborhoods as a fraction of
00074     max(map width, map height)
00075     @param locsigma sigma to use for local neighborhood, in pixels */
00076   void init(const uint qlen = 1, const double updatefac = 0.7,
00077             const double neighupdatefac = 0.7,
00078             const double sampleval = 0.0, const double samplevar = 1.0,
00079             const float neighsigma = 0.5f, const float locsigma = 3.0f,
00080             const Point2D<int>& probe = Point2D<int>(-1, -1),
00081             const double slfac = 1.0, const double ssfac = 0.1,
00082             const double sfsfac = 1.0, const double sfpfac = 1.0,
00083             const std::string& descrName = "blank",
00084             const std::string& tagName = "blank");
00085 
00086   //! Virtual destructor ensures proper destruction of derived classes
00087   ~SurpriseMapFFT();
00088 
00089   //! Reset to initial state
00090   void reset();
00091 
00092   //! Update by receiving a new sample and sample measurement error
00093   /*! The returned image is the surprise (combined temporal and
00094     spatial for each map, then combined over all maps) resulting from
00095     that update */
00096   Image<double> surprise(const SurpriseImage<T>& sample,
00097                          const Image<double>& inputI,
00098                          const Image<double>& var);
00099 
00100   //! Access to underlying SurpriseImage members:
00101   const SurpriseImage<T>& getSurpriseImage(const uint index) const;
00102 
00103   //! Access to underlying SurpriseImage members for FFT spectal mag
00104   const SurpriseImage<T>& getSurpriseImageSFFT(const uint i) const;
00105   //! Access to underlying SurpriseImage members for FFT phase
00106   const SurpriseImage<T>& getSurpriseImagePFFT(const uint i) const;
00107 
00108   void setFFTModels(const SurpriseImage<T>& models,
00109                     const Image<float>& weights,
00110                     const float wmin,
00111                     std::vector<Image<double> >& sfs,
00112                     std::vector<Image<double> >& sfp);
00113 
00114 
00115 private:
00116   std::vector<SurpriseImage<T> >  itsModels;
00117   std::vector<SurpriseImage<T> >  itsFFTSModels;
00118   std::vector<SurpriseImage<T> >  itsFFTPModels;
00119   Image<double> itsVarianceImage;
00120   uint itsQlen;
00121   T itsInitialModel;
00122   float itsNeighSigma, itsLocSigma;
00123   Image<float> itsNweights;
00124   float itsNWmin;
00125   double itsNeighUpdFac;
00126   double itsVariance, itsUpdatefac;
00127   Point2D<int> itsProbe;
00128   double itsSLfac, itsSSfac,  itsSFSfac, itsSFPfac;
00129   std::string itsDescrName, itsTagName;
00130   //! Store each frame over t iterations (usually a second) for fft
00131   std::deque<Image<double> > fftStack;
00132   //! create octave bins for fft to keep model number smaller
00133   std::vector<unsigned char> fftBinSize;
00134   //! keep track of the size of fftStack, tells when to start computing fft
00135   unsigned char fftStackCount;
00136   //! how many fft octave bins do we have?
00137   unsigned char fftBins;
00138   //! when fftStackCount is the right size this is set to true
00139   bool fftStackReady;
00140   fftw_complex *in, *out;
00141   fftw_plan p;
00142   //! a basic counter for this class
00143   unsigned int itsCounter;
00144 };
00145 
00146 #endif // HAVE_FFTW3_H
00147 
00148 // ######################################################################
00149 /* So things look consistent in everyone's emacs... */
00150 /* Local Variables: */
00151 /* indent-tabs-mode: nil */
00152 /* End: */
00153 
00154 #endif
Generated on Sun May 8 08:06:53 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3