/** * @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 // nice-vislearning includes #include // nice-segmentation includes #include // nice-semseg includes #include "SemanticSegmentation.h" #include "operations/SimpleOperationPool.h" #include "operations/RegionOperationPool.h" #include "operations/RectangleOperationPool.h" namespace OBJREC { /** Localization system */ class SemSegContextTree3D : public SemanticSegmentation { private: /** Segmentation Method */ RegionSegmentationMethod *segmentation; /** tree -> saved as vector of nodes */ std::vector > forest; /** whether to use a particular feature type or not */ bool useFeat0, useFeat1, useFeat2, useFeat3, useFeat4; /** array of usable feature types*/ std::vector featTypes; /** Number of trees used for the forest */ int nbTrees; /** 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 labelcounter; /** map of labels */ std::map labelmap; /** map of labels inverse*/ std::map labelmapback; /** scalefactor for balancing for each class */ std::vector 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 features */ std::vector ops; /** use alternative calculation for information gain */ bool useShannonEntropy; /** Classnames */ ClassNames classnames; /** train selection */ std::set 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 additional input layers or not */ bool useAdditionalLayer; /** how many additional input layers */ int numAdditionalLayer; /** 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 > channelsPerType; /** 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 &nodeIndices, NICE::MultiChannelImage3DT &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 &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 &imgData, const std::vector &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 > &feats, std::vector > &nodeIndices, const std::vector > &labels, int node, Operation3D *&splitop, double &splitval, const int &tree, std::vector > > ®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 &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 & filelist, NICE::MultiChannelImageT & segresult, NICE::MultiChannelImage3DT & 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 void semanticseg ( CachedExample *ce, NICE::ImageT & segresult, NICE::MultiChannelImageT & probabilities ) {} void semanticseg ( CachedExample *ce, NICE::MultiChannelImageT & segresult, NICE::MultiChannelImage3DT & probabilities ) {} void printFeatureStatistics(); 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