test-covEstimate.C

Go to the documentation of this file.
00001 /*!@file VFAT/test-covEstimate.C quick estimator for coveriance matrix
00002  */
00003 
00004 // //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00006 // University of Southern California (USC) and the iLab at USC.         //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: T Nathan Mundhenk <mundhenk@usc.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/VFAT/test-covEstimate.C $
00036 // $Id: test-covEstimate.C 6191 2006-02-01 23:56:12Z rjpeters $
00037 //
00038 
00039 // ############################################################
00040 // ############################################################
00041 // ##### ---NPclassify---
00042 // ##### non-parametric classifier:
00043 // ##### T. Nathan Mundhenk nathan@mundhenk.com
00044 // ##### Vidhya Navalpakkam - navalpak@usc.edu
00045 // ##### partners full name - email
00046 // ############################################################
00047 // ############################################################
00048 //This is the start of the execution path for the test alg.
00049 
00050 #define TYPE float
00051 
00052 #include "Raster/Raster.H"
00053 #include "Util/Timer.H"
00054 #include "Util/log.H"
00055 #include "Util/readConfig.H"
00056 #include "VFAT/covEstimate.H"
00057 #include <stdlib.h>
00058 #include <sys/types.h>
00059 
00060 //! This is the configFile name
00061 char* configFile;
00062 //! This is the configFile object
00063 //readConfig configIn(25);
00064 //! generic pixel
00065 PixRGB<float> pix;
00066 //! number of items if training
00067 int itemNumber;
00068 
00069 int main(int argc, char* argv[])
00070 {
00071   // get test image
00072   Image<byte> input = Raster::ReadGray(argv[1]);
00073   Image<float> finput = input;
00074 
00075 
00076   // create operating objects
00077   //configIn.openFile("NPclassify.conf");
00078   // convert test image to vector format
00079   LINFO("COUNTING SAMPLES");
00080   int vCount = 0;
00081   for(int x = 0; x < finput.getWidth(); x++)
00082   {
00083     for(int y = 0; y < finput.getHeight();y++)
00084     {
00085       if(finput.getVal(x,y) < 1.0F)
00086       {
00087         // find sample size from image
00088         vCount++;
00089       }
00090     }
00091   }
00092 
00093   std::vector<TYPE> _vinput(vCount,0);
00094   TYPE t = 0.0F;
00095   TYPE* tfloat = &t;
00096   std::vector<TYPE*> _vTinput(vCount,tfloat);
00097   std::vector<std::vector<TYPE> > vinput(2,_vinput);
00098   std::vector<std::vector<TYPE*> > vinputP(2,_vTinput);
00099   std::vector<std::vector<TYPE> > voutput(2,_vinput);
00100 
00101   LINFO("ASSEMBLING SAMPLE VECTOR SIZE %"ZU,vinput[0].size());
00102   vCount = 0;
00103   for(int x = 0; x < finput.getWidth(); x++)
00104   {
00105     for(int y = 0; y < finput.getHeight();y++)
00106     {
00107       if(finput.getVal(x,y) < 1.0F)
00108       {
00109         // insert x and y into vector
00110         vinput[0][vCount] =  255-x;
00111         vinputP[0][vCount] = &vinput[0][vCount];
00112         vinput[1][vCount] =  y;
00113         vinputP[1][vCount] = &vinput[1][vCount];
00114         vCount++;
00115       }
00116     }
00117   }
00118 
00119   LINFO("RUNNING COVESTIMATE");
00120   Timer tim;
00121   tim.reset();
00122   int t1,t2;
00123   int t0 = tim.get();  // to measure display time
00124   covHolder<TYPE> chold;
00125   chold.resize(2,vCount,0.0F);
00126 
00127   covEstimate<TYPE> CE(vinputP,chold);
00128   t1 = tim.get();
00129   t2 = t1 - t0;
00130   std::cout << ">\t(0) TIME: " << t2 << "ms\n";
00131   //CE.printDebug();
00132   t1 = tim.get();
00133   t2 = t1 - t0;
00134   std::cout << ">\tTIME: " << t2 << "ms\n";
00135 
00136   // (1) find mean value (centroid) in matrix
00137   CE.run();
00138 
00139   t1 = tim.get();
00140   t2 = t1 - t0;
00141   std::cout << ">\tTIME: " << t2 << "ms\n";
00142   Image<float> final = CE.returnCovSlice(0,1,300);
00143   //Raster::VisuFloat(translate,0,sformat("translate-%s.pgm",argv[1]));
00144   //Raster::VisuFloat(rotate,0,sformat("rotate-%s.pgm",argv[1]));
00145   Raster::VisuFloat(final,0,sformat("final-%s.pgm",argv[1]));
00146 };
00147 
00148 
Generated on Sun May 8 08:42:36 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3