SpatioTemporalEnergy.H

00001 /*!@file Robots/Beobot2/Navigation/FOE_Navigation/SpatioTemporalEnergy.C
00002   detect motion in an image stream */
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: Christian Siagian <siagian@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/Beobot2/Navigation/FOE_Navigation/SpatioTemporalEnergy.C $
00035 // $Id: SpatioTemporalEnergy.H 8429 2007-05-25 18:29:40Z rjpeters $
00036 //
00037 
00038 #ifndef BEOBOT2_SPATIOTEMPORAL_ENERGY_H
00039 #define BEOBOT2_SPATIOTEMPORAL_ENERGY_H
00040 
00041 #include "Image/PyramidOps.H"
00042 #include "Image/Image.H"
00043 #include "Image/ImageSet.H"
00044 #include "Image/DrawOps.H"
00045 #include "Image/PyramidTypes.H"
00046 #include "Image/PyrBuilder.H"
00047 #include "Image/MathOps.H"
00048 #include "GUI/XWinManaged.H"
00049 
00050 #include <math.h>
00051 
00052 // ######################################################################
00053 //! This class implements Spatiotemporal Energy motion detections
00054 /*! The class uses the filter results of pyramids of other types
00055   to implement Spatiotemporal Energy motion detection. The motion is extracted
00056   by finding edge orientations in the time and space domain. The edge
00057   orientation are computed using sobel edge dectors. */
00058 
00059 template <class T>
00060 class SpatioTemporalEnergyPyrBuilder : public PyrBuilder<T>
00061 {
00062 public:
00063   // ######################################################################
00064   // #### Constructors
00065   // ######################################################################
00066   SpatioTemporalEnergyPyrBuilder(const PyramidType typ,
00067                                  const float gabor_theta    = 0.0F,
00068                                  const float speed          = 1.0F,
00069                                  const uint  depth          = 2,
00070                                  const int   timeDomainSize = 5);
00071 
00072   //! default copy constructor and assignment are okay
00073   //! std::vector and std::deque handle the copying of the individual images
00074 
00075   //! cloning constructor
00076   virtual SpatioTemporalEnergyPyrBuilder<T>* clone() const;
00077 
00078   //! Builds a Motion Energy pyramid based on a image
00079   virtual ImageSet<T> build(const Image<T>& image,
00080                             const int firstlevel   = 0,
00081                             const int depth        = 0,
00082                             PyramidCache<T>* cache = 0);
00083 
00084   Image<float>    buildMotion(int scale);
00085   //Image<float>    
00086   //buildMotion(int scale, uint spatialShift, uint temporalShift);
00087 
00088   ImageSet<float> getOptimalShift();
00089 
00090   //! reset the stored queues - overrides PyrBuilder<T>::reset()
00091   virtual void reset();
00092 
00093   //! show the motion image as vectors (use for debuging)
00094   //! return the average motion
00095   float DrawVectors(Image<T> &img, Image<float> &motion);
00096 
00097   //! get the spatiotemporal energy map
00098   ImageSet<float> getSpatioTemporalEnergy();
00099 
00100 private:
00101 
00102   //! get the motion from the image by using sobel grad detector
00103   //! to detect edge orientations in the space and time
00104   void getMotion(const Image<T> &img, Image<float> &motion, int y_pos);
00105 
00106   //! spatiotemporal filters
00107   float getSpatioTemporalVal
00108   (float cosAng, float sinAng, uint scale, uint i, uint j,
00109    uint spatialShift, uint temporalShift);
00110 
00111   float getFilterResponseVal
00112   (float dshift, float cosAng, float sinAng, uint time, uint scale,
00113    uint i, uint j, 
00114    float wm2, float wm1, float w, float wp1, float wp2);
00115 
00116   void setSpatioTemporalFilters();
00117 
00118   void print
00119   (Image<float> image, uint si, uint ei, uint sj, uint ej, float stop);
00120   void print
00121   (ImageSet<float> images, uint si, uint ei, uint sj, uint ej, float stop);
00122   void display(Image<float> image);
00123   void display(ImageSet<float> images);
00124 
00125   std::deque< ImageSet<float> > imgPyrQ;  // hold the time domain pyramid
00126   PyramidType  itsPtype;              // Gaussian, Laplacian, Gabor, etc.
00127   uint         itsDepth;              // pyramid depth  
00128   float        itsGaborAngle;         // orientation tuning for Gabor pyr
00129   float        itsSpeed;              // this is basically shifting diff/frame  
00130   float        itsGaborIntens;        // filter strength for Gabor pyr
00131   unsigned int itsTimeDomainSize;     // the number of frames to hold in imgPyrQ  
00132   float        itsMagThreshold;       // only accept mag over this threshold
00133 
00134 
00135   ImageSet<float> itsSpatioTemporalEnergy;
00136   ImageSet<float> itsSpatioTemporalEnergyOptimalShift;
00137 
00138   Image<float> itsSpatTemp0filter;
00139   Image<float> itsSpatTemp90filter;
00140   Image<float> itsSpatTemp2filter;
00141 
00142   rutz::shared_ptr<XWinManaged> itsWin;
00143 };
00144 
00145 #endif
00146 
00147 // ######################################################################
00148 /* So things look consistent in everyone's emacs... */
00149 /* Local Variables: */
00150 /* indent-tabs-mode: nil */
00151 /* End: */
Generated on Sun May 8 08:41:18 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3