00001 /*!@file HMAX/test-hmax3.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: Daesu Chung <dchung@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/HMAX/test-hmax3.C $ 00035 // $Id: test-hmax3.C 6191 2006-02-01 23:56:12Z rjpeters $ 00036 // 00037 00038 #include "HMAX/Hmax.H" 00039 #include "Image/Image.H" 00040 #include "Image/MathOps.H" 00041 #include "Raster/Raster.H" 00042 #include "Util/Timer.H" 00043 #include "Util/Types.H" 00044 #include "Util/log.H" 00045 00046 #include <fstream> 00047 #include <iostream> 00048 00049 int tItr = 1; 00050 int c2Size = 0; 00051 int target = 0; 00052 std::string targetS1 = "tri"; 00053 std::string targetS2 = "Tri"; 00054 int imgHeight = 0; 00055 int imgWidth = 0; 00056 //int trnFlag = 0; 00057 int mixRate = 5; 00058 #define NORI 4 00059 00060 int main(int argc, char **argv) 00061 { 00062 // parse options : read directory 00063 char imname1[1024]; imname1[0] = '\0'; 00064 char imname2[1024]; imname2[0] = '\0'; 00065 strncpy(imname1, argv[1], 1023); 00066 strncpy(imname2, argv[2], 1023); 00067 //trnFlag = atoi(argv[2]); 00068 std::string inName = imname1; 00069 std::string nsName = imname2; 00070 if (argc != 3) 00071 { std::cerr<<"USAGE: test-hmax2 <dir> <trnFlag(1 or 0)>"<<std::endl; exit(1); } 00072 // weighting for IT 00073 std::ofstream c2File("c2ResSum"); 00074 Image<byte> inputImgB; Image<byte> noiseImgB; 00075 // pass image through Hmax model: 00076 std::vector<int> scss(5); 00077 scss[0] = 0; scss[1] = 2; scss[2] = 5; scss[3] = 8; scss[4] = 12; 00078 std::vector<int> spss(4); 00079 spss[0] = 4; spss[1] = 6; spss[2] = 9; spss[3] = 12; 00080 Hmax hmax(NORI, spss, scss); 00081 Timer tim; tim.reset(); 00082 00083 //read a directory for train/rest imgs. 00084 std::vector<std::string> nsList = hmax.readDir(nsName); 00085 int nsListSize = nsList.size(); 00086 Image<float> noiseImgF[nsListSize]; 00087 std::vector<std::string> inList = hmax.readDir(inName); 00088 int inListSize = inList.size(); 00089 Image<float> inputImgF[inListSize]; 00090 00091 //read the input imgs. 00092 for(int imgInd = 0; imgInd < inListSize; imgInd++) { 00093 inputImgB = Raster::ReadGray(inList[imgInd], RASFMT_PNM); 00094 inputImgF[imgInd] = inputImgB; 00095 //Raster::VisuFloat(inputImgF[imgInd], FLOAT_NORM_0_255, "inputImgF.pgm"); 00096 } 00097 00098 //read the input imgs. 00099 for(int nsInd = 0; nsInd < nsListSize; nsInd++) { 00100 noiseImgB = Raster::ReadGray(nsList[nsInd], RASFMT_PNM); 00101 noiseImgF[nsInd] = noiseImgB; 00102 //Raster::VisuFloat(inputImgF[imgInd], FLOAT_NORM_0_255, "inputImgF.pgm"); 00103 } 00104 00105 for(int nsInd = 0; nsInd < nsListSize; nsInd++) { 00106 Image<float> nsImg(noiseImgF[nsInd]); 00107 if (c2File.is_open()) 00108 c2File << std::endl <<"****** noise Image " << nsList[nsInd].c_str() << std::endl; 00109 for(int mixInd = 0; mixInd < mixRate; mixInd++) { 00110 float nsRate = mixInd * (1.0f / mixRate); 00111 if (c2File.is_open()) c2File << std::endl << "****** rate " << nsRate << std::endl; 00112 for(int imgInd = 0; imgInd < inListSize; imgInd++) { 00113 Image<float> mxImg(inputImgF[imgInd] + (nsImg * nsRate)); 00114 //Raster::VisuFloat(mxImg, FLOAT_NORM_0_255, "mxImg.pgm"); 00115 Image<float> c2Mix = hmax.origGetC2(mxImg); 00116 //Raster::VisuFloat(c2Mix, FLOAT_NORM_0_255, "c2Mix.pgm"); 00117 if (c2File.is_open()) { 00118 c2File << sum(c2Mix) << ", "; 00119 if ((imgInd+1)%10 == 0) 00120 c2File << std::endl; 00121 }//end of C2 result writing 00122 00123 }//end of imgInd 00124 }//end of mixInd 00125 }//end of nsInd 00126 00127 //Image<float> c2resp = hmax.getC2(inputf); 00128 //LDEBUG("c2Resp computed in %llums", tim.getReset()); 00129 //Image<float> oc2resp=hmax.origGetC2(inputf); 00130 //LDEBUG("original c2Resp computed in %llums", tim.get()); 00131 //Raster::VisuFloat(c2resp, FLOAT_NORM_0_255, "c2resp.pgm"); 00132 return 0; 00133 } //end of main 00134 00135 // ###################################################################### 00136 /* So things look consistent in everyone's emacs... */ 00137 /* Local Variables: */ 00138 /* indent-tabs-mode: nil */ 00139 /* End: */