123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- /**
- * @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
- // nice-core includes
- #include <core/vector/VVector.h>
- // nice-vislearning includes
- #include <vislearning/features/localfeatures/LocalFeatureColorWeijer.h>
- #include <vislearning/classifier/fpclassifier/gphik/FPCGPHIK.h>
- // nice-segmentation includes
- #include <segmentation/RegionSegmentationMethod.h>
- // nice-semseg includes
- #include "semseg/semseg/operations/Operations.h"
- #include "SemanticSegmentation.h"
- namespace OBJREC {
- /** Localization system */
- class SemSegContextTree : public SemanticSegmentation
- {
- /** Segmentation Method */
- RegionSegmentationMethod *segmentation;
- /** tree -> saved as vector of nodes */
- std::vector<std::vector<TreeNode> > forest;
- /** local features */
- LocalFeatureColorWeijer *lfcw;
- /** number of featuretype -> currently: local and context features = 2 */
- int ftypes;
- /** 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 */
- std::map<int, int> labelcounter;
- /** map of labels */
- std::map<int, int> labelmap;
- /** map of labels inverse*/
- std::map<int, int> labelmapback;
- /** scalefactor for balancing for each class */
- std::vector<double> a;
- /** counter for used operations */
- std::vector<int> opOverview;
- /** relative use of context vs raw features per tree level*/
- std::vector<std::vector<double> > contextOverview;
- /** the minimum number of features allowed in a leaf */
- int minFeats;
- /** maximal depth of tree */
- int maxDepth;
- /** current depth for training */
- int depth;
- /** how many splittests */
- int randomTests;
- /** operations for pairwise features */
- std::vector<std::vector<Operation*> > ops;
- std::vector<ValueAccess*> calcVal;
- /** use alternative calculation for information gain */
- bool useShannonEntropy;
- /** Classnames */
- ClassNames classnames;
- /** train selection */
- std::set<int> forbidden_classes;
- /** Configfile */
- const NICE::Config *conf;
- /** use pixelwise labeling or regionlabeling with additional segmenation */
- bool pixelWiseLabeling;
- /** Number of trees used for the forest */
- int nbTrees;
-
- /** use Gradient image or not */
- bool useGradient;
-
- /** use Color features from van de Weijer or not */
- bool useWeijer;
-
- /** use Regions as extra feature channel or not */
- bool useRegionFeature;
-
- /** use external image categorization to avoid some classes */
- bool useCategorization;
-
- /** categorization information for external categorization */
- std::string cndir;
- /** how to handle each channel
- * 0: simple grayvalue features
- * 1: which pixel belongs to which region
- * 2: graycolor integral images
- * 3: context integral images
- * 4: context features (not in MultiChannelImageT encoded)
- */
- std::vector<int> channelType;
- /** list of channels per feature type */
- std::vector<std::vector<int> > channelsPerType;
-
- /** whether we should use the geometric features of Hoeim (only offline computation with MATLAB supported) */
- bool useHoiemFeatures;
- /** directory of the geometric features */
- std::string hoiemDirectory;
-
- /** first iteration or not */
- bool firstiteration;
-
- /** which IntegralImage channel belongs to which raw value channel */
- std::vector<std::pair<int, int> > integralMap;
-
- /** amount of grayvalue Channels */
- int rawChannels;
-
- /** classifier for categorization */
- OBJREC::FPCGPHIK *fasthik;
-
- /** unique numbers for nodes */
- int uniquenumber;
- public:
- /** simple constructor */
- SemSegContextTree ( const NICE::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::ImageT<int> & segresult, NICE::MultiChannelImageT<double> & probabilities );
- /**
- * the main training method
- * @param md training data
- */
- void train ( const MultiDataset *md );
- /**
- * @brief computes integral image of given feats
- *
- * @param currentfeats input features
- * @param integralImage output image (must be initilized)
- * @return void
- **/
- void computeIntegralImage ( const NICE::MultiChannelImageT<unsigned short int> ¤tfeats, NICE::MultiChannelImageT<double> &lfeats,int firstChannel );
- /**
- * @brief reads image and does some simple convertions
- *
- * @param feats output image
- * @param currentFile image filename
- * @return void
- **/
- void extractBasicFeatures ( NICE::MultiChannelImageT<double> &feats, const NICE::ColorImage &img, const std::string ¤tFile, int &amountRegions);
- /**
- * 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
- * @return best information gain
- */
- double getBestSplit ( std::vector<NICE::MultiChannelImageT<double> > &feats, std::vector<NICE::MultiChannelImageT<unsigned short int> > ¤tfeats, const std::vector<NICE::MatrixT<int> > &labels, int node, Operation *&splitop, double &splitval, const int &tree, std::vector<std::vector<std::vector<double> > > ®ionProbs );
- /**
- * @brief computes the mean probability for a given class over all trees
- * @param x x position
- * @param y y position
- * @param channel current class
- * @param currentfeats information about the nodes
- * @return double mean value
- **/
- inline double getMeanProb ( const int &x, const int &y, const int &channel, const NICE::MultiChannelImageT<unsigned short int> ¤tfeats );
- /**
- * @brief load all data to is stream
- *
- * @param is input stream
- * @param format has no influence
- * @return void
- **/
- virtual void restore ( std::istream & is, int format = 0 );
- /**
- * @brief save all data to is stream
- *
- * @param os output stream
- * @param format has no influence
- * @return void
- **/
- virtual void store ( std::ostream & os, int format = 0 ) const;
- /**
- * @brief clean up
- *
- * @return void
- **/
- virtual void clear () {}
- };
- } // namespace
- #endif
|