/** * @file SemSegRegionBased.h * @brief new semantic segmentation method using regions * @author Björn Fröhlich * @date 01/29/2010 */ #ifndef SemSegRegionBasedINCLUDE #define SemSegRegionBasedINCLUDE #include "SemanticSegmentation.h" #include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h" #include "vislearning/classifier/classifierbase/VecClassifier.h" #include "objrec/segmentation/RegionSegmentationMethod.h" #include "vislearning/math/mathbase/Featuretype.h" #include "objrec/features/regionfeatures/RegionFeatures.h" #include "vislearning/features/localfeatures/LocalFeature.h" #include "vislearning/math/ftransform/PCA.h" #include "semseg/semseg/postsegmentation/PPGraphCut.h" namespace OBJREC { class SemSegRegionBased : public SemanticSegmentation { protected: //! destination for saving intermediate steps bool save_cache, read_cache; std::string cache; std::string classifiercache; //! used ClassNames ClassNames cn; //! Classifier VecClassifier *vclassifier; FeaturePoolClassifier *fpc; //! Configuration File const NICE::Config *conf; //! Segmentation Method RegionSegmentationMethod *rsm; //! using color Weijer features or not RegionFeatures *rfc; //! using HoGFeatures or not RegionFeatures *rfhog; //! using BoV or not RegionFeatures *rfbov; //! Moosmann Codebook (alternative BoV approach) RegionFeatures *rfbovcrdf; //! old method like used in Csurka RegionFeatures *rfCsurka; //! features for BoV LocalFeature *siftFeats; //! using structure feature RegionFeatures *rfstruct; //! MRF optimization PPGraphCut *gcopt; public: /** constructor * @param conf needs a configfile * @param md and a MultiDataset (contains images and other things) */ SemSegRegionBased ( const NICE::Config *c, const MultiDataset *md ); /** simple destructor */ virtual ~SemSegRegionBased(); /** The trainingstep * @param md and a MultiDataset (contains images and other things) */ void train ( 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::Image & segresult, NICE::MultiChannelImageT & probabilities ); /** * get all features for an Image and save them in Examples * @param cimg input image * @param mask region mask * @param rg region graph * @param feats output features */ void getFeats ( const NICE::ColorImage &cimg, const NICE::Matrix &mask, const RegionGraph &rg, std::vector > &feats ) const; /** * computes or reads features and corresponding labels for learnHighLevel() * @param perm input permutation * @param feats output features * @param label output label * @param examples output examples (including label) * @param mode mode 1 for examples, mode 0 for VVector */ void computeLF ( LabeledSet::Permutation perm, NICE::VVector &feats, std::vector &label, Examples &examples, int mode ); /** * Computes HighLevel Codebooks (i.e. GMM or PCA) if necessary * @param perm training examples */ void learnHighLevel ( LabeledSet::Permutation perm ); /** * trains the classifier * @param feats features */ void trainClassifier ( std::vector > &feats, Examples &examples ); /** * Convert features into examples * @param feats input features * @param examples features as examples */ void getExample ( const std::vector > &feats, Examples &examples ); /** * create featurepool depending on used features * @param feats input features * @param fp feature pool */ void getFeaturePool ( const std::vector > &feats, FeaturePool &fp ); /** * classify the given features * @param feats input features * @param examples examples * @param probs probability for each region */ void classify ( const std::vector > &feats, Examples &examples, std::vector > &probs ); /** * set the label of each region the to most probable class * @param rg * @param probs */ void labelRegions ( RegionGraph &rg, std::vector > &probs ); /** * set label of each pixel to label of corresponding region * @param segresult result image * @param mask region mask * @param rg region graph */ void labelImage ( NICE::Image &segresult, NICE::Matrix &mask,RegionGraph &rg ); /** * get the label for each region from the groundtruth for learning step and save them in rg * @param mask region mask * @param rg region graph * @param pixelLabels Groundtruth images */ void getRegionLabel ( NICE::Matrix &mask, RegionGraph &rg, NICE::Image &pixelLabels ); /** * train pca * @param feats input features * @param pca pca * @param dim new dimension * @param fn destination filename */ void initializePCA ( const NICE::VVector &feats, PCA &pca, int dim, std::string &fn ); /** * transform features using a given pca * @param feats input and output features * @param pca */ void transformFeats ( NICE::VVector &feats, PCA &pca ); }; } // namespace #endif