/** * @file SemSegCsurka.h * @brief semantic segmentation using the method from Csurka08 * @author Björn Fröhlich * @date 04/24/2009 */ #ifndef SemSegCsurkaINCLUDE #define SemSegCsurkaINCLUDE #include "SemanticSegmentation.h" #include "vislearning/math/ftransform/PCA.h" #include "vislearning/features/localfeatures/GenericLocalFeatureSelection.h" #include "vislearning/features/localfeatures/LFonHSG.h" #include "vislearning/features/localfeatures/LFColorSande.h" #include "vislearning/features/localfeatures/LocalFeatureColorWeijer.h" #include "vislearning/features/localfeatures/LFReadCache.h" #include "vislearning/features/localfeatures/LFWriteCache.h" #include "vislearning/features/fpfeatures/VectorFeature.h" #include "vislearning/features/fpfeatures/SparseVectorFeature.h" #include "vislearning/cbaselib/CachedExample.h" #include "vislearning/baselib/Preprocess.h" #include "vislearning/baselib/Globals.h" #include "segmentation/RegionSegmentationMethod.h" #include "segmentation/RSMeanShift.h" #include "segmentation/RSGraphBased.h" #include "segmentation/RSCache.h" #include "SemSegTools.h" #include "vislearning/math/cluster/GMM.h" #include "vislearning/math/cluster/KMeansOnline.h" #include #include #include #include #include "semseg/semseg/postsegmentation/RelativeLocationPrior.h" #include "semseg/semseg/postsegmentation/PPSuperregion.h" #include "semseg/semseg/postsegmentation/PPGraphCut.h" /** @brief pixelwise labeling systems */ namespace OBJREC { class SemSegCsurka : public SemanticSegmentation { protected: //! for normalization std::vector vecmin, vecmax; //! boolean whether to save the cache or not bool save_cache; //! boolean whether to read the cache or not, if read_cache is false, everything will be trained bool read_cache; //! The cached Data std::string cache; //! The PCA PCA pca; //! using normalization bool norm; //! feature Dimension after PCA int dim; //! Classifier FeaturePoolClassifier *classifier; VecClassifier *vclassifier; //! Configuration File const NICE::Config *conf; //! name of all classes ClassNames cn; //! set of forbidden/background classes std::set forbidden_classes; //! whether to use the colorfeats or not bool usecolorfeats; //! low level Segmentation method RegionSegmentationMethod *seg; //! weight for the gaussimage double sigmaweight; //! Gaussian Mixture GMM *g; //! KMeans KMeansOnline *k; //! use pca or not bool usepca; //! forced recalculation of the pca bool calcpca; //! use highlevel transformation with gmm or not bool usegmm; //! use highlevel transformation with kmeans or not bool usekmeans; int bestclasses; //! how much clusters of the kmeans to use int kmeansfeat; //! use hard assignment or not bool kmeanshard; //! use fisher kernel for bag if visual words bool usefisher; //! forced recalculation of the gmm bool dogmm; //! number of gaussians int gaussians; //! whether to use the relative location features or not bool userellocprior; //! which classifier to use std::string cname; //! use regions segmentation or not bool useregions; //! how many features should be used for training the classifier (relative value between 0 and 1 double anteil; //! save steps for faster computing postprocesses bool savesteps; //! the relative location features RelativeLocationPrior *relloc; //! Shape pp PPSuperregion *srg; //! Graph Cut pp PPGraphCut *gcopt; //! smooth high level features or not bool smoothhl; //! sigma for high level smoothing double smoothfactor; //! which OpponentSIFT implementation to use {NICE, VANDESANDE} std::string opSiftImpl; //! read features? bool readfeat; //! write features? bool writefeat; /** * converts the low level features in high level features * @param ex input and output features * @param reduce reduce the dataset (1.0 means no reduction) */ void convertLowToHigh ( Examples &ex, double reduce = 1.0 ); /** * Starts the PCA * @param ex input features */ void initializePCA ( Examples &ex ); /** * using PCA on al input features * @param ex input features */ void doPCA ( Examples &ex ); /** * normalize the features between 0 and 1 * @param ex input features */ void normalize ( Examples &ex ); /** * smooth the high level features * @param ex input features */ void smoothHL ( Examples ex ); public: /** constructor * @param conf needs a configfile * @param md and a MultiDataset (contains images and other things) */ SemSegCsurka ( const NICE::Config *conf, const MultiDataset *md ); /** simple destructor */ virtual ~SemSegCsurka(); /** The trainingstep * @param md and a MultiDataset (contains images and other things) */ void train ( const MultiDataset *md ); /** The trainingstep for the postprocess * @param md and a MultiDataset (contains images and other things) */ void trainpostprocess ( const MultiDataset *md ); /** The main procedure. Input: Image, Output: Segmented Image with pixelwise labeles and the probabilities * @param ce image data * @param segresult result of the semantic segmentation with a label for each pixel * @param probabilities multi-channel image with one channel for each class and corresponding probabilities for each pixel */ void semanticseg ( CachedExample *ce, NICE::ImageT & segresult, NICE::MultiChannelImageT & probabilities ); void semanticseg ( CachedExample *ce, NICE::MultiChannelImageT & segresult, NICE::MultiChannelImage3DT & probabilities ) {} /** this procedure is equal semanticseg, if there is no post process * @param ce image data * @param segresult result of the semantic segmentation with a label for each pixel * @param probabilities multi-channel image with one channel for each class and corresponding probabilities for each pixel * @param Regionen the output regions * @param mask the positions of the regions */ void classifyregions ( CachedExample *ce, NICE::ImageT & segresult, NICE::MultiChannelImageT & probabilities, Examples &Regionen, NICE::Matrix &mask ); void getFeats ( NICE::Image arg1, NICE::VVector arg2, NICE::VVector arg3 ); }; } //namespace #endif