getSaliency.C

Go to the documentation of this file.
00001 /*!@file Neuro/getSaliency.C Interface for obtaining lists of salient
00002   locations */
00003 
00004 // //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00006 // University of Southern California (USC) and the iLab at USC.         //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: Dirk Walther <walther@caltech.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Neuro/getSaliency.C $
00036 // $Id: getSaliency.C 13065 2010-03-28 00:01:00Z itti $
00037 //
00038 
00039 #include "Neuro/getSaliency.H"
00040 
00041 #include "Channels/ChannelMaps.H"
00042 #include "Channels/ChannelOpts.H"
00043 #include "Component/OptionManager.H"
00044 #include "Media/MediaSimEvents.H"
00045 #include "Neuro/NeuroSimEvents.H"
00046 #include "Neuro/NeuroOpts.H"
00047 #include "Neuro/VisualCortex.H"
00048 #include "Util/log.H"
00049 #include "Image/MathOps.H"
00050 #include "Image/CutPaste.H"
00051 #include "Image/ShapeOps.H"
00052 #include <string>
00053 
00054 // ######################################################################
00055 GetSaliency::GetSaliency(OptionManager& mgr) :
00056   StdBrain(mgr),
00057   SIMCALLBACK_INIT(SimEventWTAwinner),
00058   itsQ(new SimEventQueue(mgr)),
00059   itsSalmap(), itsCoords(), itsTimes()
00060 {
00061   this->addSubComponent(itsQ);
00062 
00063   // by default, only use CIO channels and no TRM:
00064 //  mgr.setOptionValString(&OPT_RawVisualCortexChans, "CIO");
00065 //  mgr.setOptionValString(&OPT_TaskRelevanceMapType, "None");
00066 }
00067 
00068 
00069 // ######################################################################
00070 GetSaliency::~GetSaliency()
00071 { }
00072 
00073 // ######################################################################
00074 void GetSaliency::
00075 onSimEventWTAwinner(SimEventQueue& q, rutz::shared_ptr<SimEventWTAwinner>& e)
00076 {
00077   itsCoords.push_back(e->winner().p);
00078   itsTimes.push_back(q.now());
00079 }
00080 
00081 // ######################################################################
00082 const int GetSaliency::compute(const Image< PixRGB<byte> >& img,
00083                                const SimTime& max_time)
00084 {
00085   LINFO("Start at %.2fms", itsQ->now().msecs());
00086 
00087   SimTime end_time = itsQ->now() + max_time;
00088 
00089   // post the input as an event:
00090   rutz::shared_ptr<SimEventInputFrame> e(new SimEventInputFrame(this, GenericFrame(img), 0));
00091   itsQ->post(e);
00092 
00093   // start with empty lists of coords and times:
00094   itsCoords.clear(); itsTimes.clear();
00095 
00096   // time-loop, evolve until we have anough attention shifts:
00097   while (itsQ->now() < end_time) itsQ->evolve();
00098 
00099   // obtain the saliency map to return it with getSalmap
00100   if (SeC<SimEventVisualCortexOutput> e = itsQ->check<SimEventVisualCortexOutput>(this))
00101     itsSalmap = e->vco();
00102 
00103   // return number of winners
00104   return itsTimes.size();
00105 }
00106 
00107 // ######################################################################
00108 const Image<float>& GetSaliency::getSalmap()
00109 { return itsSalmap; }
00110 
00111 // ######################################################################
00112 const std::vector<Point2D<int> >& GetSaliency::getCoords()
00113 { return itsCoords; }
00114 
00115 // ######################################################################
00116 const std::vector<SimTime>& GetSaliency::getTimes()
00117 { return itsTimes; }
00118 
00119 // ######################################################################
00120 const std::vector<subMap>& GetSaliency::getSubMaps()
00121 {
00122   // grab all the VisualCortex maps:
00123   rutz::shared_ptr<SimReqVCXmaps> vcxm(new SimReqVCXmaps(this));
00124   itsQ->request(vcxm); // VisualCortex is now filling-in the maps...
00125   rutz::shared_ptr<ChannelMaps> chm = vcxm->channelmaps();
00126 
00127   uint numSubmaps = chm->numSubmaps();
00128   Dims mapDims = chm->getMap().getDims();
00129   std::vector<subMap> theSubMaps(numSubmaps);
00130 
00131   for(uint i=0;i < numSubmaps; i++)
00132     {
00133       NamedImage<float> tempMap = chm->getRawCSmap(i);
00134       theSubMaps[i].itsSubMap = tempMap;  // conversion to Image
00135       theSubMaps[i].itsSubMapName = tempMap.name();
00136 
00137       if (theSubMaps[i].itsSubMap.getWidth() > mapDims.w())
00138         theSubMaps[i].itsSubMap = downSize(theSubMaps[i].itsSubMap, mapDims);
00139       else if (theSubMaps[i].itsSubMap.getWidth() < mapDims.w())
00140         theSubMaps[i].itsSubMap = rescale(theSubMaps[i].itsSubMap, mapDims);
00141     }
00142   itsSubMaps = theSubMaps;
00143   return itsSubMaps;
00144 }
00145 
00146 Image<float> GetSaliency::getVCXmap(const Image<PixRGB<byte> > &img)
00147 {
00148   SimStatus status = itsQ->evolve();
00149   if (status != SIM_CONTINUE) LFATAL("Quitting! Queue Status is %d", status);
00150 
00151   // Create a new Retina Image from the inputImage, and post it to the queue
00152   itsQ->post(rutz::make_shared(
00153         new SimEventRetinaImage(
00154           this,
00155           InputFrame(InputFrame::fromRgb(&img, itsQ->now())),
00156           Rectangle(Point2D<int>(0,0), img.getDims()),
00157           Point2D<int>(0,0)
00158           )
00159         )
00160       );
00161 
00162   Image<float> vcMap;
00163   //Get the raw, unnormalized visual cortex output map
00164   if (SeC<SimEventVisualCortexOutput> e = itsQ->check<SimEventVisualCortexOutput>(this, SEQ_ANY))
00165     vcMap = e->vco(1.0F);
00166 
00167 
00168   return vcMap;
00169 }
00170 
00171 
00172 
00173 // ######################################################################
00174 
00175 
00176 
00177 /* So things look consistent in everyone's emacs... */
00178 /* Local Variables: */
00179 /* indent-tabs-mode: nil */
00180 /* End: */
Generated on Sun May 8 08:05:24 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3