00001 /*!@file AppNeuro/app-cortical-map.C */ 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: David Berg <dberg@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppNeuro/app-cortical-map.C $ 00035 00036 00037 #include "Component/ModelManager.H" 00038 #include "Component/ModelOptionDef.H" 00039 00040 #include "Channels/InputFrame.H" 00041 #include "GUI/XWinManaged.H" 00042 #include "Image/DrawOps.H" 00043 #include "Image/Image.H" 00044 #include "Image/ShapeOps.H" 00045 #include "Image/Layout.H" 00046 #include "Image/Normalize.H" 00047 #include "SpaceVariant/FovealTransformModule.H" 00048 #include "SpaceVariant/SpaceVariantDoGModule.H" 00049 #include "SpaceVariant/SpaceVariantEdgeModule.H" 00050 #include "SpaceVariant/SpaceVariantOpts.H" 00051 #include "Media/FrameSeries.H" 00052 #include "Raster/GenericFrame.H" 00053 #include "Raster/Raster.H" 00054 #include "Transport/FrameInfo.H" 00055 #include "Util/Pause.H" 00056 #include "Util/csignals.H" 00057 #include "Util/Timer.H" 00058 00059 static const ModelOptionDef OPT_SpaceVariantUseDog = 00060 { MODOPT_FLAG, "SpaceVariantUseDog", &MOC_SPACEVARIANT, OPTEXP_CORE, 00061 "display a dog image?","use-dog", '\0', "", "false" }; 00062 00063 static const ModelOptionDef OPT_SpaceVariantUseEdge = 00064 { MODOPT_FLAG, "SpaceVariantUseEdge", &MOC_SPACEVARIANT, OPTEXP_CORE, 00065 "display an edge image?","use-edge", '\0', "", "false" }; 00066 00067 static const ModelOptionDef OPT_SpaceVariantUseLines = 00068 { MODOPT_FLAG, "SpaceVariantUseLines", &MOC_SPACEVARIANT, OPTEXP_CORE, 00069 "ignore the input frame series and transform an image of vertical lines", 00070 "use-lines", '\0', "", "false" }; 00071 00072 static const ModelOptionDef OPT_SpaceVariantSplit = 00073 { MODOPT_FLAG, "SpaceVariantSplit", &MOC_SPACEVARIANT, OPTEXP_CORE, 00074 "should we display a fovea and a periphery separately?", 00075 "split-fovea-periphery", '\0', "", "false" }; 00076 00077 int submain(const int argc, const char **argv) 00078 { 00079 volatile int signum = 0; 00080 catchsignals(&signum); 00081 00082 ModelManager manager("Cortical Transform Images"); 00083 OModelParam<bool> useDog(&OPT_SpaceVariantUseDog, &manager); 00084 OModelParam<bool> useEdge(&OPT_SpaceVariantUseEdge, &manager); 00085 OModelParam<bool> useLines(&OPT_SpaceVariantUseLines, &manager); 00086 OModelParam<bool> svSplit(&OPT_SpaceVariantSplit, &manager); 00087 00088 nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); 00089 manager.addSubComponent(ifs); 00090 00091 nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager)); 00092 manager.addSubComponent(ofs); 00093 00094 nub::soft_ref<FovealTransformModule> svm(new FovealTransformModule(manager)); 00095 manager.addSubComponent(svm); 00096 00097 nub::soft_ref<SpaceVariantDoGModule> svmdog(new SpaceVariantDoGModule(manager)); 00098 manager.addSubComponent(svmdog); 00099 00100 nub::soft_ref<SpaceVariantEdgeModule> svmedge(new SpaceVariantEdgeModule(manager)); 00101 manager.addSubComponent(svmedge); 00102 00103 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) 00104 return(1); 00105 00106 manager.start(); 00107 00108 ifs->startStream(); 00109 00110 int c = 0; 00111 PauseWaiter p; 00112 00113 SimTime tm = SimTime::ZERO(); 00114 Timer timer(1000); 00115 while (true) 00116 { 00117 if (signum != 0) 00118 { 00119 LINFO("quitting because %s was caught", signame(signum)); 00120 return -1; 00121 } 00122 00123 if (ofs->becameVoid()) 00124 { 00125 LINFO("quitting because output stream was closed or became void"); 00126 return 0; 00127 } 00128 00129 if (p.checkPause()) 00130 continue; 00131 00132 const FrameState is = ifs->updateNext(); 00133 if (is == FRAME_COMPLETE) 00134 break; 00135 00136 GenericFrame input = ifs->readFrame(); 00137 if (!input.initialized()) 00138 break; 00139 00140 //display am image of lines 00141 if (useLines.getVal()) 00142 { 00143 Image<PixRGB<byte> > img(input.getDims(), NO_INIT); 00144 for (int x = 0; x < input.getWidth(); ++x) 00145 for (int y = 0; y < input.getHeight(); ++y) 00146 if (x % 2 == 0) 00147 img.setVal(x,y,PixRGB<byte>(0,0,255)); 00148 else 00149 img.setVal(x,y,PixRGB<byte>(255,0,0)); 00150 input = GenericFrame(img); 00151 } 00152 00153 Image<PixRGB<byte> > ctimage, ctimageinv; 00154 if (useDog.getVal()) 00155 { 00156 //get rgb image and transform 00157 const Image<float> rgbin = input.asGray(); 00158 timer.reset(); 00159 ctimage = normalizeFloat(svmdog->transformDoG(rgbin), FLOAT_NORM_0_255); 00160 LINFO("Transform time: %.6f", timer.getSecs()); 00161 timer.reset(); 00162 ctimageinv = svmdog->inverseTransform(ctimage); 00163 LINFO("Inverse Transform time: %.6f", timer.getSecs()); 00164 } 00165 else if (useEdge.getVal()) 00166 { 00167 //get rgb image and transform 00168 const Image<float> rgbin = input.asGray(); 00169 timer.reset(); 00170 ctimage = normalizeFloat(svmedge->transformEdge(rgbin), FLOAT_NORM_0_255); 00171 00172 LINFO("Transform time: %.6f", timer.getSecs()); 00173 timer.reset(); 00174 ctimageinv = svmedge->inverseTransform(ctimage); 00175 LINFO("Inverse Transform time: %.6f", timer.getSecs()); 00176 } 00177 else 00178 { 00179 //get rgb image and transform 00180 const Image<PixRGB<byte> > rgbin = input.asRgb(); 00181 timer.reset(); 00182 ctimage = svm->transform(rgbin); 00183 00184 LINFO("Transform time: %.6f", timer.getSecs()); 00185 timer.reset(); 00186 ctimageinv = svm->inverseTransform(ctimage); 00187 LINFO("Inverse Transform time: %.6f", timer.getSecs()); 00188 } 00189 00190 00191 00192 const FrameState os = ofs->updateNext(); 00193 00194 if (svSplit.getVal()) 00195 { 00196 Image<PixRGB<byte> > f, p; 00197 svm->getFoveaPeriphery(ctimage, f, p); 00198 ofs->writeRGB(f,"Cortical Image Fovea"); 00199 ofs->writeRGB(p,"Cortical Image Periphery"); 00200 } 00201 else 00202 ofs->writeRGB(ctimage,"Cortical Image"); 00203 00204 ofs->writeRGB(ctimageinv,"Cortical Image Inverse"); 00205 ofs->writeFrame(input,"input"); 00206 00207 if (os == FRAME_FINAL) 00208 break; 00209 00210 LDEBUG("frame %d", c++); 00211 00212 if (ifs->shouldWait() || ofs->shouldWait()) 00213 Raster::waitForKey(); 00214 00215 tm += SimTime::HERTZ(30); 00216 } 00217 00218 return 0; 00219 } 00220 00221 int main(const int argc, const char **argv) 00222 { 00223 try 00224 { 00225 return submain(argc, argv); 00226 } 00227 catch (...) 00228 { 00229 REPORT_CURRENT_EXCEPTION; 00230 } 00231 00232 return 1; 00233 } 00234 00235 // ###################################################################### 00236 /* So things look consistent in everyone's emacs... */ 00237 /* Local Variables: */ 00238 /* mode: c++ */ 00239 /* indent-tabs-mode: nil */ 00240 /* End: */