pvisionTCP3.C

Go to the documentation of this file.
00001 /*!@file Parallel/pvisionTCP3.C A parallel vision slave to use w/ pvisionTCP3master */
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: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Parallel/pvisionTCP3.C $
00035 // $Id: pvisionTCP3.C 13086 2010-03-30 03:24:43Z beobot $
00036 //
00037 
00038 /*! See the pvisionTCP3go script in bin/ for how to launch the slaves, and
00039   see pvisionTCP3-master.C for the master program. */
00040 
00041 #include "Beowulf/Beowulf.H"
00042 #include "Component/ModelManager.H"
00043 #include "Image/ColorOps.H"
00044 #include "Image/Image.H"
00045 #include "Image/ImageSet.H"
00046 #include "Image/Pixels.H"
00047 #include "Image/PyramidOps.H"
00048 #include "Image/ShapeOps.H"
00049 #include "Image/Transforms.H"
00050 #include "Image/fancynorm.H"
00051 #include "Parallel/pvisionTCP-defs.H"
00052 #include "Util/Assert.H"
00053 #include "Util/Timer.H"
00054 #include "Util/Types.H"
00055 
00056 #include <signal.h>
00057 
00058 static bool goforever = true;  //!< Will turn false on interrupt signal
00059 
00060 //! Signal handler (e.g., for control-C)
00061 void terminate(int s) { LERROR("*** INTERRUPT ***"); goforever = false; }
00062 
00063 //! Compute a conspicuity map from an image received in a message
00064 void computeCMAP(TCPmessage& msg, const PyramidType ptyp,
00065                  const float ori, const float coeff,
00066                  const int slave, nub::soft_ref<Beowulf>& b);
00067 
00068 //! Compute a conspicuity map from two images received in a message
00069 void computeCMAP2(TCPmessage& msg, const PyramidType ptyp,
00070                  const float ori, const float coeff,
00071                  const int slave, nub::soft_ref<Beowulf>& b);
00072 
00073 //! Compute a conspicuity map from an image
00074 void computeCMAP(const Image<float>& fima, const PyramidType ptyp,
00075                  const float ori, const float coeff,
00076                  const int slave, nub::soft_ref<Beowulf>& b, const int32 id);
00077 
00078 // ######################################################################
00079 // ##### Global options:
00080 // ######################################################################
00081 #define sml        2
00082 #define delta_min  3
00083 #define delta_max  4
00084 #define level_min  0
00085 #define level_max  2
00086 #define maxdepth   (level_max + delta_max + 1)
00087 #define normtyp    (VCXNORM_MAXNORM)
00088 
00089 // relative feature weights:
00090 #define IWEIGHT 1.0
00091 #define CWEIGHT 1.0
00092 #define OWEIGHT 1.0
00093 #define FWEIGHT 1.5
00094 
00095 // ######################################################################
00096 int main(const int argc, const char **argv)
00097 {
00098   MYLOGVERB = LOG_INFO;
00099 
00100   // instantiate a model manager:
00101   ModelManager manager("Parallel Vision TCP Version 3 - Slave");
00102 
00103   // Instantiate our various ModelComponents:
00104   nub::soft_ref<Beowulf>
00105     beo(new Beowulf(manager, "Beowulf Slave", "BeowulfSlave", false));
00106   manager.addSubComponent(beo);
00107 
00108   // Parse command-line:
00109   if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00110 
00111   // setup signal handling:
00112   signal(SIGHUP, terminate); signal(SIGINT, terminate);
00113   signal(SIGQUIT, terminate); signal(SIGTERM, terminate);
00114   initRandomNumbers();
00115 
00116   // various processing inits:
00117   TCPmessage rmsg;            // message being received and to process
00118   TCPmessage smsg;            // message being sent
00119   Image<float> previma;       // previous image; for flicker processing
00120   Timer tim;                  // to measure processing speed
00121 
00122   // let's get all our ModelComponent instances started:
00123   manager.start();
00124 
00125   // wait for data and process it:
00126   while(goforever)
00127     {
00128       int32 rframe, raction, rnode = -1;  // receive from any node
00129       if (beo->receive(rnode, rmsg, rframe, raction, 3))  // wait up to 3ms
00130         {
00131           //LINFO("fFrame %d, action %d from node %d", rframe, raction, rnode);
00132           tim.reset();
00133 
00134           // select processing branch based on frame number:
00135           switch(raction)
00136             {
00137             case BEO_INIT:       // ##############################
00138               {
00139                 // ooops, someone wants to re-initialize us!
00140                 // reinitialization of beowulf is handled automatically.
00141               }
00142               break;
00143             case BEO_LUMINANCE:  // ##############################
00144               computeCMAP(rmsg, Gaussian5, 0.0, IWEIGHT, 0, beo);
00145               break;
00146             case BEO_FLICKER:   // ##############################
00147               {
00148                 // get the luminance image out of the message:
00149                 Image<byte> ima = rmsg.getElementByteIma();
00150                 Image<float> fima = ima;  // convert to float
00151 
00152                 // compute flicker consp map and send to collector:
00153                 if (previma.initialized() == false) previma = fima;
00154                 previma -= fima;
00155                 computeCMAP(previma, Gaussian5, 0.0, FWEIGHT, 1, beo, rframe);
00156                 previma = fima;
00157               }
00158               break;
00159             case BEO_REDGREEN:   // ##############################
00160               computeCMAP2(rmsg, Gaussian5, 0.0, CWEIGHT, 2, beo);
00161               break;
00162             case BEO_BLUEYELLOW: // ##############################
00163               computeCMAP2(rmsg, Gaussian5, 0.0, CWEIGHT, 3, beo);
00164               break;
00165             case BEO_ORI0:       // ##############################
00166               computeCMAP(rmsg, Oriented5, 0.0, OWEIGHT, 4, beo);
00167               break;
00168             case BEO_ORI45:      // ##############################
00169               computeCMAP(rmsg, Oriented5, 45.0, OWEIGHT, 5, beo);
00170               break;
00171             case BEO_ORI90:      // ##############################
00172               computeCMAP(rmsg, Oriented5, 90.0, OWEIGHT, 6, beo);
00173               break;
00174             case BEO_ORI135:     // ##############################
00175               computeCMAP(rmsg, Oriented5, 135.0, OWEIGHT, 7, beo);
00176               break;
00177             default: // ##############################
00178               LERROR("Bogus action %d -- IGNORING.", raction);
00179               break;
00180             }
00181           //if (rframe % 101 == 0)
00182             LINFO("Action %d, frame %d processed in %llums",
00183                   raction, rframe, tim.get());
00184         }
00185     }
00186 
00187   // we got broken:
00188   manager.stop();
00189   return 0;
00190 }
00191 
00192 // ######################################################################
00193 void computeCMAP(TCPmessage& msg, const PyramidType ptyp,
00194                  const float ori, const float coeff,
00195                  const int mapn, nub::soft_ref<Beowulf>& b)
00196 {
00197   Image<byte> ima = msg.getElementByteIma();
00198   Image<float> fima = ima; // convert to float
00199 
00200   computeCMAP(fima, ptyp, ori, coeff, mapn, b, msg.getID());
00201 }
00202 
00203 // ######################################################################
00204 void computeCMAP2(TCPmessage& msg, const PyramidType ptyp,
00205                  const float ori, const float coeff,
00206                  const int mapn, nub::soft_ref<Beowulf>& b)
00207 {
00208   Image<byte> ima1 = msg.getElementByteIma();
00209   Image<byte> ima2 = msg.getElementByteIma();
00210   Image<float> fima = ima1 - ima2;
00211 
00212   computeCMAP(fima, ptyp, ori, coeff, mapn, b, msg.getID());
00213 }
00214 
00215 // ######################################################################
00216 void computeCMAP(const Image<float>& fima, const PyramidType ptyp,
00217                  const float ori, const float coeff,
00218                  const int mapn, nub::soft_ref<Beowulf>& b, const int32 id)
00219 {
00220   // compute pyramid:
00221   ImageSet<float> pyr = buildPyrGeneric(fima, 0, maxdepth, ptyp, ori);
00222 
00223   // alloc conspicuity map and clear it:
00224   Image<float> cmap(pyr[sml].getDims(), ZEROS);
00225 
00226   // intensities is the max-normalized weighted sum of IntensCS:
00227   for (int delta = delta_min; delta <= delta_max; delta ++)
00228     for (int lev = level_min; lev <= level_max; lev ++)
00229       {
00230         Image<float> tmp = centerSurround(pyr, lev, lev + delta, true);
00231         tmp = downSize(tmp, cmap.getWidth(), cmap.getHeight());
00232         inplaceAddBGnoise(tmp, 255.0);
00233         tmp = maxNormalize(tmp, MAXNORMMIN, MAXNORMMAX, normtyp);
00234         cmap += tmp;
00235       }
00236   if (normtyp == VCXNORM_MAXNORM)
00237     cmap = maxNormalize(cmap, MAXNORMMIN, MAXNORMMAX, normtyp);
00238   else
00239     cmap = maxNormalize(cmap, 0.0f, 0.0f, normtyp);
00240 
00241   // multiply by conspicuity coefficient:
00242   cmap *= coeff;
00243 
00244   // send off resulting conspicuity map to master:
00245   TCPmessage smsg(id, BEO_CMAP | (mapn << 16));
00246   smsg.addImage(cmap);
00247 
00248   // let's compute a crude estimate of our time to idle:
00249   int qlen = b->nbReceived();  // how many messages to process?
00250   smsg.setETI(float(qlen) * 0.005); // assume 5ms/message
00251 
00252   // send off the result:
00253   b->send(-1, smsg);
00254 }
00255 
00256 // ######################################################################
00257 /* So things look consistent in everyone's emacs... */
00258 /* Local Variables: */
00259 /* indent-tabs-mode: nil */
00260 /* End: */
Generated on Sun May 8 08:41:08 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3