00001 /*!@file AppMedia/test-lowDec.C 00002 */ 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2002 // 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: Dirk Walther <walther@caltech.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppMedia/test-lowDec.C $ 00035 // $Id: test-lowDec.C 10982 2009-03-05 05:11:22Z itti $ 00036 // 00037 00038 #include "Component/ModelManager.H" 00039 #include "Image/ColorOps.H" 00040 #include "Image/FilterOps.H" 00041 #include "Image/Image.H" 00042 #include "Image/MathOps.H" 00043 #include "Image/Pixels.H" 00044 #include "Image/ShapeOps.H" 00045 #include "Neuro/StdBrain.H" 00046 #include "Raster/PngWriter.H" 00047 #include "Raster/Raster.H" 00048 #include "Util/Timer.H" 00049 #include "Util/log.H" 00050 00051 #include <cstdio> 00052 00053 int main(const int argc, const char** argv) 00054 { 00055 00056 if (argc <= 1) 00057 { 00058 LINFO("usage: %s imagefile [sampling factor]",argv[0]); 00059 return -1; 00060 } 00061 00062 int sub = 2; 00063 if (argc > 2) sscanf(argv[2],"%d",&sub); 00064 00065 LINFO("subsampling factor is %d",sub); 00066 00067 // load image 00068 Image<PixRGB <byte> > rgbimg = Raster::ReadRGB(argv[1]); 00069 Image<float> img = luminance(rgbimg); 00070 LINFO("image dimensions: %d x %d",img.getWidth(), img.getHeight()); 00071 00072 00073 // process with old method 00074 Image<float> lowPx = lowPass5x(img); 00075 Image<float> oldresultX = decX(lowPx,sub); 00076 Image<float> lowP = lowPass5y(oldresultX); 00077 Image<float> oldresult = decY(lowP,sub); 00078 00079 // process with new method 00080 Image<float> newresultX = lowPass5xDecX(img,sub); 00081 Image<float> newresult = lowPass5yDecY(newresultX,sub); 00082 00083 00084 LINFO("old dims = %d x %d",oldresult.getWidth(),oldresult.getHeight()); 00085 LINFO("new dims = %d x %d",newresult.getWidth(),newresult.getHeight()); 00086 00087 // compare the results 00088 Image<float> diff = oldresult - newresult; 00089 float min, max; 00090 getMinMax(diff, min,max); 00091 00092 // output the verdict 00093 LINFO("diff.min = %g; diff.max = %g",min,max); 00094 00095 // save them images 00096 PngWriter::writeGray(newresult, "new.png"); 00097 PngWriter::writeGray(oldresult, "old.png"); 00098 PngWriter::writeGray(diff, "diff.png"); 00099 PngWriter::writeGray(lowP, "lowp.png"); 00100 00101 // stop time for repeated execution 00102 const int N = 100; 00103 Timer timer; 00104 00105 for (int i = 0; i < N; ++i) decY(lowPass5y(decX(lowPass5x(img),sub)),sub); 00106 int oldtime = (int)timer.getReset(); 00107 for (int i = 0; i < N; ++i) lowPass5yDecY(lowPass5xDecX(img,sub),sub); 00108 00109 int newtime = (int)timer.get(); 00110 00111 LINFO("old time = %i ms; new time = %i ms for %i iterations", 00112 oldtime,newtime,N); 00113 00114 /* 00115 ModelManager mgr; 00116 mgr.allowOptions(OPTEXP_CORE); 00117 nub::soft_ref<StdBrain> brain(new StdBrain(mgr)); 00118 mgr.addSubComponent(brain); 00119 mgr.exportOptions(MC_RECURSE); 00120 mgr.setOptionValString(&OPT_RawVisualCortexType,"Std"); 00121 mgr.start(); 00122 00123 timer.reset(); 00124 00125 for (int i = 0; i < N; ++i) 00126 { 00127 brain->input(rgbimg); 00128 brain->reset(); 00129 } 00130 int tbrain = (int)timer.get(); 00131 00132 mgr.stop(); 00133 00134 LINFO("time for %i brain calls is %i ms",N,tbrain); 00135 */ 00136 00137 } 00138 00139 00140 // ###################################################################### 00141 /* So things look consistent in everyone's emacs... */ 00142 /* Local Variables: */ 00143 /* indent-tabs-mode: nil */ 00144 /* End: */