app-compare-streams.C

Go to the documentation of this file.
00001 /*!@file AppMedia/app-compare-streams.C compute correlation coefficients between two series of images */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the 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: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppMedia/app-compare-streams.C $
00035 // $Id: app-compare-streams.C 6960 2006-08-08 20:25:51Z rjpeters $
00036 //
00037 
00038 #ifndef APPMEDIA_APP_COMPARE_STREAMS_C_DEFINED
00039 #define APPMEDIA_APP_COMPARE_STREAMS_C_DEFINED
00040 
00041 #include "Image/Image.H"
00042 #include "Image/MathOps.H"
00043 #include "Image/Range.H"
00044 #include "Raster/Raster.H"
00045 #include "Util/log.H"
00046 #include <cstdio>
00047 
00048 #ifdef HAVE_FENV_H
00049 #include <fenv.h>
00050 #endif
00051 
00052 #include <string>
00053 #include <fstream>
00054 #include <vector>
00055 
00056 namespace
00057 {
00058   void readfile(const char* fname,
00059                 std::vector<std::string>& filelist)
00060   {
00061     filelist.resize(0);
00062 
00063     std::ifstream ifs(fname);
00064 
00065     if (!ifs.is_open())
00066       {
00067         LFATAL("couldn't open %s for reading", fname);
00068       }
00069 
00070     std::string line;
00071     while (std::getline(ifs, line))
00072       {
00073         filelist.push_back(line);
00074       }
00075 
00076     LINFO("read %"ZU" filenames from %s", filelist.size(), fname);
00077   }
00078 }
00079 
00080 int main(int argc, char** argv)
00081 {
00082   if (argc != 3)
00083     {
00084       printf("usage: %s filelist1 filelist2\n", argv[0]);
00085       return 1;
00086     }
00087 
00088 #ifdef HAVE_FEENABLEEXCEPT
00089   feenableexcept(FE_DIVBYZERO|FE_INVALID);
00090 #endif
00091 
00092   std::vector<std::string> filelist1;
00093   std::vector<std::string> filelist2;
00094 
00095   readfile(argv[1], filelist1);
00096   readfile(argv[2], filelist2);
00097 
00098   const size_t chunk_size = 256;
00099 
00100   for (size_t i = 0; i < filelist1.size(); i += chunk_size)
00101     {
00102       std::vector<Image<float> > images1;
00103 
00104       for (size_t ii = 0; ii < chunk_size; ++ii)
00105         {
00106           if (i+ii >= filelist1.size())
00107             break;
00108 
00109           images1.push_back(Raster::ReadFloat(filelist1[i+ii]));
00110         }
00111 
00112       for (size_t j = 0; j < filelist2.size(); j += chunk_size)
00113         {
00114           std::vector<Image<float> > images2;
00115 
00116           for (size_t jj = 0; jj < chunk_size; ++jj)
00117             {
00118               if (j+jj >= filelist2.size())
00119                 break;
00120 
00121               images2.push_back(Raster::ReadFloat(filelist2[j+jj]));
00122             }
00123 
00124           for (size_t iii = 0; iii < images1.size(); ++iii)
00125             for (size_t jjj = 0; jjj < images2.size(); ++jjj)
00126               {
00127                 const double rsq = corrcoef(images1[iii], images2[jjj]);
00128 
00129                 fprintf(stdout, "%4"ZU"  %4"ZU"  %15e\n",
00130                         i + iii, j + jjj, rsq);
00131               }
00132         }
00133     }
00134 }
00135 
00136 // ######################################################################
00137 /* So things look consistent in everyone's emacs... */
00138 /* Local Variables: */
00139 /* mode: c++ */
00140 /* indent-tabs-mode: nil */
00141 /* End: */
00142 
00143 #endif // APPMEDIA_APP_COMPARE_STREAMS_C_DEFINED
Generated on Sun May 8 08:40:07 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3