MultiSpectralResidualChannel.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
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
00143
00144
00145
00146
00147
00148
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
00163
00164
00165
00166
00167
00168 #endif // CHANNELS_MULTISPECTRALRESIDUALCHANNEL_C_DEFINED