test-SoxChannel.C

Go to the documentation of this file.
00001 /*!@file AppNeuro/test-SoxChannel.C Test the SoxChannel 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/AppNeuro/test-SoxChannel.C $
00035 // $Id: test-SoxChannel.C 9412 2008-03-10 23:10:15Z farhan $
00036 //
00037 
00038 
00039 #include "Channels/SoxChannel.H"
00040 #include "Component/ModelManager.H"
00041 #include "Component/ParamMap.H"
00042 #include "Image/ColorOps.H"
00043 #include "Image/DrawOps.H"
00044 #include "Image/LevelSpec.H"
00045 #include "Image/MathOps.H"
00046 #include "Image/Pixels.H"
00047 #include "Image/Range.H"
00048 #include "Image/ShapeOps.H"
00049 #include "Image/fancynorm.H"
00050 #include "Raster/Raster.H"
00051 #include "Util/log.H"
00052 #include "rutz/compat_snprintf.h"
00053 
00054 #include <algorithm>
00055 #include <vector>
00056 
00057 int main(const int argc, const char** argv)
00058 {
00059   // Instantiate a ModelManager:
00060   ModelManager manager("SoxChannel Tester");
00061 
00062   // Instantiate our various ModelComponents:
00063   nub::soft_ref<SoxChannel> lc(new SoxChannel(manager));
00064   manager.addSubComponent(lc);
00065 
00066   // Parse command-line:
00067   if (manager.parseCommandLine(argc, argv,
00068                                "<image.ppm> [scale]", 1, 2) == false)
00069     return(1);
00070 
00071   // do post-command-line configs:
00072   int SCALE = 1;
00073   if (manager.numExtraArgs() > 1) SCALE = manager.getExtraArgAs<int>(1);
00074 
00075   // let's get all our ModelComponent instances started:
00076   manager.start();
00077 
00078   // read the input image:
00079   const Image<PixRGB<byte> > input =
00080     Raster::ReadRGB(manager.getExtraArg(0));
00081 
00082   lc->input(InputFrame::fromRgb(&input));
00083 
00084   std::vector<Image<float> > lin(lc->numChans());
00085   std::vector<Image<float> > nonlin(lc->numChans());
00086 
00087   Range<float> lin_rng;
00088   Range<float> nonlin_rng;
00089 
00090   for (uint ori = 0; ori < lc->numChans(); ++ori)
00091     {
00092       lin[ori] = lc->getLinearResponse(ori, SCALE);
00093       nonlin[ori] = lc->getNonlinearResponse(ori, SCALE);
00094 
00095       lin_rng.merge(rangeOf(lin[ori]));
00096       nonlin_rng.merge(rangeOf(nonlin[ori]));
00097     }
00098 
00099   LINFO("lin_rng: [%g, %g]", lin_rng.min(), lin_rng.max());
00100   LINFO("nonlin_rng: [%g, %g]", nonlin_rng.min(), nonlin_rng.max());
00101 
00102   std::vector<Image<PixRGB<float> > > resps;
00103 
00104   // This is a "backwards" range so that we in effect do a binaryReverse()
00105   // when we call remapRange()
00106   Range<float> stdrange(1.0f, 0.0f);
00107 
00108   for (uint ori = 0; ori < lc->numChans(); ++ori)
00109     {
00110       lin[ori] = remapRange(lin[ori], lin_rng, stdrange);
00111       nonlin[ori] = remapRange(nonlin[ori], nonlin_rng, stdrange);
00112 
00113       char text[256]; text[0] = 0;
00114 
00115       if (lin[ori].getWidth() > 50)
00116         snprintf(text, 256, "%d", ori);
00117 
00118       int border_width = lin[ori].getWidth() > 25 ? 1 : 0;
00119 
00120       resps.push_back(stain(lin[ori], PixRGB<float>(245, 255, 245)));
00121       writeText(resps.back(), Point2D<int>(0,0), text);
00122       inplaceSetBorders(resps.back(), border_width, PixRGB<float>(128, 255, 128));
00123 
00124       resps.push_back(stain(nonlin[ori], PixRGB<float>(245, 245, 255)));
00125       inplaceSetBorders(resps.back(), border_width, PixRGB<float>(128, 128, 255));
00126 
00127       Image<float> diff = (lin[ori] - nonlin[ori]);
00128 
00129       Image<PixRGB<float> > cdiff = normalizeRGPolar(diff, 2.0, -2.0);
00130       normalizeC(cdiff, 0, 255);
00131       resps.push_back(cdiff);
00132       inplaceSetBorders(resps.back(), border_width, PixRGB<float>(255, 128, 128));
00133     }
00134 
00135   Image<PixRGB<float> > arr = concatArray(&resps[0], resps.size(), 3);
00136   Raster::VisuRGB(arr, "sox.ppm");
00137 
00138   // get ready for a clean exit:
00139   manager.stop();
00140   return 0;
00141 }
00142 
00143 // ######################################################################
00144 /* So things look consistent in everyone's emacs... */
00145 /* Local Variables: */
00146 /* indent-tabs-mode: nil */
00147 /* End: */
Generated on Sun May 8 08:04:11 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3