00001 /*!@file Channels/MultiSpectralResidualChannel.C A complex channel holding several spectral residual sub-channels */ 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: Rob Peters <rjpeters at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Channels/MultiSpectralResidualChannel.C $ 00035 // $Id: MultiSpectralResidualChannel.C 9356 2008-03-01 01:25:05Z rjpeters $ 00036 // 00037 00038 #ifndef CHANNELS_MULTISPECTRALRESIDUALCHANNEL_C_DEFINED 00039 #define CHANNELS_MULTISPECTRALRESIDUALCHANNEL_C_DEFINED 00040 00041 #include "Channels/MultiSpectralResidualChannel.H" 00042 00043 #include "Channels/ChannelOpts.H" 00044 #include "Channels/SpectralResidualChannel.H" 00045 #include "Component/ModelOptionDef.H" 00046 #include "Image/LowPass.H" 00047 #include "Image/ShapeOps.H" 00048 #include "Util/StringUtil.H" 00049 #include "Util/sformat.H" 00050 00051 #include <iterator> 00052 00053 static const ModelOptionDef OPT_MultiSpectralResidualSizes = 00054 { MODOPT_ARG_STRING, "MultiSpectralResidualSizes", &MOC_CHANNEL, OPTEXP_CORE, 00055 "A comma-separated list of dimensions for each of the spectral residual " 00056 "subchannels in a multi-spectral residual channel", 00057 "multi-srs-sizes", '\0', "w1xh1,w2xh2,w3xh3,...", 00058 "64x64,128x128,256x256,512x512" }; 00059 00060 00061 // ###################################################################### 00062 MultiSpectralResidualChannel:: 00063 MultiSpectralResidualChannel(OptionManager& mgr) 00064 : 00065 ComplexChannel(mgr, "Multi-Spectral Residual Channel", 00066 "MultiSpectralResidualChannel", UNKNOWN), 00067 itsSizesString(&OPT_MultiSpectralResidualSizes, this), 00068 itsDownSizeFilterWidth(&OPT_SpectralResidualChannelDownSizeFilterWidth, this), 00069 itsDoOutputResize(&OPT_SpectralResidualChannelOutputResize, this) 00070 { 00071 this->buildSubChans(); 00072 } 00073 00074 // ###################################################################### 00075 MultiSpectralResidualChannel::~MultiSpectralResidualChannel() 00076 {} 00077 00078 // ###################################################################### 00079 void MultiSpectralResidualChannel:: 00080 paramChanged(ModelParamBase* const param, 00081 const bool valueChanged, 00082 ParamClient::ChangeStatus* status) 00083 { 00084 if (param == &itsSizesString) 00085 { 00086 std::vector<std::string> sizestrings; 00087 split(itsSizesString.getVal(), ",", std::back_inserter(sizestrings)); 00088 00089 if (sizestrings.size() == 0) 00090 LFATAL("Expected at least one Dims value in --%s, but got \"%s\"", 00091 itsSizesString.getOptionDef()->longoptname, 00092 itsSizesString.getVal().c_str()); 00093 00094 itsResizeSpecs.resize(0); 00095 for (size_t i = 0; i < sizestrings.size(); ++i) 00096 itsResizeSpecs.push_back(fromStr<ResizeSpec>(sizestrings[i])); 00097 00098 this->buildSubChans(); 00099 } 00100 } 00101 00102 // ###################################################################### 00103 void MultiSpectralResidualChannel::doInput(const InputFrame& inframe) 00104 { 00105 ASSERT(inframe.grayFloat().initialized()); 00106 00107 for (uint i = 0; i < numChans(); ++i) 00108 subChan(i)->input(inframe); 00109 } 00110 00111 // ###################################################################### 00112 void MultiSpectralResidualChannel::buildSubChans() 00113 { 00114 this->removeAllSubChans(); 00115 00116 rutz::shared_ptr<SpectralResidualChannel::Downsizer> dx0; 00117 00118 for (size_t i = 0; i < itsResizeSpecs.size(); ++i) 00119 { 00120 nub::ref<SpectralResidualChannel> chan 00121 (new SpectralResidualChannel 00122 (this->getManager(), 00123 sformat("Spectral Residual (%s)", 00124 itsResizeSpecs[i].toString().c_str()), 00125 sformat("srs_%"ZU, i))); 00126 00127 // make all the channels share the same downsizer 00128 if (i == 0) 00129 { 00130 dx0 = chan->getDownsizer(); 00131 ASSERT(dx0.get() != 0); 00132 } 00133 else 00134 chan->setDownsizer(dx0); 00135 00136 this->addSubChan(chan); 00137 00138 chan->exportOptions(MC_RECURSE); 00139 00140 chan->setResizeSpec(itsResizeSpecs[i]); 00141 00142 // we need all the subchannels to have the same output-resize 00143 // spec; this can happen two ways: (1) the user gives 00144 // --srs-output-resize and --srs-output-resize-spec=<foo> on the 00145 // command-line, in which case we're all set; or (2) if the user 00146 // specifies nothing then we force all the subchannels to have 00147 // an output-resize spec equivalent to chan[0]'s INPUT-resize 00148 // spec 00149 if (!itsDoOutputResize.getVal()) 00150 chan->setOutputResizeSpec(true, itsResizeSpecs[0]); 00151 00152 LINFO("created %s with input resize %s, output blur %f, " 00153 "output resize %s", 00154 chan->descriptiveName().c_str(), 00155 chan->getResizeSpec().toString().c_str(), 00156 chan->getOutputBlur(), 00157 convertToString(chan->getOutputResizeSpec()).c_str()); 00158 } 00159 } 00160 00161 // ###################################################################### 00162 /* So things look consistent in everyone's emacs... */ 00163 /* Local Variables: */ 00164 /* mode: c++ */ 00165 /* indent-tabs-mode: nil */ 00166 /* End: */ 00167 00168 #endif // CHANNELS_MULTISPECTRALRESIDUALCHANNEL_C_DEFINED