ColorChannel.C

Go to the documentation of this file.
00001 /*!@file Channels/ColorChannel.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/ColorChannel.C $
00035 // $Id: ColorChannel.C 8210 2007-03-31 00:21:06Z rjpeters $
00036 //
00037 
00038 #ifndef COLORCHANNEL_C_DEFINED
00039 #define COLORCHANNEL_C_DEFINED
00040 
00041 #include "Channels/ColorChannel.H"
00042 
00043 #include "Channels/BlueYellowChannel.H"
00044 #include "Channels/YellowBlueChannel.H"
00045 #include "Channels/ChannelOpts.H"
00046 #include "Channels/RedGreenChannel.H"
00047 #include "Channels/GreenRedChannel.H"
00048 #include "Component/OptionManager.H"
00049 #include "Image/ColorOps.H"
00050 #include "rutz/trace.h"
00051 
00052 // ######################################################################
00053 // Double Opponent ColorChannel member definitions:
00054 // ######################################################################
00055 
00056 ColorChannel::ColorChannel(OptionManager& mgr) :
00057   ComplexChannel(mgr, "Color", "color", COLOR),
00058   itsLumThresh("ColorChannelLuminanceThreshold", this, 25.5F),
00059   itsMethod(&OPT_ColorComputeType, this)
00060 {
00061 GVX_TRACE(__PRETTY_FUNCTION__);
00062 
00063   itsRG = nub::soft_ref<RedGreenChannel>(new RedGreenChannel(getManager(), true));
00064   itsBY = nub::soft_ref<BlueYellowChannel>(new BlueYellowChannel(getManager(), true));
00065 
00066   this->addSubChan(itsRG);
00067   this->addSubChan(itsBY);
00068 }
00069 
00070 // ######################################################################
00071 void ColorChannel::paramChanged(ModelParamBase* const param,
00072                                 const bool valueChanged,
00073                                 ParamClient::ChangeStatus* status)
00074 {
00075   ComplexChannel::paramChanged(param, valueChanged, status);
00076 
00077   // if the param has become different from our number of channels,
00078   // let's reconfigure:
00079   if (param == &itsMethod && valueChanged)
00080   {
00081     switch(itsMethod.getVal())
00082     {
00083       case COLstandardFull:
00084         {
00085           LINFO("Rebuilding Color Channels");
00086           //remove the old channels
00087           this->removeAllSubChans();
00088 
00089           //rebuild the channels without taking the abs value
00090           itsRG = nub::soft_ref<RedGreenChannel>(new RedGreenChannel(getManager(), false));
00091           itsGR = nub::soft_ref<GreenRedChannel>(new GreenRedChannel(getManager(), false));
00092           itsBY = nub::soft_ref<BlueYellowChannel>(new BlueYellowChannel(getManager(), false));
00093           itsYB = nub::soft_ref<YellowBlueChannel>(new YellowBlueChannel(getManager(), false));
00094 
00095           this->addSubChan(itsRG);
00096           this->addSubChan(itsGR);
00097           this->addSubChan(itsBY);
00098           this->addSubChan(itsYB);
00099         }
00100       default:
00101         break;
00102     }
00103 
00104   }
00105 
00106 }
00107 
00108 // ######################################################################
00109 RedGreenChannel& ColorChannel::rg() const
00110 {
00111 GVX_TRACE(__PRETTY_FUNCTION__);
00112   return *itsRG;
00113 }
00114 
00115 // ######################################################################
00116 BlueYellowChannel& ColorChannel::by() const
00117 {
00118 GVX_TRACE(__PRETTY_FUNCTION__);
00119   return *itsBY;
00120 }
00121 
00122 // ######################################################################
00123 GreenRedChannel& ColorChannel::gr() const
00124 {
00125 GVX_TRACE(__PRETTY_FUNCTION__);
00126   return *itsGR;
00127 }
00128 
00129 // ######################################################################
00130 YellowBlueChannel& ColorChannel::yb() const
00131 {
00132 GVX_TRACE(__PRETTY_FUNCTION__);
00133   return *itsYB;
00134 }
00135 
00136 // ######################################################################
00137 ColorChannel::~ColorChannel()
00138 {
00139 GVX_TRACE(__PRETTY_FUNCTION__);
00140 }
00141 
00142 // ######################################################################
00143 void ColorChannel::doInput(const InputFrame& inframe)
00144 {
00145 GVX_TRACE(__PRETTY_FUNCTION__);
00146   Image<float> rgimg, byimg;
00147 
00148   switch(itsMethod.getVal())
00149     {
00150     case COLstandard:
00151       ASSERT(inframe.colorByte().initialized());
00152       LINFO("Using 'standard' method to compute color opponencies.");
00153       getRGBY(inframe.colorByte(), rgimg, byimg, itsLumThresh.getVal());
00154       break;
00155 
00156     case COLstandardFull:
00157       {
00158         ASSERT(inframe.colorFloat().initialized());
00159 
00160         LINFO("Using 'standard Full' method to compute color opponencies.");
00161         Image<float> grimg, ybimg;
00162         Image<float> r,g,b,y;
00163         getRGBY(inframe.colorFloat(), r, g, b, y, itsLumThresh.getVal());
00164         rgimg = r-g; grimg = g - r;
00165         byimg = b-y; ybimg = y - b;
00166         itsGR->input(InputFrame::fromGrayFloat
00167                      (&grimg, inframe.time(), &inframe.clipMask(), inframe.pyrCache()));
00168         itsYB->input(InputFrame::fromGrayFloat
00169                      (&ybimg, inframe.time(), &inframe.clipMask(), inframe.pyrCache()));
00170       }
00171       break;
00172 
00173     case COLsimple:
00174       ASSERT(inframe.colorByte().initialized());
00175       LINFO("Using 'simple' method to compute color opponencies.");
00176       getRGBYsimple(inframe.colorByte(), rgimg, byimg, itsLumThresh.getVal());
00177       break;
00178 
00179     default:
00180       LFATAL("Unknown ColorComputeType!");
00181       break;
00182     }
00183 
00184 
00185   itsRG->input(InputFrame::fromGrayFloat(&rgimg, inframe.time(), &inframe.clipMask(), inframe.pyrCache()));
00186   itsBY->input(InputFrame::fromGrayFloat(&byimg, inframe.time(), &inframe.clipMask(), inframe.pyrCache()));
00187   LINFO("Double Opponent Color channel ok.");
00188 }
00189 
00190 // ######################################################################
00191 void ColorChannel::setRG(nub::ref<RedGreenChannel> rg)
00192 {
00193   this->removeSubChan(itsRG);
00194   itsRG = rg;
00195   this->addSubChan(itsRG);
00196 }
00197 
00198 // ######################################################################
00199 void ColorChannel::setBY(nub::ref<BlueYellowChannel> by)
00200 {
00201   this->removeSubChan(itsBY);
00202   itsBY = by;
00203   this->addSubChan(itsBY);
00204 }
00205 
00206 // ######################################################################
00207 void ColorChannel::setGR(nub::ref<GreenRedChannel> gr)
00208 {
00209   this->removeSubChan(itsGR);
00210   itsGR = gr;
00211   this->addSubChan(itsGR);
00212 }
00213 
00214 // ######################################################################
00215 void ColorChannel::setYB(nub::ref<YellowBlueChannel> yb)
00216 {
00217   this->removeSubChan(itsYB);
00218   itsYB = yb;
00219   this->addSubChan(itsYB);
00220 }
00221 
00222 // ######################################################################
00223 /* So things look consistent in everyone's emacs... */
00224 /* Local Variables: */
00225 /* indent-tabs-mode: nil */
00226 /* End: */
00227 
00228 #endif // COLORCHANNEL_C_DEFINED
Generated on Sun May 8 08:04:34 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3