SingleChannel.H
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 SINGLECHANNEL_H_DEFINED
00039 #define SINGLECHANNEL_H_DEFINED
00040
00041 #include "Channels/ChannelBase.H"
00042 #include "Channels/ChannelFacet.H"
00043 #include "Channels/InputHandler.H"
00044 #include "Channels/SubmapAlgorithm.H"
00045 #include "Component/ModelParam.H"
00046 #include "Image/ImageSet.H"
00047 #include "Image/LevelSpec.H"
00048 #include "Image/PyrBuilder.H"
00049 #include "Image/fancynorm.H"
00050 #include "Util/SimTime.H"
00051 #include "rutz/shared_ptr.h"
00052 #include <deque>
00053
00054
00055
00056
00057
00058 class SingleChannel : public ChannelBase, public ChannelFacetMap
00059 {
00060 public:
00061
00062
00063
00064
00065
00066
00067 SingleChannel(OptionManager& mgr, const std::string& descrName,
00068 const std::string& tagName, const VisualFeature vs,
00069 rutz::shared_ptr<PyrBuilder<float> > pyr);
00070
00071
00072 virtual ~SingleChannel();
00073
00074
00075
00076 virtual void reset1();
00077
00078
00079 virtual void accept(ChannelVisitor& v);
00080
00081
00082 virtual void paramChanged(ModelParamBase* const param,
00083 const bool valueChanged,
00084 ParamClient::ChangeStatus* status);
00085
00086
00087 void inputPyramid(const ImageSet<float>& pyramid, const SimTime& t,
00088 const Image<byte>& clipMask = Image<byte>());
00089
00090
00091 virtual ImageSet<float> computePyramid(const Image<float>& bwimg,
00092 const rutz::shared_ptr<PyramidCache<float> >& cache);
00093
00094 virtual void readFrom(const ParamMap& pmap);
00095
00096 virtual void writeTo(ParamMap& pmap) const;
00097
00098
00099 void setTempl(const uint cntr, const uint surr, Image<float> &templ);
00100
00101
00102 void setBiasMask(Image<float> &biasMask);
00103
00104
00105 Image<float> getBiasMask() const;
00106
00107
00108 Image<float> getTempl(const uint cntr, const uint surr) const;
00109
00110 virtual bool outputAvailable() const;
00111
00112
00113 bool hasPyramid() const;
00114
00115
00116 bool hasOutputCache() const;
00117
00118 virtual Dims getMapDims() const;
00119
00120
00121 virtual const Image<float>& getImage(const uint lev) const;
00122
00123
00124 virtual Image<float> centerSurround(const uint cntr, const uint surr) const;
00125
00126
00127 virtual void centerSurround(const uint cntr, const uint surr,
00128 Image<float>& pos, Image<float>& neg) const;
00129
00130 virtual uint numSubmaps() const;
00131
00132
00133 virtual Image<float> getSubmap(const uint index) const;
00134
00135 virtual std::string getSubmapName(const uint index) const;
00136
00137 virtual std::string getSubmapNameShort(const uint index) const;
00138
00139 virtual void getFeatures(const Point2D<int>& locn,
00140 std::vector<float>& mean) const;
00141
00142 virtual void getFeaturesBatch(std::vector<Point2D<int>*> *locn,
00143 std::vector<std::vector<float> > *mean,
00144 int *count) const;
00145
00146
00147 void saveStats(const Image<float> img, const short idx);
00148
00149
00150 virtual Image<float> getOutput();
00151
00152
00153 virtual Image<float> combineSubMaps();
00154
00155
00156
00157
00158
00159
00160 virtual void saveResults(const nub::ref<FrameOstream>& ofs);
00161
00162
00163 size_t numPyramids() const;
00164
00165
00166
00167
00168
00169
00170 const ImageSet<float>& pyramid(const uint index) const;
00171
00172
00173
00174
00175
00176
00177 SimTime pyramidTime(const uint index) const;
00178
00179
00180 const ImageSet<float>& clipPyramid() const;
00181
00182
00183 virtual LevelSpec getLevelSpec() const;
00184
00185
00186 int getNormType() const;
00187
00188
00189 virtual void killCaches();
00190
00191
00192 struct TPyr
00193 {
00194 TPyr(const ImageSet<float>& pyr_, const SimTime t_)
00195 : pyr(pyr_), t(t_) {}
00196 ImageSet<float> pyr;
00197 SimTime t;
00198 };
00199
00200
00201 void storeOutputCache(const Image<float>& m);
00202
00203
00204 virtual void storePyramid(const ImageSet<float>& p, const SimTime& t);
00205
00206
00207 void storeClipPyramid(const ImageSet<float>& p);
00208
00209
00210 virtual void setClipPyramid(const Image<byte>& clipMask);
00211
00212
00213 void storeSubmapCache(const ImageSet<float>& p);
00214
00215
00216 void setInputHandler(rutz::shared_ptr<InputHandler> h);
00217
00218
00219 rutz::shared_ptr<InputHandler> cloneInputHandler() const;
00220
00221
00222 virtual Image<float> getRawCSmap(const uint idx) const;
00223
00224
00225 Image<float> postProcessMap(const Image<float>& smap,
00226 const uint idx) const;
00227
00228
00229 void setSubmapAlgorithm(nub::ref<SubmapAlgorithm> algo);
00230
00231 void setComputeFullPyramid(bool v)
00232 { itsComputeFullPyramid.setVal(v); }
00233
00234 virtual int getMinPyrLevel() const
00235 {
00236
00237
00238
00239
00240 return (itsSaveRawMaps.getVal() || itsComputeFullPyramid.getVal() ||
00241 itsComputeFullPyramidForGist.getVal() ) ? 0 : itsLevelSpec.getVal().levMin();
00242 }
00243
00244 virtual int getMaxPyrLevel() const { return itsLevelSpec.getVal().maxDepth(); }
00245
00246 protected:
00247
00248 virtual void doInput(const InputFrame& inframe);
00249
00250
00251 void setPyramid(rutz::shared_ptr<PyrBuilder<float> > pyr);
00252
00253
00254 ImageSet<float>& pyrMut(const uint index);
00255
00256 NModelParam<bool> itsTakeAbs;
00257 NModelParam<bool> itsNormalizeOutput;
00258 NModelParam<bool> itsScaleNoiseToMax;
00259 NModelParam<float> itsLowThresh;
00260 NModelParam<bool> itsRectifyPyramid;
00261 NModelParam<bool> itsComputeFullPyramid;
00262
00263 OModelParam<bool> itsUseRandom;
00264 OModelParam<bool> itsUseSplitCS;
00265 OModelParam<LevelSpec> itsLevelSpec;
00266 OModelParam<MaxNormType> itsNormType;
00267 OModelParam<int> itsQlen;
00268 OModelParam<bool> itsUseOlderVersion;
00269
00270
00271
00272
00273
00274 OModelParam<double> itsTimeDecay;
00275
00276
00277 OModelParam<bool> itsSaveRawMaps;
00278
00279
00280 OModelParam<bool> itsComputeFullPyramidForGist;
00281
00282
00283 OModelParam<bool> itsSaveFeatureMaps;
00284
00285
00286 OModelParam<bool> itsSaveOutputMap;
00287
00288
00289 OModelParam<std::string> itsSubmapAlgoType;
00290
00291
00292 OModelParam<bool> itsGetSingleChannelStats;
00293
00294
00295 OModelParam<bool> itsSaveStatsPerChannel;
00296
00297
00298 OModelParam<bool> itsSaveStatsPerChannelFreq;
00299
00300
00301 OModelParam<std::string> itsGetSingleChannelStatsFile;
00302
00303
00304 OModelParam<std::string> itsGetSingleChannelStatsTag;
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 OModelParam<float> itsOutputRangeMin;
00316 OModelParam<float> itsOutputRangeMax;
00317
00318
00319
00320
00321 virtual void start1();
00322
00323
00324
00325
00326 virtual void stop2();
00327
00328
00329 virtual uint csToIndex(uint centerlev, uint surroundlev) const;
00330
00331
00332 virtual void indexToCS(const uint index, uint& centerlev, uint& surroundlev) const;
00333
00334
00335 virtual uint maxIndex() const;
00336
00337 private:
00338 SingleChannel(const SingleChannel&);
00339 SingleChannel& operator=(const SingleChannel&);
00340
00341 std::deque<TPyr> itsPq;
00342 Image<float> itsBiasMask;
00343
00344 uint itsFrameIdx;
00345 Image<float> itsOutputCache;
00346 Image<float>* itsSubmapCache;
00347 ImageSet<float> itsTempl;
00348 rutz::shared_ptr<PyrBuilder<float> > itsPyrBuilder;
00349 ImageSet<float> itsClipPyr;
00350 rutz::shared_ptr<InputHandler> itsInputHandler;
00351 nub::ref<SubmapAlgorithm> itsSubmapAlgo;
00352
00353 friend class OrientationChannel;
00354 friend class RGBConvolveChannel;
00355 };
00356
00357
00358
00359
00360
00361
00362
00363 #endif // !SINGLECHANNEL_H_DEFINED