app-comparefixationmaps.C

00001 /*!@file AppMedia/app-comparefixationmaps.C Create small images from originals */
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: David Berg <dberg@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppEye/app-comparefixationmaps.C $
00035 
00036 #include "Image/Image.H"
00037 #include "Image/ShapeOps.H"
00038 #include "Image/MathOps.H"
00039 #include "Image/Pixels.H"
00040 #include "Raster/Raster.H"
00041 #include "Image/Convolutions.H"
00042 #include "Image/Kernels.H"
00043 #include "GUI/XWindow.H"
00044 
00045 #include <vector>
00046 #include <fstream>
00047 #include <algorithm>
00048 
00049 #define RANDITER 10000
00050 #define DISPLAY 0
00051 #define STD9 1.4364
00052 
00053 //input should be two arguments to text files of eye positions' x y\n'
00054 int main(int argc, char** argv)
00055 {
00056 
00057 const float blur1 = 1.5F*12.7F;
00058 const float blur2 = 1.5F*10.19F;
00059 
00060  srand(time(0));
00061 
00062 //load our files
00063 std::vector<Point2D<int> > randPoints;
00064 std::vector<uint> gind;
00065 uint count = 0;
00066 for (int ii=1; ii < argc-1; ii++){
00067     std::ifstream *itsRandFile = new std::ifstream(argv[ii]);
00068     if (itsRandFile->is_open() == false)
00069         LFATAL("Cannot open '%s' for reading", argv[ii]);
00070     else {
00071       while (!itsRandFile->eof())
00072         {
00073           Point2D<int> pr;
00074           (*itsRandFile) >> pr.i >> pr.j;
00075           randPoints.push_back(pr);
00076           count++;
00077         }
00078       randPoints.pop_back();    // why???
00079       gind.push_back(count - 1);  // offset -1 for ???
00080       itsRandFile->close();
00081       delete itsRandFile;
00082     }
00083 }
00084 
00085 //setup a preview window
00086  Dims dispdims(640*2,480);
00087  XWindow *prevwin;
00088  if (DISPLAY)
00089    prevwin = new XWindow(dispdims, 0, 0, "Preview"); //preview window
00090 
00091 //open an output file
00092  std::ofstream *itsOutFile = new std::ofstream(argv[argc-1]);//our output file
00093  if (itsOutFile->is_open() == false)
00094    LFATAL("Cannot open '%s' for reading",argv[argc-1]);
00095 
00096 //now we have read our files and know where our groups start and stop.
00097 //g through NUMITER and create images taking KL between them
00098 float data[RANDITER];
00099 for (uint ii = 0; ii < RANDITER; ii++){
00100     //suffle the data
00101     std::vector< Point2D<int> > rshuffle = randPoints;
00102     if (ii < RANDITER-1) //calculate original groups last
00103         std::random_shuffle(rshuffle.begin(),rshuffle.end());
00104 
00105     Image<float> im1(640,480,ZEROS);
00106     Image<float> im2(640,480,ZEROS);
00107     //image1
00108     for (uint jj=0; jj < gind[0]; jj++){
00109         im1.setVal(rshuffle[jj].i,
00110                   rshuffle[jj].j,
00111                    im1.getVal(rshuffle[jj].i,rshuffle[jj].j)+1.0F);
00112     }
00113     //image2
00114     for (uint jj=gind[0]; jj < randPoints.size(); jj++){
00115         im2.setVal(rshuffle[jj].i,
00116                   rshuffle[jj].j,
00117                    im2.getVal(rshuffle[jj].i,rshuffle[jj].j)+1.0F);
00118     }
00119 
00120 
00121     //now lets run a truncating filter over this
00122     //image1
00123     im1 += .00000001;
00124         //Image<float> kernel = binomialKernel(9);
00125         //for (uint kk = 0; kk < floor(blur1/STD9); kk++)
00126         //im1 = sepFilter(im1,kernel,kernel,CONV_BOUNDARY_CLEAN);
00127         //Image<float> kernel = gaussian<float>(0.0F,blur1,0,.1F);
00128         //im1 = sepFilter(im1,kernel,kernel,CONV_BOUNDARY_CLEAN);
00129     Image<float> filter1 = gaussian2D<float>(blur1);
00130     filter1 /= sum(filter1);
00131     im1 = convolveHmax(im1,filter1);
00132     im1 /= sum(im1);
00133 
00134     //image 2
00135     im2 += .00000001;
00136         //for (uint kk = 0; kk < ceil(blur2/STD9); kk++)
00137         //im2 = sepFilter(im2,kernel,kernel,CONV_BOUNDARY_CLEAN);
00138     Image<float> filter2 = gaussian2D<float>(blur2);
00139     filter2 /= sum(filter2);
00140     im2 = convolveHmax(im2,filter2);
00141     im2 /= sum(im2);
00142 
00143     //lets display the images
00144     if (DISPLAY)
00145     {
00146         prevwin->drawImage(im1,0,0);
00147         prevwin->drawImage(im2,640,0);
00148     }
00149 
00150     //output KL
00151     data[ii] = .05F * (sum(im1 * log(im1/im2)) + sum(im2 * log(im2/im1)));
00152     (*itsOutFile) << sformat("%2.6f",data[ii]) << std::endl;
00153     LINFO("%2.6f ",data[ii]);
00154 
00155 }
00156  itsOutFile->close();
00157 
00158 
00159 
00160 }//END MAIN
00161 
00162 // ######################################################################
00163 /* So things look consistent in everyone's emacs... */
00164 /* Local Variables: */
00165 /* indent-tabs-mode: nil */
00166 /* End: */
Generated on Sun May 8 08:40:07 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3