00001 /*!@file HMAX/test-hmax5.C Test Hmax class and compare to original code */ 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: Dan Parks <danielfp@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/HMAX/extractpatches.C $ 00035 // $Id: extractpatches.C 14139 2010-10-16 02:11:21Z dparks $ 00036 // 00037 00038 #include "Component/ModelManager.H" 00039 #include "GUI/XWindow.H" 00040 #include "HMAX/HmaxFL.H" 00041 #include "HMAX/Hmax.H" 00042 #include "Image/Image.H" 00043 #include "Image/CutPaste.H" 00044 #include "Image/Rectangle.H" 00045 #include "Image/MathOps.H" 00046 #include "Image/Normalize.H" 00047 #include "Image/Transforms.H" 00048 #include "Image/Convolutions.H" 00049 #include "Learn/svm.h" 00050 #include "Media/FrameSeries.H" 00051 #include "nub/ref.h" 00052 #include "Raster/GenericFrame.H" 00053 #include "Raster/Raster.H" 00054 #include "Util/Types.H" 00055 #include "Util/log.H" 00056 00057 #include <fstream> 00058 #include <iostream> 00059 #include <string> 00060 #include <unistd.h> 00061 #include <cstdlib> 00062 00063 00064 // number of orientations to use in HmaxFL 00065 #define NORI 4 00066 #define NUM_PATCHES_PER_SIZE 250 00067 00068 00069 int main(const int argc, const char **argv) 00070 { 00071 00072 MYLOGVERB = LOG_INFO; 00073 ModelManager *mgr = new ModelManager("Extract Patches for Hmax with Feature Learning"); 00074 00075 mgr->exportOptions(MC_RECURSE); 00076 00077 // required arguments 00078 // <c1patchesDir> <trainPosDir> 00079 00080 if (mgr->parseCommandLine( 00081 (const int)argc, (const char**)argv, "<c1patchesDir> <trainPosDir>", 2, 2) == false) 00082 return 1; 00083 00084 // Create a temp HmaxFL object to extract C1Patches 00085 std::vector<int> c1ScaleSS(2); 00086 c1ScaleSS[0] = 1; c1ScaleSS[1] = 3; 00087 std::vector<int> c1SpaceSS(2); 00088 c1SpaceSS[0] = 10; c1SpaceSS[1] = 11; 00089 // desired frame sizes [11 and 13] 00090 HmaxFL hmax(NORI,c1SpaceSS,c1ScaleSS,2,true,1.0F,1.0F,0.3F,4.05F,-0.05F,11,2); 00091 00092 std::string c1PatchesBaseDir; 00093 std::string trainPosName; // Directory where positive images are 00094 00095 c1PatchesBaseDir = mgr->getExtraArg(0); 00096 trainPosName = mgr->getExtraArg(1); 00097 00098 // Extract random patches from a set of images in a positive training directory 00099 std::vector<std::string> trainPos = hmax.readDir(trainPosName); 00100 int posTrainSize = trainPos.size(); 00101 00102 //Image<byte> inputb; 00103 00104 Image<float> trainPosImage; 00105 00106 std::cout << "Scanned training and testing images" << std::endl; 00107 00108 std::vector<int> pS(4); 00109 pS[0] = 4; pS[1] = 8, pS[2] = 12; pS[3] = 16; 00110 00111 std::srand(time(0)); 00112 for(int i=0;i<NUM_PATCHES_PER_SIZE;i++){ 00113 // Randomly select an image from the list 00114 unsigned int imInd = static_cast<unsigned int>(floor((rand()-1.0F)/RAND_MAX*posTrainSize)); 00115 trainPosImage = Raster::ReadFloat(trainPos[imInd]); 00116 // Learn the appropriate simple S2 patches from the C1 results 00117 hmax.extractRandC1Patch(c1PatchesBaseDir,trainPosImage,i,pS); 00118 } 00119 00120 std::cout << "Completed extraction of C1 Patches" << std::endl; 00121 00122 return 0; 00123 } 00124 00125 00126 00127 00128 // ###################################################################### 00129 /* So things look consistent in everyone's emacs... */ 00130 /* Local Variables: */ 00131 /* indent-tabs-mode: nil */ 00132 /* End: */