DirectionSpatioTemporalChannel.C

Go to the documentation of this file.
00001 /*!@file Channels/DirectionSpatioTemporalChannel.C */
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:
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Channels/DirectionSpatioTemporalChannel.C $
00035 // $Id:$
00036 //
00037 
00038 #ifndef DIRECTIONSPATIOTEMPORALCHANNEL_C_DEFINED
00039 #define DIRECTIONSPATIOTEMPORALCHANNEL_C_DEFINED
00040 
00041 #include "Channels/DirectionSpatioTemporalChannel.H"
00042 
00043 #include "Channels/ChannelOpts.H"
00044 #include "Component/OptionManager.H"
00045 #include "Image/ImageSetOps.H"
00046 #include "Image/MathOps.H"
00047 #include "Util/sformat.H"
00048 #include "rutz/compat_cmath.h" // for M_PI
00049 #include "rutz/trace.h"
00050 #include "Raster/Raster.H"
00051 #include "Image/ShapeOps.H"
00052 
00053 
00054 // ######################################################################
00055 // DirectionSpatioTemporalChannel member definitions:
00056 // ######################################################################
00057 
00058 // ######################################################################
00059 DirectionSpatioTemporalChannel::DirectionSpatioTemporalChannel
00060 (OptionManager& mgr, 
00061  const uint dirIndex, 
00062  const uint speedIndex,
00063  const double direction, 
00064  const double speed,
00065  const PyramidType type):
00066   SingleChannel(mgr, "", "", MOTIONSPATIOTEMPORAL,
00067                 rutz::make_shared
00068                 (new SpatioTemporalEnergyPyrBuilder<float>
00069                  (Oriented5, direction, speed))), //itsNumPyrLevels
00070   itsDirIndex("DirectionChannelDirectionIndex", this, dirIndex),
00071   itsSpeedIndex("DirectionChannelSpeedIndex", this, speedIndex),
00072   itsDirection("DirectionChannelDirection", this, direction),
00073   itsSpeed("DirectionChannelSpeed", this, direction)
00074 {
00075   // FIXXX: how to switch to new SpatioTemporalEnergyPyrBuilder<byte>
00076   // FIXXX: what do we do with the level specs
00077 
00078 GVX_TRACE(__PRETTY_FUNCTION__);
00079   
00080   // this is because we only have 2 levels of center surround maps
00081   //mgr.setOptionValString(&OPT_LevelSpec, "0,1,0,0,4");
00082   //mgr.setOptionValString(&OPT_LevelSpec, "0,2,0,0,4"); // for depth of 3
00083   
00084   itsSpatioTemporalPyrBuilder.reset
00085     (new SpatioTemporalEnergyPyrBuilder<float>
00086      (Oriented5, direction, speed));
00087   
00088   setDescriptiveName(sformat("DirectionSpeed(%d,%f)", int(direction), speed));
00089   setTagName(sformat("dir_%d_sp_%d", dirIndex, speedIndex));
00090 }
00091 
00092 // ######################################################################
00093 void DirectionSpatioTemporalChannel::start1()
00094 {
00095 GVX_TRACE(__PRETTY_FUNCTION__);
00096  itsLevelSpec.setVal(LevelSpec(0,1,0,0,4) );  //.levMin();
00097  SingleChannel::start1();
00098 }
00099 
00100 // ######################################################################
00101 void DirectionSpatioTemporalChannel::start2()
00102 {
00103 GVX_TRACE(__PRETTY_FUNCTION__);
00104 }
00105 
00106 // ######################################################################
00107 DirectionSpatioTemporalChannel::~DirectionSpatioTemporalChannel()
00108 {
00109 GVX_TRACE(__PRETTY_FUNCTION__);
00110 }
00111 
00112 // ######################################################################
00113 ImageSet<float> DirectionSpatioTemporalChannel::
00114 computePyramid(const Image<float>& bwimg,
00115                const rutz::shared_ptr<PyramidCache<float> >& cache)
00116 {
00117 GVX_TRACE(__PRETTY_FUNCTION__);
00118 
00119   // get the pyramid as usual:
00120   itsSpatioTemporalEnergy = 
00121     itsSpatioTemporalPyrBuilder->build(bwimg);
00122   ImageSet<float> py = itsSpatioTemporalEnergy;
00123   
00124   return py;
00125 }
00126 
00127 // ######################################################################
00128 void DirectionSpatioTemporalChannel::doInput(const InputFrame& inframe)
00129 {
00130 GVX_TRACE(__PRETTY_FUNCTION__);
00131 
00132   if (!this->started())
00133     CLFATAL("must be start()-ed before using receiving any input");
00134 
00135   ASSERT(inframe.grayFloat().initialized());  
00136 
00137   // V1: compute spatiotemporal motion detection
00138   Image<byte> image(inframe.grayFloat());
00139 
00140   setClipPyramid(inframe.clipMask());
00141   
00142   itsSpatioTemporalEnergy = 
00143     itsSpatioTemporalPyrBuilder->build(image);
00144 
00145   if(itsSpatioTemporalEnergy.size() != 0)
00146     storePyramid(itsSpatioTemporalEnergy, inframe.time());
00147 }
00148 
00149 // ######################################################################
00150 void DirectionSpatioTemporalChannel::setMTfeatureMap(Image<float> mtFeat)
00151 {
00152   itsMTfeatureMap = mtFeat;
00153 }
00154 
00155 // ######################################################################
00156 Image<float> DirectionSpatioTemporalChannel::getRawCSmap(const uint idx) const
00157 {
00158   //Image<float> res = decXY(itsMTfeatureMap);
00159   Image<float> res = downSize(itsMTfeatureMap, getMapDims());
00160   Image<float> tres = maxNormalize(res, MAXNORMMIN, MAXNORMMAX,
00161                                       itsNormType.getVal());
00162 
00163 
00164   
00165   //return tres;
00166   //return res;
00167   return itsMTfeatureMap;
00168 }
00169 
00170 // ######################################################################
00171 ImageSet<float> DirectionSpatioTemporalChannel::getSpatioTemporalEnergy()
00172 {
00173   return itsSpatioTemporalPyrBuilder->getSpatioTemporalEnergy();
00174 }
00175 
00176 // ######################################################################
00177 /* So things look consistent in everyone's emacs... */
00178 /* Local Variables: */
00179 /* indent-tabs-mode: nil */
00180 /* End: */
00181 
00182 #endif // DIRECTIONSPATIOTEMPORALCHANNEL_C_DEFINED
Generated on Sun May 8 08:40:21 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3