/** * @file SemSegContextTree.h * @brief Context Trees -> Combination of decision tree and context information * @author Björn Fröhlich * @date 29.11.2011 */ #ifndef SemSegContextTreeINCLUDE #define SemSegContextTreeINCLUDE #include "SemanticSegmentation.h" #include #include "objrec/features/localfeatures/LFColorWeijer.h" namespace OBJREC { /** Localization system */ class SemSegContextTree : public SemanticSegmentation { protected: class Node { public: /** probabilities for each class */ vector probs; /** left child node */ int left; /** right child node */ int right; /** position of feat for decision */ int feat; /** decision stamp */ double decision; /** is the node a leaf or not */ bool isleaf; /** distribution in current node */ vector dist; /** depth of the node in the tree */ int depth; /** simple constructor */ Node():left(-1),right(-1),feat(-1), decision(-1.0), isleaf(false){} /** standard constructor */ Node(int _left, int _right, int _feat, double _decision):left(_left),right(_right),feat(_feat), decision(_decision),isleaf(false){} }; class Operation { public: virtual double getVal(const double &v1, const double &v2) = 0; }; class Minus:public Operation { public: virtual double getVal(const double &v1, const double &v2) { return v1-v2; } }; class MinusAbs:public Operation { public: virtual double getVal(const double &v1, const double &v2) { return abs(v1-v2); } }; class Addition:public Operation { public: virtual double getVal(const double &v1, const double &v2) { return v1+v2; } }; class Only1:public Operation { public: virtual double getVal(const double &v1, const double &v2) { return v1; } }; /** store features */ VVector currentfeats; /** store the positions of the features */ VVector positions; /** tree -> saved as vector of nodes */ vector tree; /** local features */ LFColorWeijer *lfcw; /** distance between features */ int grid; /** maximum samples for tree */ int maxSamples; /** size for neighbourhood */ int windowSize; /** how many feats should be considered for a split */ int featsPerSplit; /** count samples per label */ map labelcounter; /** map of labels */ map labelmap; /** map of labels inverse*/ map labelmapback; /** scalefactor for balancing for each class */ vector a; /** the minimum number of features allowed in a leaf */ int minFeats; /** maximal depth of tree */ int maxDepth; /** operations for pairwise features */ vector ops; /** number of possible features */ int allfeatsize; /** vector of all possible features */ vector > featsel; public: /** simple constructor */ SemSegContextTree( const Config *conf, const MultiDataset *md ); /** simple destructor */ virtual ~SemSegContextTree(); /** * test a single image * @param ce input data * @param segresult segmentation results * @param probabilities probabilities for each pixel */ void semanticseg ( CachedExample *ce, NICE::Image & segresult, GenericImage & probabilities ); /** * the main training method * @param md training data */ void train ( const MultiDataset *md ); /** * compute best split for current settings * @param feats features * @param currentfeats matrix with current node for each feature * @param labels labels for each feature * @param node current node * @param splitfeat output feature position * @param splitval */ void getBestSplit(const vector > > > &feats, vector > > ¤tfeats,const vector > > &labels, int node, int &splitfeat, double &splitval); }; } // namespace #endif