test-Jet.C

Go to the documentation of this file.
00001 /*!@file Beobot/test-Jet.C Test Jet class */
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: Rob Peters <rjpeters@klab.caltech.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/test-Jet.C $
00035 // $Id: test-Jet.C 12074 2009-11-24 07:51:51Z itti $
00036 //
00037 
00038 #include "Beobot/BeobotVisualCortex.H"
00039 #include "GUI/XWindow.H"
00040 #include "Image/ColorOps.H"
00041 #include "Image/CutPaste.H"     // for inplacePaste()
00042 #include "Image/Image.H"
00043 #include "Image/Pixels.H"
00044 #include "Image/fancynorm.H"
00045 #include "Raster/Raster.H"
00046 
00047 #include <iostream>
00048 #include <cstdio>
00049 
00050 
00051 
00052 #define NBNEIGH 24
00053 
00054 // ######################################################################
00055 int main(const int argc, const char **argv)
00056 {
00057   initRandomNumbers();
00058 
00059   int sml = 4;                       // [4] level of salmap
00060   int delta_min = 3, delta_max = 4;  // [3,4] spacing (in levs) betw C and S
00061   int level_min = 2, level_max = 4;  // [2,4] top levels for CS
00062   int nborient = 4;                  // nb of basis orientations for avg orient
00063   int jdepth = 3;                    // number of scales in the jets
00064   int frame, initFrame; char imageNameBase[100]; int outframe = 0;
00065   bool pause, writeframes, firstFrame = true;
00066 
00067   if (argc >= 2) strcpy(imageNameBase, argv[1]);
00068   else LFATAL("USAGE: test-Jet <path> [initFrame] [pause] [writeframes]");
00069   if (imageNameBase[strlen(imageNameBase) - 1] != '/')
00070     strcat(imageNameBase, "/");
00071   if (argc >= 3) initFrame = atoi(argv[2]); else initFrame = 0;
00072   if (argc >= 4) pause = atoi(argv[3]) != 0; else pause = false;
00073   if (argc >= 5) writeframes = atoi(argv[4]) != 0; else writeframes = false;
00074 
00075   // read the first frame to determine its size
00076   Image< PixRGB<byte> > col_image =
00077     Raster::ReadRGB(sformat("%sframe%06d.ppm", imageNameBase, initFrame));
00078 
00079   XWindow xwindow(Dims(col_image.getWidth() * 3, col_image.getHeight() * 2),
00080                   -1, -1, "Visual Scene Clustering");
00081   Image< PixRGB<byte> > disp(col_image.getWidth() * 3,
00082                              col_image.getHeight() * 2, ZEROS);
00083 
00084   Point2D<int> centroid(col_image.getWidth() / (1 << (sml + 1)),
00085                    col_image.getHeight() / (1 << sml) - 2);
00086   Point2D<int> prevcentroid(centroid);
00087 
00088   // initialize visual cortex:
00089   BeobotVisualCortex visualCX;
00090   visualCX.init(col_image.getWidth(), col_image.getHeight(),
00091                 level_min, level_max, delta_min, delta_max,
00092                 sml, nborient, VCXNORM_DEFAULT, sml, jdepth, NBNEIGH,
00093                 nub::soft_ref<Beowulf>());
00094 
00095   for (frame = initFrame; ; frame++)
00096     {
00097       col_image = Raster::ReadRGB(sformat("%sframe%06d.ppm", imageNameBase, frame));
00098       inplacePaste(disp, col_image, Point2D<int>(0, 0));
00099 
00100       visualCX.newVisualInput(col_image);
00101       visualCX.process(frame);
00102       visualCX.initSprings(firstFrame);
00103 
00104       Image< PixRGB<byte> > deformedImage;
00105 
00106       const float dt = 0.1;
00107       int nbIter; if (firstFrame) nbIter = 5 /*15*/; else nbIter = 5;
00108 
00109       for(int t = 0; t < nbIter; t++)
00110         {
00111           // iterate the spring model:
00112           visualCX.iterateSprings(dt);
00113 
00114           Image< PixRGB<byte> > img;
00115           visualCX.getPositions(img, 1 << (sml+1));
00116           inplacePaste(disp, img, Point2D<int>(col_image.getWidth(), 0));
00117 
00118           // compute the clusters:
00119           visualCX.getClusteredImage(deformedImage, centroid, prevcentroid);
00120           prevcentroid = centroid;
00121           inplacePaste(disp, deformedImage, Point2D<int>(0, col_image.getHeight()));
00122 
00123           // display the current state:
00124           xwindow.drawImage(disp);
00125 
00126           // write frames out:
00127           if (writeframes) Raster::WriteRGB(disp, sformat("T%06d.ppm", outframe ++));
00128 
00129           if (pause)
00130             {
00131               std::cout<<"<<<<< Press [RETURN] to continue >>>>>"<<std::endl;
00132               getchar();
00133             }
00134         }
00135       firstFrame = false;
00136     }
00137   return 0;
00138 }
00139 
00140 // ######################################################################
00141 /* So things look consistent in everyone's emacs... */
00142 /* Local Variables: */
00143 /* indent-tabs-mode: nil */
00144 /* End: */
Generated on Sun May 8 08:40:15 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3