test-hmaxRec.C

Go to the documentation of this file.
00001 /*!@file HMAX/test-hmaxRec.C aginst 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: Lior Elazary
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/HMAX/test-hmaxRec.C $
00035 // $Id: test-hmaxRec.C 9412 2008-03-10 23:10:15Z farhan $
00036 //
00037 
00038 #include "HMAX/Hmax.H"
00039 #include "Image/Image.H"
00040 #include "Image/ColorOps.H"
00041 #include "Image/MathOps.H"
00042 #include "Image/CutPaste.H"
00043 #include "Image/Transforms.H"
00044 #include "Raster/Raster.H"
00045 #include "Util/Types.H"
00046 #include "Util/log.H"
00047 #include "GUI/DebugWin.H"
00048 #include "Media/TestImages.H"
00049 
00050 #include <iostream>
00051 #include <unistd.h>
00052 
00053 // number of orientations to use in Hmax
00054 #define NORI 4
00055 
00056 int main(const int argc, const char **argv)
00057 {
00058   int debug=0;
00059   if (argc != 2)
00060     { std::cerr<<"USAGE: test-hmaxRec <file>"<<std::endl; exit(1); }
00061 
00062   // get an Hmax object:
00063   std::vector<int> scss(5);
00064   scss[0] = 0; scss[1] = 2; scss[2] = 5; scss[3] = 8; scss[4] = 12;
00065   std::vector<int> spss(4);
00066   spss[0] = 4; spss[1] = 6; spss[2] = 9; spss[3] = 12;
00067   Hmax hmax(NORI, spss, scss);
00068 
00069   const char *imageSetFile = argv[1];
00070 
00071   //load the images
00072   TestImages testImages(imageSetFile, TestImages::XMLFILE);
00073 
00074   //int numMatches = 0; //the number of correct matches
00075   int totalObjects = 0; //the number of objects presented to the network
00076 
00077   for (uint scene=0; scene<testImages.getNumScenes(); scene++) //look at all the scenes
00078   {
00079 
00080     for (uint obj=0; obj<testImages.getNumObj(scene); obj++) //look at all the objects
00081     {
00082       TestImages::ObjData objData = testImages.getObjectData(scene, obj);
00083 
00084       //crop the obj image to 256x256;
00085       Point2D<int> upperLeft(0,0);
00086 
00087       if (objData.img.getWidth() > 256 || objData.img.getHeight() > 256)
00088         upperLeft = Point2D<int>((objData.img.getWidth()/2)-128, (objData.img.getHeight()/2)-128);
00089 
00090       LINFO("Upper left %ix%i", upperLeft.i, upperLeft.j);
00091         Image<PixRGB<byte> > inputImg = crop(objData.img, upperLeft, Dims(256,256), true);
00092       //center the object
00093       if (objData.img.getWidth() < 256 || objData.img.getHeight() < 256)
00094         inputImg = shift(inputImg, 128-(objData.img.getWidth()/2), 128-(objData.img.getHeight()/2));
00095 
00096       totalObjects++;
00097 
00098       // read the image:
00099       Image<byte> input = luminance(inputImg); //convert to gray
00100 
00101       Image<PixRGB<byte> > out = toRGB(input);
00102       if(debug) SHOWIMG(out);
00103 
00104 
00105       // pass image through Hmax model:
00106       Image<float> inputf = input;   // convert image to floats
00107       Image<float> c2resp = hmax.getC2(inputf);
00108 
00109       float mi, ma; getMinMax(c2resp, mi, ma);
00110       LINFO("%ix%i min=%f max=%f", c2resp.getWidth(), c2resp.getHeight(), mi, ma);
00111 
00112       printf("%i ", objData.id);
00113       for(int i=0; i<c2resp.getWidth()*c2resp.getHeight(); i++)
00114       {
00115         printf("%i:%f ", i,c2resp[i]);
00116       }
00117       printf("\n");
00118 
00119 
00120       //use svm to classify
00121 
00122       // display C2 response in an X window:
00123       if (debug)
00124       {
00125         c2resp = scaleBlock(c2resp, input.getDims());
00126 
00127         inplaceNormalize(c2resp, 0.0F, 255.0F);
00128         SHOWIMG(c2resp);
00129       }
00130     }
00131   }
00132 
00133   return 0;
00134 }
00135 
00136 // ######################################################################
00137 /* So things look consistent in everyone's emacs... */
00138 /* Local Variables: */
00139 /* indent-tabs-mode: nil */
00140 /* End: */
Generated on Sun May 8 08:40:41 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3