DisparityChannel.C

Go to the documentation of this file.
00001 /*!@file Channels/DisparityChannel.C */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the 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:
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Channels/DisparityChannel.C $
00035 // $Id: DisparityChannel.C 12074 2009-11-24 07:51:51Z itti $
00036 //
00037 
00038 #ifndef DISPARITYCHANNEL_C_DEFINED
00039 #define DISPARITYCHANNEL_C_DEFINED
00040 
00041 #include "Channels/DisparityChannel.H"
00042 
00043 #include "Image/CutPaste.H"
00044 #include "Image/MathOps.H"
00045 #include "Image/PyramidOps.H"
00046 #include "Util/sformat.H"
00047 
00048 // ######################################################################
00049 // DisparityChannel member definitions:
00050 // ######################################################################
00051 
00052 // ######################################################################
00053 DisparityChannel::DisparityChannel(OptionManager& mgr, const uint dIndex,
00054                                    const double ang, const double pha) :
00055   SingleChannel(mgr, "", "", DISPARITY, rutz::shared_ptr< PyrBuilder<float> >(NULL)),
00056   itsIndex("DisparityChannelIndex", this, dIndex),
00057   itsOrientation("DisparityChannelOrientation", this, ang),
00058   itsPhase("DisparityChannelPhase", this, pha)
00059 {
00060   //  itsNormalizeOutput.setVal(true);
00061 
00062   setDescriptiveName(sformat("Disparity(%d,%d)", int(ang), int(pha)));
00063   setTagName(sformat("d_%d", dIndex));
00064 }
00065 
00066 // ######################################################################
00067 DisparityChannel::~DisparityChannel()
00068 { }
00069 
00070 // ######################################################################
00071 void DisparityChannel::start1()
00072 {
00073   SingleChannel::start1();
00074 
00075   // initilialize the size of the disparity map
00076   depth = itsLevelSpec.getVal().maxDepth();
00077   dispMap.reset(depth);
00078 
00079 }
00080 
00081 // ######################################################################
00082 double DisparityChannel::angle() const
00083 {
00084   return itsOrientation.getVal();
00085 }
00086 
00087 // ######################################################################
00088 double DisparityChannel::phase() const
00089 {
00090   return itsPhase.getVal();
00091 }
00092 
00093 // ######################################################################
00094 void DisparityChannel::setRawFilteredImages(Image<float> ***fImgLE,
00095                                             Image<float> ***fImgRI)
00096 {
00097   fImgL = fImgLE;
00098   fImgR = fImgRI;
00099 }
00100 
00101 // ######################################################################
00102 void DisparityChannel::getRawFilteredImages(Image<float> ****fImgLE,
00103                                             Image<float> ****fImgRI)
00104 {
00105   *fImgLE = fImgL;
00106   *fImgRI = fImgR;
00107 }
00108 
00109 // ######################################################################
00110 void DisparityChannel::getDispMap(ImageSet<float> *dMap)
00111 {
00112   *dMap = dispMap;
00113 }
00114 
00115 // ######################################################################
00116 void DisparityChannel::normalizeDispMap(ImageSet<float> tDispMap, int nChan)
00117 {
00118   float min,max;
00119   for(uint d = 0; d < depth; d++)
00120     {
00121       dispMap[d] /= tDispMap[d];
00122       getMinMax(dispMap[d], min,max);
00123       LINFO("MIN:%f, MAX:%f\n\n\n",min,max);
00124 
00125       // FIXME: get the numer of channels from the
00126       dispMap[d] -= (float)(1.0F/(float)(nChan));
00127       getMinMax(dispMap[d], min,max);
00128       LINFO("-- MIN:%f, MAX:%f\n\n\n",min,max);
00129       inplaceRectify(dispMap[d]);
00130       getMinMax(dispMap[d], min,max);
00131       LINFO("RR MIN:%f, MAX:%f\n\n\n",min,max);
00132     }
00133 }
00134 
00135 // ######################################################################
00136 void DisparityChannel::setNumPhase(int n)
00137 {
00138   nPhase = n;
00139 }
00140 
00141 // ######################################################################
00142 void DisparityChannel::setNumTheta(int t)
00143 {
00144   nTheta = t;
00145 }
00146 
00147 // ######################################################################
00148 void DisparityChannel::doInput(const InputFrame& inframe)
00149 {
00150   // for now only evaluate the horizontal disparity
00151   // and make sure the phase is normalized to 0 to 360
00152   //int t  = 0; //(int)(round((itsOrientation.getVal()/180.0)*nTheta));
00153   //int dp = (int)(round((itsPhase.getVal()/360.0)*nPhase));
00154   float dt = 1.2;//itsPhase.getVal();
00155   if(itsPhase.getVal() > 180.0) dt = -1.2;//dt -= 360.0;
00156   if(itsPhase.getVal() == 0.0) dt = 0.0;
00157   float  dx = dt;
00158   //float dx = period * dt/360.0;
00159   //printf("dx = %f \n",dx);
00160 
00161   int width  = fImgL[0][0][0].getWidth();
00162   int height = fImgL[0][0][0].getHeight();
00163 
00164   Image<float> sumL(width,height,ZEROS);
00165   Image<float> sumR(width,height,ZEROS);
00166 
00167   for(uint d = 0; d < 1; d++)
00168   {
00169     dispMap[d].resize(width,height,true);
00170     /*
00171     // add the phase shift portion
00172     for(int p = 0; p < nPhase; p++)
00173       dispMap[d] +=
00174        fImgL[d][0][p] * fImgR[d][0][(p+dp)%nPhase];
00175     */
00176 
00177     //int t = 0;
00178     // add the position shift portion
00179     // the equation is already derived
00180     for(uint t = 0; t < nTheta; t++)
00181       for(uint p = 0; p < nPhase; p++)
00182       {
00183         Image<float> tmp =
00184           fImgL[d][t][p] * shiftImage(fImgR[d][t][p],dx,0);
00185         inplaceRectify(tmp);
00186         dispMap[d] += squared(tmp);
00187      }
00188 
00189     if(width  > 1) width  /= 2;
00190     if(height > 1) height /= 2;
00191 
00192   }
00193 
00194   // build the feature map pyramid and store it
00195   dispMap = buildPyrGaussian((dispMap[0]),0,depth,5);
00196   SingleChannel::storePyramid(dispMap,inframe.time());
00197 }
00198 
00199 // store the disparity map as feature map
00200 void DisparityChannel::storePyramid(const SimTime& t)
00201 {
00202   SingleChannel::storePyramid(dispMap, t);
00203 }
00204 
00205 
00206 // ######################################################################
00207 /* So things look consistent in everyone's emacs... */
00208 /* Local Variables: */
00209 /* indent-tabs-mode: nil */
00210 /* End: */
00211 
00212 #endif // DISPARITYCHANNEL_C_DEFINED
Generated on Sun May 8 08:04:34 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3