123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- /**
- * @file SemSegContextTree3D.h
- * @brief Context Trees -> Combination of decision tree and context information
- * @author Björn Fröhlich, Sven Sickert
- * @date 29.11.2011
- */
- #ifndef SemSegContextTree3DINCLUDE
- #define SemSegContextTree3DINCLUDE
- // 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 "SemanticSegmentation.h"
- #include "operations/Operations3D.h"
- namespace OBJREC
- {
- /** Localization system */
- class SemSegContextTree3D : public SemanticSegmentation
- {
- private:
- /** Segmentation Method */
- RegionSegmentationMethod *segmentation;
- /** tree -> saved as vector of nodes */
- std::vector<std::vector<TreeNode> > forest;
- /** local features */
- LocalFeatureColorWeijer *lfcw;
- /** whether to run in 3D mode or not */
- bool run3Dseg;
- /** whether to use a particular feature type or not */
- bool useFeat0, useFeat1, useFeat2, useFeat3, useFeat4;
- /** array of usable feature types*/
- std::vector<int> featTypes;
- /** Number of trees used for the forest */
- int nbTrees;
- /** maximum samples for tree */
- int maxSamples;
- /** size for neighbourhood */
- int windowSize;
- /** multiplier for window size if context feature */
- int contextMultiplier;
- /** 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;
- /** 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;
- int labelIncrement;
- /** prototype operations for pairwise features */
- std::vector<std::vector<Operation3D*> > ops;
- /** 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;
- /** whether to use alternative tristimulus for CIE_Lab that matches openCV or not */
- bool useAltTristimulus;
- /** use Gradient image or not */
- bool useGradient;
- /** use Color features from van de Weijer or not */
- bool useWeijer;
- /** use additional input Layer or not */
- bool useAdditionalLayer;
- /** use external image categorization to avoid some classes */
- bool useCategorization;
- /** categorization information for external categorization */
- std::string cndir;
- /** 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;
-
- /** save / load trained icf classifier */
- bool saveLoadData;
- /** file location of trained icf classifier */
- std::string fileLocation;
- /** first iteration or not */
- bool firstiteration;
- /** amount of grayvalue Channels */
- int rawChannels;
- /** classifier for categorization */
- OBJREC::FPCGPHIK *fasthik;
- /** unique numbers for nodes */
- int uniquenumber;
-
- /**
- * @brief initOperations initialize the operation types
- */
- void initOperations();
- /**
- * @brief updateProbabilityMaps computes probability maps for context features
- * @param nodeIndices matrix with current node for each feature
- * @param feats output MCI3D (must be initilized)
- * @param firstChannel index of the first channel
- */
- void updateProbabilityMaps ( const NICE::MultiChannelImage3DT<unsigned short int> &nodeIndices, NICE::MultiChannelImage3DT<double> &feats, int firstChannel );
- /**
- * @brief computeRayFeatImage computes ray feature images using canny filter
- * @param feats output MCI3D (must be initilized)
- * @param firstChannel index of the first channel
- */
- void computeRayFeatImage ( NICE::MultiChannelImage3DT<double> &feats, int firstChannel );
- /**
- * @brief addFeatureMaps initializes the selected feature channels
- * @param imgData output MCI3D (must be initilized)
- * @param filelist a list of image file names representing slices of a stack
- * @param amountRegions the amount of regions created by the segmentation
- **/
- void addFeatureMaps ( NICE::MultiChannelImage3DT<double> &imgData, const std::vector<std::string> &filelist, int &amountRegions );
- /**
- * @brief compute best split for current settings
- * @param feats features
- * @param nodeIndices matrix with current node for each feature
- * @param labels labels for each feature
- * @param node current node
- * @param splitfeat output selected feature dimension
- * @param splitval output threshold for selected feature
- * @return double best information gain value
- */
- double getBestSplit ( std::vector<NICE::MultiChannelImage3DT<double> > &feats, std::vector<NICE::MultiChannelImage3DT<unsigned short int> > &nodeIndices, const std::vector<NICE::MultiChannelImageT<int> > &labels, int node, Operation3D *&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 z z position
- * @param channel current class
- * @param nodeIndices matrix with current node for each feature
- * @return double mean value
- **/
- inline double getMeanProb ( const int &x, const int &y, const int &z, const int &channel, const NICE::MultiChannelImage3DT<unsigned short int> &nodeIndices );
- public:
- /** simple constructor */
- SemSegContextTree3D ();
- /** constructor */
- SemSegContextTree3D ( const NICE::Config *conf,
- const ClassNames *classNames );
- /** simple destructor */
- virtual ~SemSegContextTree3D();
- /**
- * classify each voxel of a 3D image (image stack)
- * @param filelist filename list of images that represent slices of a stack
- * @param segresult segmentation results (output)
- * @param probabilities probabilities for each pixel (output)
- */
- void classify ( const std::vector<std::string> & filelist,
- NICE::MultiChannelImageT<int> & segresult,
- NICE::MultiChannelImage3DT<double> & probabilities );
- /**
- * @brief train the actual training method
- * @param trainp pointer to training data
- */
- void train ( const LabeledSet * trainp );
- /**
- * the training method with checking for already existing trained classifier from file
- * @param md training data
- */
- void train ( const MultiDataset *md );
- // deprecated stuff
- virtual void semanticseg ( OBJREC::CachedExample *ce,
- NICE::ImageT<int> & segresult,
- NICE::MultiChannelImageT<double> & probabilities )
- {}
- bool active3DMode ()
- {
- return run3Dseg;
- }
- /**
- * @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
|