app-sc-map.C

Go to the documentation of this file.
00001 /*!@file AppNeuro/app-sc-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: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppNeuro/app-sc-map.C $
00035 // $Id: app-sc-map.C 10982 2009-03-05 05:11:22Z itti $
00036 //
00037 
00038 #ifndef APPNEURO_APP_SC_MAP_C_DEFINED
00039 #define APPNEURO_APP_SC_MAP_C_DEFINED
00040 
00041 #include "Channels/InputFrame.H"
00042 #include "Component/ModelManager.H"
00043 #include "GUI/XWinManaged.H"
00044 #include "Image/DrawOps.H"
00045 #include "Image/Image.H"
00046 #include "Image/LogPolarTransform.H"
00047 #include "Image/Normalize.H"
00048 #include "Image/Pixels.H"
00049 #include "Image/ShapeOps.H"
00050 #include "Media/FrameSeries.H"
00051 #include "Channels/RawVisualCortex.H"
00052 #include "Neuro/VisualCortexConfigurator.H"
00053 #include "Raster/GenericFrame.H"
00054 #include "Raster/Raster.H"
00055 #include "Transport/FrameInfo.H"
00056 #include "Util/CpuTimer.H"
00057 #include "Util/Pause.H"
00058 #include "Util/csignals.H"
00059 
00060 // int main(int argc, const char** argv)
00061 // {
00062 //   Image<PixRGB<byte> > inp(512, 512, ZEROS);
00063 //   inp.clear(PixRGB<byte>(255, 255, 255));
00064 
00065 //   const int w = inp.getWidth();
00066 //   const int h = inp.getHeight();
00067 
00068 //   for (int j = 0; j < h; ++j)
00069 //     for (int i = 0; i < w; ++i)
00070 //       {
00071 //         if (j < h/2)
00072 //           {
00073 //             if (i < w/2)
00074 //               inp.setVal(i, j, PixRGB<byte>(255, 192, 192));
00075 //             else
00076 //               inp.setVal(i, j, PixRGB<byte>(192, 255, 192));
00077 //           }
00078 //         else
00079 //           {
00080 //             if (i < w/2)
00081 //               inp.setVal(i, j, PixRGB<byte>(192, 192, 255));
00082 //             else
00083 //               inp.setVal(i, j, PixRGB<byte>(255, 255, 192));
00084 //           }
00085 //       }
00086 
00087 // //   drawGrid(inp, 32, 32, 2, 2, PixRGB<byte>(255, 0, 0));
00088 
00089 //   for (int ori = 0; ori < 360; ori += 30)
00090 //     {
00091 //       const double rad = ori * M_PI / 180.0;
00092 //       drawLine(inp, Point2D<int>(inp.getWidth() / 2, inp.getHeight() / 2),
00093 //                rad, inp.getWidth() * 2, PixRGB<byte>(255, 0, 0), 2);
00094 //     }
00095 
00096 //   for (int rad = 63; rad < inp.getWidth() / 2; rad += 64)
00097 //     {
00098 //       drawCircle(inp, Point2D<int>(inp.getWidth() / 2, inp.getHeight() / 2),
00099 //                  rad, PixRGB<byte>(0, 0,
00100 //                                    double(255.0 * rad / (inp.getWidth() / 2))),
00101 //                  2);
00102 //     }
00103 
00104 //   CpuTimer tm;
00105 
00106 //   LogPolarTransform t(inp.getDims(), Dims(375, 200), 0.3, 0.25);
00107 
00108 //   tm.mark(); tm.report("setup"); tm.reset();
00109 
00110 //   Image<PixRGB<byte> > btxf = t.transform(inp, PixRGB<byte>(255));
00111 
00112 //   tm.mark(); tm.report("transform"); tm.reset();
00113 
00114 //   XWinManaged win(inp);
00115 
00116 //   XWinManaged win2(btxf);
00117 
00118 //   while (!win.pressedCloseButton())
00119 //     sleep(1);
00120 // }
00121 
00122 int submain(const int argc, const char **argv)
00123 {
00124   volatile int signum = 0;
00125   catchsignals(&signum);
00126 
00127   ModelManager manager("Streamer");
00128 
00129   nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00130   manager.addSubComponent(ifs);
00131 
00132   nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00133   manager.addSubComponent(ofs);
00134 
00135   nub::ref<RawVisualCortex> vcx(new RawVisualCortex(manager));
00136   manager.addSubComponent(vcx);
00137 
00138   if (manager.parseCommandLine(argc, argv, "", 0, 0) == false)
00139     return(1);
00140 
00141   manager.start();
00142 
00143   ifs->startStream();
00144 
00145   const Dims indims = ifs->peekDims();
00146 
00147   LogPolarTransform t(indims, Dims(375, 200), 0.3, 0.2);
00148 
00149   int c = 0;
00150 
00151   PauseWaiter p;
00152 
00153   SimTime tm = SimTime::ZERO();
00154 
00155   while (true)
00156     {
00157       if (signum != 0)
00158         {
00159           LINFO("quitting because %s was caught", signame(signum));
00160           return -1;
00161         }
00162 
00163       if (ofs->becameVoid())
00164         {
00165           LINFO("quitting because output stream was closed or became void");
00166           return 0;
00167         }
00168 
00169       if (p.checkPause())
00170         continue;
00171 
00172       const FrameState is = ifs->updateNext();
00173       if (is == FRAME_COMPLETE)
00174         break;
00175 
00176       GenericFrame input = ifs->readFrame();
00177       if (!input.initialized())
00178         break;
00179 
00180       const Image<PixRGB<byte> > rgbin = input.asRgb();
00181 
00182       vcx->input(InputFrame::fromRgb(&rgbin, tm));
00183 
00184       const Image<float> vcxmap = rescaleBilinear(vcx->getOutput(), input.getDims());
00185 
00186       const FrameState os = ofs->updateNext();
00187 
00188       const Image<PixRGB<byte> > txf = logPolarTransform(t, input.asRgb(), PixRGB<byte>(255));
00189 
00190       const Image<float> txfsalmap = logPolarTransform(t, vcxmap, float(0.0f));
00191 
00192       ofs->writeFrame(input, "input",
00193                       FrameInfo("input frame", SRC_POS));
00194 
00195       ofs->writeRGB(txf, "logpolar",
00196                     FrameInfo("log-polar transform of input frame", SRC_POS));
00197 
00198       ofs->writeFloat(vcxmap, FLOAT_NORM_0_255, "vcxmap",
00199                       FrameInfo("VisualCortex output", SRC_POS));
00200 
00201       ofs->writeFloat(txfsalmap, FLOAT_NORM_0_255, "txfsalmap",
00202                       FrameInfo("Log-Polar VisualCortex output", SRC_POS));
00203 
00204       {
00205         Image<byte> vcxmapb = normalizeFloat(vcxmap, FLOAT_NORM_0_255);
00206         Image<byte> txfsalmapb = normalizeFloat(txfsalmap, FLOAT_NORM_0_255);
00207 
00208         const Image<PixRGB<byte> > vcxmapn(vcxmapb);
00209         const Image<PixRGB<byte> > txfsalmapn(txfsalmapb);
00210 
00211         ofs->writeRgbLayout(hcat(vcat(rescaleBilinear(rgbin, 372,279), txf),
00212                                  vcat(rescaleBilinear(vcxmapn, 372,279), txfsalmapn)),
00213                             "grid");
00214       }
00215 
00216       if (os == FRAME_FINAL)
00217         break;
00218 
00219       LDEBUG("frame %d", c++);
00220 
00221       if (ifs->shouldWait() || ofs->shouldWait())
00222         Raster::waitForKey();
00223 
00224       tm += SimTime::HERTZ(30);
00225     }
00226 
00227   return 0;
00228 }
00229 
00230 int main(const int argc, const char **argv)
00231 {
00232   try
00233     {
00234       return submain(argc, argv);
00235     }
00236   catch (...)
00237     {
00238       REPORT_CURRENT_EXCEPTION;
00239     }
00240 
00241   return 1;
00242 }
00243 
00244 // ######################################################################
00245 /* So things look consistent in everyone's emacs... */
00246 /* Local Variables: */
00247 /* mode: c++ */
00248 /* indent-tabs-mode: nil */
00249 /* End: */
00250 
00251 #endif // APPNEURO_APP_SC_MAP_C_DEFINED
Generated on Sun May 8 08:40:08 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3