CudaSaliency.H

Go to the documentation of this file.
00001 /*!@file CUDA/CudaSaliency.H A class for quick-and-dirty CUDA saliency mapping */
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: Zack Gossman <gossman@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/CUDA/CudaSaliency.H $
00035 // $Id: CudaSaliency.H 13326 2010-04-27 22:02:05Z dparks $
00036 //
00037 
00038 #ifndef CUDASALIENCY_H_DEFINED
00039 #define CUDASALIENCY_H_DEFINED
00040 
00041 #include "Component/ModelComponent.H"
00042 #include "Component/ModelParam.H"
00043 #include "CUDA/CudaColorOps.H"
00044 #include "CUDA/CudaImage.H"
00045 #include "CUDA/CudaImageSet.H"
00046 #include "CUDA/CudaMathOps.H"
00047 #include "Image/DrawOps.H"
00048 #include "CUDA/CudaFilterOps.H"
00049 #include "Image/Pixels.H"
00050 #include "Image/PyramidTypes.H"
00051 
00052 #include "Util/Types.H"
00053 
00054 #include <cstdlib>
00055 #include <unistd.h>
00056 #include <list>
00057 
00058 
00059 template <class T> class CudaReichardtPyrBuilder;
00060 
00061 // ######################################################################
00062 class CudaSaliency : public ModelComponent
00063 {
00064 public:
00065 
00066   // ######################################################################
00067   /*! @name Constructors and Destructors */
00068   //@{
00069 
00070   //! Constructor
00071   CudaSaliency(OptionManager& mgr,
00072              const std::string& descrName = "CudaSaliency",
00073              const std::string& tagName = "CudaSaliency");
00074 
00075   //! Destructor
00076   ~CudaSaliency();
00077 
00078   //@}
00079 
00080   // ######################################################################
00081   /*! @name member functions */
00082   //@{
00083 
00084   virtual void paramChanged(ModelParamBase* const param,
00085                             const bool valueChanged,
00086                             ParamClient::ChangeStatus* status);
00087 
00088 
00089   //! Setup up with image to be processed and build the job queue
00090   void doInput(const Image< PixRGB<byte> > img);
00091 
00092   void doCudaInput(const CudaImage< PixRGB<float> > img);
00093 
00094   void setDevice(MemoryPolicy mp_in, int dev_in);
00095 
00096   // Clear stored maps
00097   void clearMaps();
00098 
00099   //! Is the last given input done processing?
00100   bool outputReady();
00101 
00102   //! Get last computed output
00103   Image<float> getOutput();
00104 
00105   CudaImage<float> getCudaOutput();
00106 
00107   CudaImage<float> getIMap();
00108 
00109   CudaImage<float> getCMap();
00110 
00111   CudaImage<float> getOMap();
00112 
00113   CudaImage<float> getFMap();
00114 
00115   CudaImage<float> getMMap();
00116 
00117   CudaImage<float> getInertiaMap();
00118 
00119   CudaImage<float> getInhibitionMap();
00120 
00121   std::vector<Point2D<int> > getSalMaxLoc();
00122 
00123   std::vector<float> getSalMax();
00124 
00125   double getPatchSize();
00126 
00127   //! For internal thread use: Compute a conspicuity map from an image
00128   void runSaliency();
00129 
00130   //! Calculate the pyramid and post the generated conspicuity map to the saliency output mapt
00131   CudaImage<float> cudaPostChannel(CudaImage<float> curImage, PyramidType ptyp, float orientation, float weight, CudaImage<float>& outmap);
00132 
00133   // Generate a conspicuity map from a pyramid
00134   CudaImage<float> processPyramid(CudaImageSet<float> pyr);
00135 
00136   //! Calculate intensity channel
00137   void calcIntensity(const CudaImage<PixRGB<float> > & colImage, CudaImage<float>& outmap);
00138 
00139   //! Calculate the red/green & blue/yellow color oppponent channel
00140   void calcColor(const CudaImage<PixRGB<float> > & colImage, CudaImage<float>& outmap);
00141 
00142   //! Calculate a particular orientation channel
00143   void calcOrientation(const CudaImage<PixRGB<float> > & colImage, float orientation, CudaImage<float>& outmap);
00144 
00145   //! Calculate the flicker channel
00146   void calcFlicker(const CudaImage<PixRGB<float> >& colImage, CudaImage<float>& outmap);
00147 
00148   //! Calculate the motion channel
00149   void calcMotion(const CudaImage<PixRGB<float> > & colImage, int motionIndex);
00150 
00151   //! Calculate inhibition of return on the saliency map
00152   void calcInhibition(const CudaImage<float> & salMap);
00153 
00154   //! Calculate inertia on the saliency map
00155   void calcInertia(const CudaImage<float> & salMap);
00156 
00157   //@}
00158 
00159 protected:
00160 
00161   void start1(); //!< get started
00162   void stop2();  //!< get stopped
00163 
00164 private:
00165   OModelParam<int> itsCudaDevice;
00166   Point2D<int> itsInertiaLoc;
00167   double itsCurrentInertiaFactor;
00168   CudaImage<float> itsInertiaMap;
00169   CudaImage<float> itsInhibitionMap;
00170   OModelParam<int> itsNMostSalientLoc;
00171   OModelParam<double> itsInertiaHalfLife;
00172   OModelParam<double> itsInertiaStrength;
00173   OModelParam<double> itsInertiaRadius;
00174   OModelParam<double> itsInertiaShiftThresh;
00175   OModelParam<double> itsIorHalfLife;
00176   OModelParam<double> itsIorStrength;
00177   OModelParam<double> itsIorRadius;
00178   OModelParam<double> itsPatchSize;
00179   double itsDynamicFactor;
00180   std::vector<Point2D<int> > itsSalMaxLoc;
00181   std::vector<float> itsSalMax;
00182   CudaImage<float> prevLum;
00183   CudaImage<float> curLum;
00184   CudaImageSet<float> curLumPyr;
00185   CudaReichardtPyrBuilder<float> *reichardtPyr;
00186   CudaImage<float> rg;
00187   CudaImage<float> by;
00188   CudaImage<float> randBuf;
00189   CudaImage<PixRGB<float> > colima;
00190   bool gotLum;
00191   bool gotRGBY;
00192   bool gotSaliency;
00193   CudaImage<float> outmap;
00194   CudaImage<float> intensityMap,colorMap,orientationMap,flickerMap,motionMap;
00195   CudaImage<float> convmap;
00196   MemoryPolicy mp;
00197   int dev;
00198   int numMotionDirs,numOrientationDirs;
00199 
00200 };
00201 
00202 #endif
00203 
00204 // ######################################################################
00205 /* So things look consistent in everyone's emacs... */
00206 /* Local Variables: */
00207 /* indent-tabs-mode: nil */
00208 /* End: */
Generated on Sun May 8 08:04:44 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3