app-combineSTSD.C

Go to the documentation of this file.
00001 /*!@file AppNeuro/app-combineSTSD.C combine STSD optimal gains files */
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: Vidhya Navalpakkam <navalpak@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppNeuro/app-combineSTSD.C $
00035 // $Id: app-combineSTSD.C 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #include "Channels/OptimalGains.H"
00039 #include "Component/ModelManager.H"
00040 #include "Component/ParamMap.H"
00041 #include "Util/sformat.H"
00042 
00043 // ######################################################################
00044 rutz::shared_ptr<ParamMap>
00045 combineParamMaps(std::vector<rutz::shared_ptr<ParamMap> > pmaps, const uint indent)
00046 {
00047   rutz::shared_ptr<ParamMap> outpmap(new ParamMap());
00048   const std::string id(indent, ' ');
00049 
00050   // take the first pmap as reference for the keys, and loop over keys:
00051   ParamMap::key_iterator itr = pmaps[0]->keys_begin(), stop = pmaps[0]->keys_end();
00052 
00053   while (itr != stop) {
00054     const std::string name = *itr;
00055 
00056     // find a submap or copy the subchanidx info:
00057     if (pmaps[0]->isLeaf(name)) {
00058       if (name.compare("subchanidx") == 0) outpmap->putIntParam(name, pmaps[0]->getIntParam(name));
00059     } else {
00060       // it's a subpmap, let's recurse through it: for that, we need
00061       // to extract the subpmaps from all our input pmaps. This will
00062       // LFATAL if there is inconsistency among our input pmaps:
00063       std::vector<rutz::shared_ptr<ParamMap> > subpmaps;
00064       for (uint i = 0; i < pmaps.size(); i ++) subpmaps.push_back(pmaps[i]->getSubpmap(name));
00065 
00066       // recurse:
00067       LDEBUG("%s%s:", id.c_str(), name.c_str());
00068       outpmap->putSubpmap(name, combineParamMaps(subpmaps, indent + 2));
00069     }
00070     ++itr;
00071   }
00072 
00073   // now combine at our level:
00074   uint i = 0;
00075   while (pmaps[0]->hasParam(sformat("salienceT(%d)", i)))
00076     {
00077       double sT = 0.0, sD = 0.0;
00078       for (uint j = 0; j < pmaps.size(); j ++)
00079         {
00080           sT += pmaps[j]->getDoubleParam(sformat("salienceT(%d)", i));
00081           sD += pmaps[j]->getDoubleParam(sformat("salienceD(%d)", i));
00082         }
00083 
00084       // output combined (averaged) sT and sD:
00085       sT /= pmaps.size(); sD /= pmaps.size();
00086 
00087       LDEBUG("%ssT(%d) = %f, sD(%d) = %f", id.c_str(), i, sT, i, sD);
00088       outpmap->putDoubleParam(sformat("salienceT(%d)", i), sT);
00089       outpmap->putDoubleParam(sformat("salienceD(%d)", i), sD);
00090 
00091       ++i;
00092     }
00093   return outpmap;
00094 }
00095 
00096 // ######################################################################
00097 //! Combine several stsd.pmap files into a combo stsd.pmap file
00098 /*! The stsd.pmap files should be obtained by running something like:
00099 
00100     ezvision --in=xmlfile:testfile.xml --out=display --pfc-type=OG
00101          --vc-type=Std --vc-chans=GNO --stsd-filename=stsd.pmap --nouse-older-version
00102 
00103     which will compute the salience of target and distractor and save
00104     those to a ParamMap. Once you have several of these you can use
00105     the present program to generate a combined ParamMap (it is
00106     written to stdout).
00107 */
00108 int main(const int argc, const char **argv)
00109 {
00110   MYLOGVERB = LOG_INFO;  // suppress debug messages
00111 
00112   // Instantiate a ModelManager:
00113   ModelManager manager("Optimal Gains Combiner");
00114 
00115   // Parse command-line:
00116   if (manager.parseCommandLine(argc, argv, "<stsd1.pmap> ... <stsdN.pmap>",
00117                                1, -1) == false)
00118     return(1);
00119 
00120   // do post-command-line configs:
00121   std::vector<rutz::shared_ptr<ParamMap> > pmaps;
00122   for (uint i = 0; i < manager.numExtraArgs(); i ++)
00123     {
00124       LINFO("Loading: %s", manager.getExtraArg(i).c_str());
00125       pmaps.push_back(ParamMap::loadPmapFile(manager.getExtraArg(i)));
00126     }
00127 
00128   rutz::shared_ptr<ParamMap> outpmap = combineParamMaps(pmaps, 0);
00129 
00130   // write output to stdout:
00131   outpmap->format(std::cout);
00132 
00133   // all done!
00134   return 0;
00135 }
00136 
00137 // ######################################################################
00138 /* So things look consistent in everyone's emacs... */
00139 /* Local Variables: */
00140 /* indent-tabs-mode: nil */
00141 /* End: */
Generated on Sun May 8 08:04:11 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3