00001 /*!@file Parallel/pvisionTCP4.C A parallel vision slave to use w/ pvisionTCP4master */ 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/pvisionTCP4.C $ 00035 // $Id: $ 00036 // 00037 00038 /*! See the pvisionTCP4go script in bin/ for how to launch the slaves, and 00039 see pvisionTCP4-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("Frame %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 //LINFO("start"); 00156 00157 computeCMAP(previma, Gaussian5, 0.0, FWEIGHT, 1, beo, rframe); 00158 00159 //LINFO("end"); 00160 previma = fima; 00161 } 00162 break; 00163 case BEO_REDGREEN: // ############################## 00164 computeCMAP2(rmsg, Gaussian5, 0.0, CWEIGHT, 2, beo); 00165 break; 00166 case BEO_BLUEYELLOW: // ############################## 00167 computeCMAP2(rmsg, Gaussian5, 0.0, CWEIGHT, 3, beo); 00168 break; 00169 00170 case BEO_ORI0: // ############################## 00171 computeCMAP(rmsg, Oriented5, 0.0, OWEIGHT, 4, beo); 00172 break; 00173 case BEO_ORI15: // ############################## 00174 computeCMAP(rmsg, Oriented5, 15.0, OWEIGHT, 5, beo); 00175 break; 00176 case BEO_ORI30: // ############################## 00177 computeCMAP(rmsg, Oriented5, 30.0, OWEIGHT, 6, beo); 00178 break; 00179 case BEO_ORI45: // ############################## 00180 computeCMAP(rmsg, Oriented5, 45.0, OWEIGHT, 7, beo); 00181 break; 00182 case BEO_ORI60: // ############################## 00183 computeCMAP(rmsg, Oriented5, 60.0, OWEIGHT, 8, beo); 00184 break; 00185 case BEO_ORI75: // ############################## 00186 computeCMAP(rmsg, Oriented5, 75.0, OWEIGHT, 9, beo); 00187 break; 00188 case BEO_ORI90: // ############################## 00189 computeCMAP(rmsg, Oriented5, 90.0, OWEIGHT, 10, beo); 00190 break; 00191 case BEO_ORI105: // ############################## 00192 computeCMAP(rmsg, Oriented5, 105.0, OWEIGHT, 11, beo); 00193 break; 00194 case BEO_ORI120: // ############################## 00195 computeCMAP(rmsg, Oriented5, 120.0, OWEIGHT, 12, beo); 00196 break; 00197 case BEO_ORI135: // ############################## 00198 computeCMAP(rmsg, Oriented5, 135.0, OWEIGHT, 13, beo); 00199 break; 00200 case BEO_ORI150: // ############################## 00201 computeCMAP(rmsg, Oriented5, 150.0, OWEIGHT, 14, beo); 00202 break; 00203 case BEO_ORI165: // ############################## 00204 computeCMAP(rmsg, Oriented5, 165.0, OWEIGHT, 15, beo); 00205 break; 00206 default: // ############################## 00207 LERROR("Bogus action %d -- IGNORING.", raction); 00208 break; 00209 } 00210 //if (rframe % 101 == 0) 00211 LINFO("Action %d, frame %d processed in %llums", 00212 raction, rframe, tim.get()); 00213 } 00214 } 00215 00216 LINFO("done"); 00217 00218 // we got broken: 00219 manager.stop(); 00220 return 0; 00221 } 00222 00223 // ###################################################################### 00224 void computeCMAP(TCPmessage& msg, const PyramidType ptyp, 00225 const float ori, const float coeff, 00226 const int mapn, nub::soft_ref<Beowulf>& b) 00227 { 00228 //LINFO("bam"); 00229 Image<byte> ima = msg.getElementByteIma(); 00230 Image<float> fima = ima; // convert to float 00231 00232 computeCMAP(fima, ptyp, ori, coeff, mapn, b, msg.getID()); 00233 //LINFO("bam2"); 00234 } 00235 00236 // ###################################################################### 00237 void computeCMAP2(TCPmessage& msg, const PyramidType ptyp, 00238 const float ori, const float coeff, 00239 const int mapn, nub::soft_ref<Beowulf>& b) 00240 { 00241 Image<byte> ima1 = msg.getElementByteIma(); 00242 Image<byte> ima2 = msg.getElementByteIma(); 00243 Image<float> fima = ima1 - ima2; 00244 00245 computeCMAP(fima, ptyp, ori, coeff, mapn, b, msg.getID()); 00246 } 00247 00248 // ###################################################################### 00249 void computeCMAP(const Image<float>& fima, const PyramidType ptyp, 00250 const float ori, const float coeff, 00251 const int mapn, nub::soft_ref<Beowulf>& b, const int32 id) 00252 { 00253 //LINFO("here 1"); 00254 00255 // compute pyramid: 00256 ImageSet<float> pyr = buildPyrGeneric(fima, 0, maxdepth, ptyp, ori); 00257 00258 // alloc conspicuity map and clear it: 00259 Image<float> cmap(pyr[sml].getDims(), ZEROS); 00260 00261 //LINFO("here 2"); 00262 00263 // intensities is the max-normalized weighted sum of IntensCS: 00264 for (int delta = delta_min; delta <= delta_max; delta ++) 00265 for (int lev = level_min; lev <= level_max; lev ++) 00266 { 00267 Image<float> tmp = centerSurround(pyr, lev, lev + delta, true); 00268 tmp = downSize(tmp, cmap.getWidth(), cmap.getHeight()); 00269 inplaceAddBGnoise(tmp, 255.0); 00270 tmp = maxNormalize(tmp, MAXNORMMIN, MAXNORMMAX, normtyp); 00271 cmap += tmp; 00272 } 00273 if (normtyp == VCXNORM_MAXNORM) 00274 cmap = maxNormalize(cmap, MAXNORMMIN, MAXNORMMAX, normtyp); 00275 else 00276 cmap = maxNormalize(cmap, 0.0f, 0.0f, normtyp); 00277 00278 //LINFO("here 3"); 00279 00280 // multiply by conspicuity coefficient: 00281 cmap *= coeff; 00282 00283 // send off resulting conspicuity map to master: 00284 TCPmessage smsg(id, BEO_CMAP | (mapn << 16)); 00285 smsg.addImage(cmap); 00286 00287 //LINFO("here 4"); 00288 00289 // let's compute a crude estimate of our time to idle: 00290 int qlen = b->nbReceived(); // how many messages to process? 00291 smsg.setETI(float(qlen) * 0.005); // assume 5ms/message 00292 00293 // send off the result: 00294 b->send(-1, smsg); 00295 00296 //LINFO("here 5"); 00297 } 00298 00299 // ###################################################################### 00300 /* So things look consistent in everyone's emacs... */ 00301 /* Local Variables: */ 00302 /* indent-tabs-mode: nil */ 00303 /* End: */