00001 /*!@file Foveator/test-Foveator.C Test the Foveator 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: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Foveator/test-Foveator.C $ 00035 // $Id: test-Foveator.C 6191 2006-02-01 23:56:12Z rjpeters $ 00036 // 00037 00038 #include "Foveator/BlurFoveator.H" 00039 #include "Foveator/Foveator.H" 00040 #include "Foveator/LPTFoveator.H" 00041 #include "Foveator/PyrFoveator.H" 00042 #include "Image/Image.H" 00043 #include "Image/Pixels.H" 00044 #include "Raster/Raster.H" 00045 #include "Util/Timer.H" 00046 #include "Util/log.H" 00047 00048 // ###################################################################### 00049 // ##### Main Program: 00050 // ###################################################################### 00051 00052 //! The main routine. Read images, process, output results. 00053 int main (int argc, char **argv) 00054 { 00055 if (argc != 2) 00056 { 00057 LFATAL("usage: test-Foveator file.[ppm|pgm]\n"); 00058 } 00059 00060 // read the image 00061 00062 Image< PixRGB<byte> > img; 00063 00064 img = Raster::ReadRGB( argv[1] ); 00065 if (!img.initialized()) 00066 { 00067 LFATAL("error loading image: %s", argv[1] ); 00068 } 00069 00070 // create output file names 00071 00072 char *blr_out, *pyr_out, *lpt_out, *map_out; 00073 int filenameLength = strlen( argv[1] ); 00074 blr_out = new char[filenameLength + 5]; 00075 pyr_out = new char[filenameLength + 5]; 00076 lpt_out = new char[filenameLength + 5]; 00077 map_out = new char[filenameLength + 5]; 00078 00079 int lastdot = filenameLength - 1; 00080 while( argv[1][lastdot] != '.' ) 00081 { 00082 lastdot--; 00083 } 00084 int i = 0; 00085 for( i = 0; i < lastdot; i++ ) 00086 { 00087 blr_out[i] = argv[1][i]; 00088 pyr_out[i] = argv[1][i]; 00089 lpt_out[i] = argv[1][i]; 00090 map_out[i] = argv[1][i]; 00091 } 00092 00093 blr_out[i++] = '_'; 00094 blr_out[i++] = 'b'; 00095 blr_out[i++] = 'l'; 00096 blr_out[i++] = 'r'; 00097 i -= 4; 00098 pyr_out[i++] = '_'; 00099 pyr_out[i++] = 'p'; 00100 pyr_out[i++] = 'y'; 00101 pyr_out[i++] = 'r'; 00102 i -= 4; 00103 lpt_out[i++] = '_'; 00104 lpt_out[i++] = 'l'; 00105 lpt_out[i++] = 'p'; 00106 lpt_out[i++] = 't'; 00107 i -= 4; 00108 map_out[i++] = '_'; 00109 map_out[i++] = 'm'; 00110 map_out[i++] = 'a'; 00111 map_out[i++] = 'p'; 00112 00113 while( i < ( filenameLength + 4 ) ) 00114 { 00115 blr_out[i] = argv[1][i-4]; 00116 pyr_out[i] = argv[1][i-4]; 00117 lpt_out[i] = argv[1][i-4]; 00118 map_out[i] = argv[1][i-4]; 00119 i++; 00120 } 00121 blr_out[i] = '\0'; 00122 pyr_out[i] = '\0'; 00123 lpt_out[i] = '\0'; 00124 map_out[i] = '\0'; 00125 00126 // using Foveator classes 00127 00128 BlurFoveator bf( img, 5 ); 00129 PyrFoveator pf( img, 5 ); 00130 pf.setBaseRect( 40, 40 ); 00131 LPTFoveator lf( img, img.getWidth() / 2, img.getHeight() / 2 ); 00132 00133 // write foveated image to output files 00134 00135 Image< PixRGB<byte> > blrImg; 00136 Timer tm; 00137 blrImg = bf.foveate(); 00138 // blrImg = BlurFoveator::foveate( img, 5, 100, 100 ); 00139 LINFO( "Time for BlurFoveation: %llums", tm.get() ); 00140 Raster::WriteRGB( blrImg, blr_out ); 00141 00142 Image< PixRGB<byte> > pyrImg; 00143 tm.reset(); 00144 pyrImg = pf.foveate(); 00145 // pyrImg = PyrFoveator::foveate( img, 5, 40, 40, 100, 100 ); 00146 LINFO( "Time for PyrFoveation: %llums", tm.get() ); 00147 Raster::WriteRGB( pyrImg, pyr_out ); 00148 00149 Image< PixRGB<byte> > lptImg; 00150 tm.reset(); 00151 lptImg = lf.foveate(); 00152 /* lptImg = LPTFoveator::foveate( img, img.getWidth() / 2, 00153 img.getHeight() / 2, img.getWidth() / 2, 00154 img.getHeight() / 2, false ); */ 00155 LINFO( "Time for LPTFoveation (full process): %llums", tm.get() ); 00156 Raster::WriteRGB( lptImg, lpt_out ); 00157 00158 Image< PixRGB<byte> > mapImg; 00159 tm.reset(); 00160 mapImg = lf.getLPT(); 00161 /* mapImg = LPTFoveator::foveate( img, img.getWidth() / 2, 00162 img.getHeight() / 2, img.getWidth() / 2, 00163 img.getHeight() / 2, true ); */ 00164 LINFO( "Time for LPTFoveation (map image only): %llums", tm.get() ); 00165 Raster::WriteRGB( mapImg, map_out ); 00166 } 00167 00168 // ###################################################################### 00169 /* So things look consistent in everyone's emacs... */ 00170 /* Local Variables: */ 00171 /* indent-tabs-mode: nil */ 00172 /* End: */