123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- /**
- * @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 "objrec/classifier/classifierbase/FeaturePoolClassifier.h"
- #include "objrec/classifier/classifierbase/VecClassifier.h"
- #include "objrec/segmentation/RegionSegmentationMethod.h"
- #include "objrec/math/mathbase/Featuretype.h"
- #include "objrec/features/regionfeatures/RegionFeatures.h"
- #include "objrec/features/localfeatures/LocalFeature.h"
- #include "objrec/math/ftransform/PCA.h"
- #include "objrec-froehlichexp/semseg/postsegmentation/PPGraphCut.h"
- namespace OBJREC
- {
- class SemSegRegionBased : public SemanticSegmentation
- {
- protected:
-
- //! destination for saving intermediate steps
- bool save_cache, read_cache;
- std::string cache;
- string classifiercache;
-
- //! used ClassNames
- ClassNames cn;
- //! Classifier
- VecClassifier *vclassifier;
- FeaturePoolClassifier *fpc;
- //! Configuration File
- const 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 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, GenericImage<double> & 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, vector<vector< FeatureType> > &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, VVector &feats, vector<int> &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(vector<vector<FeatureType> > &feats, Examples &examples);
-
- /**
- * Convert features into examples
- * @param feats input features
- * @param examples features as examples
- */
- void getExample(const vector<vector<FeatureType> > &feats, Examples &examples);
-
- /**
- * create featurepool depending on used features
- * @param feats input features
- * @param fp feature pool
- */
- void getFeaturePool( const vector<vector<FeatureType> > &feats, FeaturePool &fp);
- /**
- * classify the given features
- * @param feats input features
- * @param examples examples
- * @param probs probability for each region
- */
- void classify(const vector<vector<FeatureType> > &feats, Examples &examples, vector<vector<double> > &probs);
-
- /**
- * set the label of each region the to most probable class
- * @param rg
- * @param probs
- */
- void labelRegions(RegionGraph &rg, vector<vector<double> > &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 VVector &feats, PCA &pca, int dim, string &fn );
-
- /**
- * transform features using a given pca
- * @param feats input and output features
- * @param pca
- */
- void transformFeats(VVector &feats, PCA &pca);
- };
- } // namespace
- #endif
|