CudaHmax.H

Go to the documentation of this file.
00001 /*!@file CUDA/CudaHmax.H Riesenhuber & Poggio's HMAX model for object recognition */
00002 
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: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/CUDA/CudaHmax.H $
00035 // $Id: CudaHmax.H 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #ifndef CUDAHMAX_H_DEFINED
00039 #define CUDAHMAX_H_DEFINED
00040 
00041 #include "CUDA/CudaImage.H"
00042 #include <vector>
00043 
00044 #include <cmath>
00045 #include <string>
00046 #include <vector>
00047 #include <dirent.h>
00048 
00049 //! Object recognition model inspired from Riesenhuber & Poggio's HMAX model
00050 /*! See Riesenhuber & Poggio, Nature Neuroscience, 1999.
00051  */
00052 
00053 class CudaHmax {
00054 public:
00055   //! Default constructor. Need to call init() later.
00056   CudaHmax();
00057 
00058   //! Constructor
00059   CudaHmax(MemoryPolicy mp, int dev, const int nori, const std::vector<int>& spacess,
00060        const std::vector<int>& scaless, const int c1spaceol = 2,
00061        const bool angleflag = true, const float s2t = 1.0F,
00062        const float s2s = 1.0F, const float stdmin = 1.75F,
00063        const float stdstep = 0.5F, const int fsmin = 3, const int fsstep = 1);
00064 
00065   //! Initialization
00066   void init(MemoryPolicy mp, int dev, const int nori, const std::vector<int>& spacess,
00067             const std::vector<int>& scaless, const int c1spaceol = 2,
00068             const bool angleflag = true, const float s2t = 1.0F,
00069             const float s2s = 1.0F);
00070 
00071   void initFilters(const float stdmin, const float stdstep, const int fsmin, const int fsstep);
00072 
00073 
00074   //! Free internal memory
00075   void freeMem();
00076 
00077   //! Destructor
00078   ~CudaHmax();
00079 
00080   //! For utilize the operation : read a directory and pass the list of files
00081   std::vector<std::string> readDir(std::string dirName);
00082   std::vector<std::string> readList(std::string inName);
00083 
00084   //! Compute C2 responses from an input image
00085   CudaImage<float> getC2(const CudaImage<float>& input);
00086   void initC1(CudaImage<float> **&c1Res);
00087   void clearC1(CudaImage<float> **&c1Res);
00088   void printCorners(const char name[], const CudaImage<float>& cim, bool cond);
00089   void writeOutImage(const CudaImage<float>& cim,std::string & fName);
00090   // Calculate just the C1 level (must be public if you need to learn patches)
00091   void getC1(const CudaImage<float>& input, CudaImage<float>**& c1Res);
00092   void sumFilter(const CudaImage<float>& image, const float radius, CudaImage<float>& newImage);
00093   void sumFilter(const CudaImage<float>& image, const Rectangle& support, CudaImage<float>& newImage);
00094 
00095 protected:
00096   bool initialized; //!< keep track of whether we have allocated some memory
00097   int nsb; //!< number of scale bands
00098   int ns;  //!< number of scales
00099   int no;  //!< number of orientations
00100   CudaImage<float> **filter; //!< low-level processing filters [ns][no]
00101   MemoryPolicy itsMp;
00102   int itsDev;
00103 
00104   int c1SpaceOL;  //!< spatial overlap in C1 cells
00105   bool angleFlag; //!< normalize convolution by image energy if true
00106   float s2Target; //!< center of S2 target
00107   float s2Sigma;  //!< size of S2 target
00108 
00109   std::vector<int> spaceSS;
00110   std::vector<int> scaleSS;
00111 };
00112 
00113 #endif
00114 
00115 // ######################################################################
00116 /* So things look consistent in everyone's emacs... */
00117 /* Local Variables: */
00118 /* indent-tabs-mode: nil */
00119 /* End: */
Generated on Sun May 8 08:04:43 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3