HmaxFL.H

Go to the documentation of this file.
00001 /*!@file HMAX/HmaxFL.H Modified from T. Serre's HMAX model with feature learning  */
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/HMAX/HmaxFL.H $
00035 // $Id: HmaxFL.H 14139 2010-10-16 02:11:21Z dparks $
00036 //
00037 
00038 #ifndef HMAXFL_H_DEFINED
00039 #define HMAXFL_H_DEFINED
00040 
00041 #include "Image/Image.H"
00042 #include "HMAX/Hmax.H"
00043 #include <vector>
00044 
00045 #include <cmath>
00046 #include <string>
00047 #include <vector>
00048 #include <dirent.h>
00049 
00050 #define C1_PATCH_FILE_NAME "C1Patches"
00051 
00052 //! Object recognition model inspired from Riesenhuber & Poggio's HMAX model
00053 /*! See Riesenhuber & Poggio, Nature Neuroscience, 1999.
00054  */
00055 
00056 class HmaxFL : public Hmax {
00057 public:
00058   //! Default constructor. Need to call init() later.
00059   HmaxFL();
00060 
00061   //! Constructor
00062   HmaxFL(const int nori, const std::vector<int>& spacess,
00063          const std::vector<int>& scaless, const int c1spaceol = 2,
00064          const bool angleflag = true, const float s2t = 1.0F,
00065          const float s2s = 1.0F, const float gamma = 0.3F, const float divstart = 4.05F,
00066          const float divstep = -0.05F, const int fsmin = 5, const int fsstep = 2);
00067 
00068   //! Initialization
00069   void init(const int nori, const std::vector<int>& spacess,
00070             const std::vector<int>& scaless, const int c1spaceol = 2,
00071             const bool angleflag = true, const float s2t = 1.0F,
00072             const float s2s = 1.0F, const float gamma = 0.3F, const float divstart = 4.05F,
00073             const float divstep = -0.05F, const int fsmin = 5, const int fsstep = 2);
00074 
00075   void initFilters(const float gamma, const float divstart, const float divstep, const int fsmin , const int fsstep);
00076 
00077   //! Free internal memory
00078   void freeMem();
00079   void freeC1Patches();
00080 
00081   //! Destructor
00082   ~HmaxFL();
00083 
00084   //! Compute C2 responses from an input image
00085   void getC2(const Image<float>& input, float**& c2Res);
00086 
00087   //! Randomly extract a set of C1Patches from positive training images
00088   void extractRandC1Patch(std::string dirname, Image<float> & image, int index, std::vector<int> patchSizes);
00089   void extractRandC1Patches(std::string dirname, Image<float> *& posTrainingImages, int numPosTrainImages, std::vector<int> patchSizes, int nPatchesPerSize);
00090 
00091   //! Set the c1patches that should be used
00092   void setC1Patches(Image<float>***&patches,std::vector<int> patchSizes,int numPatchesPerSize);
00093   void readInC1Patches(std::string fileName);
00094   void writeOutC1Patch(std::string dirName, Image<float>& patch, int i, int j,int k);
00095   void writeOutC1Patches(std::string dirName);
00096   std::vector<int> getC1PatchSizes();
00097   int getC1PatchesPerSize();
00098 
00099   //! Get the c1patches that are being used
00100   Image<float>***& getC1Patches();
00101 
00102   //! Calculate the distance from a patch to an image
00103   void windowedPatchDistance(Image <float>*& images, int nimages, Image <float> * &patches, int npatches, Image<float>& D);
00104 
00105 
00106 protected:
00107   int nswb; //!< number of scales within a scale band
00108   Image<float> ***c1Patches; //!< patches that should be compared in S2 activation c1Patches[patchSizes][patchesPerSize]
00109   std::vector<int> c1PatchSizes; //!< Number of square patch sizes of c1Patches
00110   int nC1PatchesPerSize; //!< Number of patches per patch size of c1Patches
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:40:41 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3