SemSegCsurka2.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /**
  2. * @file SemSegCsurka2.h
  3. * @brief semantic segmentation using the method from Csurka08
  4. * @author Björn Fröhlich
  5. * @date 04/24/2009
  6. */
  7. #ifndef SemSegCsurka2INCLUDE
  8. #define SemSegCsurka2INCLUDE
  9. #include <objrec/nice.h>
  10. #include "SemanticSegmentation.h"
  11. #include "objrec/math/ftransform/PCA.h"
  12. #include "objrec/features/localfeatures/LFColorSande.h"
  13. #include "objrec/features/localfeatures/LFColorWeijer.h"
  14. #include "objrec/features/localfeatures/LFReadCache.h"
  15. #include "objrec/features/localfeatures/LFWriteCache.h"
  16. #include "objrec/cbaselib/VectorFeature.h"
  17. #include "objrec/features/fpfeatures/SparseVectorFeature.h"
  18. #include "objrec/cbaselib/CachedExample.h"
  19. #include "objrec/baselib/Preprocess.h"
  20. #include "objrec/baselib/Globals.h"
  21. #include "objrec/segmentation/RegionSegmentationMethod.h"
  22. #include "objrec/segmentation/RSMeanShift.h"
  23. #include "objrec/segmentation/RSCache.h"
  24. #include "SemSegTools.h"
  25. #include "objrec/math/cluster/GMM.h"
  26. #include "objrec/math/cluster/KMeansOnline.h"
  27. #include "objrec/classifier/fpclassifier/randomforest/FPCRandomForests.h"
  28. #include "objrec/classifier/fpclassifier/logisticregression/FPCSMLR.h"
  29. #include "objrec-froehlichexp/semseg/postsegmentation/PSSImageLevelPrior.h"
  30. #include "objrec-froehlichexp/semseg/postsegmentation/RelativeLocationPrior.h"
  31. #include "objrec-froehlichexp/semseg/postsegmentation/PPSuperregion.h"
  32. #include "objrec-froehlichexp/semseg/postsegmentation/PPGraphCut.h"
  33. #include <objrec/iclassifier/icgeneric/CSGeneric.h>
  34. /** @brief pixelwise labeling systems */
  35. namespace OBJREC {
  36. class SemSegCsurka2 : public SemanticSegmentation
  37. {
  38. protected:
  39. //! for normalization
  40. vector<double> vecmin, vecmax;
  41. //! boolean whether to save the cache or not
  42. bool save_cache;
  43. //! boolean whether to read the cache or not, if read_cache is false, everything will be trained
  44. bool read_cache;
  45. //! The cached Data
  46. std::string cache;
  47. //! The PCA
  48. PCA pca;
  49. //! using normalization
  50. bool norm;
  51. //! feature Dimension after PCA
  52. int dim;
  53. //! Classifier
  54. FeaturePoolClassifier *classifier;
  55. VecClassifier *vclassifier;
  56. //! Configuration File
  57. const Config *conf;
  58. ClassNames cn;
  59. //! whether to use the colorfeats or not
  60. bool usecolorfeats;
  61. //! low level Segmentation method
  62. RegionSegmentationMethod *seg;
  63. //! weight for the gaussimage
  64. double sigmaweight;
  65. //! Gaussian Mixture
  66. GMM *g;
  67. //! KMeans
  68. KMeansOnline *k;
  69. //! use pca or not
  70. bool usepca;
  71. //! forced recalculation of the pca
  72. bool calcpca;
  73. //! use highlevel transformation with gmm or not
  74. bool usegmm;
  75. //! use highlevel transformation with kmeans or not
  76. bool usekmeans;
  77. int bestclasses;
  78. //! how much clusters of the kmeans to use
  79. int kmeansfeat;
  80. //! use hard assignment or not
  81. bool kmeanshard;
  82. //! use fisher kernel for bag if visual words
  83. bool usefisher;
  84. //! forced recalculation of the gmm
  85. bool dogmm;
  86. //! number of gaussians
  87. int gaussians;
  88. //! whether to use the relative location features or not
  89. bool userellocprior;
  90. //! which classifier to use
  91. std::string cname;
  92. //! use regions segmentation or not
  93. bool useregions;
  94. //! how many features should be used for training the classifier (relative value between 0 and 1
  95. double anteil;
  96. //! save steps for faster computing postprocesses
  97. bool savesteps;
  98. //! the relative location features
  99. RelativeLocationPrior *relloc;
  100. //! Shape pp
  101. PPSuperregion *srg;
  102. //! Graph Cut pp
  103. PPGraphCut *gcopt;
  104. //! smooth high level features or not
  105. bool smoothhl;
  106. //! sigma for high level smoothing
  107. double smoothfactor;
  108. /**
  109. * converts the low level features in high level features
  110. * @param ex input and output features
  111. * @param reduce reduce the dataset (1.0 means no reduction)
  112. */
  113. void convertLowToHigh(Examples &ex, double reduce = 1.0);
  114. /**
  115. * Starts the PCA
  116. * @param ex input features
  117. */
  118. void initializePCA(Examples &ex);
  119. /**
  120. * using PCA on al input features
  121. * @param ex input features
  122. */
  123. void doPCA(Examples &ex);
  124. /**
  125. * normalize the features between 0 and 1
  126. * @param ex input features
  127. */
  128. void normalize(Examples &ex);
  129. /**
  130. * smooth the high level features
  131. * @param ex input features
  132. */
  133. void smoothHL(Examples ex);
  134. public:
  135. /** constructor
  136. * @param conf needs a configfile
  137. * @param md and a MultiDataset (contains images and other things)
  138. */
  139. SemSegCsurka2( const Config *conf, const MultiDataset *md );
  140. /** simple destructor */
  141. virtual ~SemSegCsurka2();
  142. /** The trainingstep
  143. * @param md and a MultiDataset (contains images and other things)
  144. */
  145. void train ( const MultiDataset *md );
  146. /** The trainingstep for the postprocess
  147. * @param md and a MultiDataset (contains images and other things)
  148. */
  149. void trainpostprocess( const MultiDataset *md );
  150. /** The main procedure. Input: Image, Output: Segmented Image with pixelwise labeles and the probabilities
  151. * @param ce image data
  152. * @param segresult result of the semantic segmentation with a label for each pixel
  153. * @param probabilities multi-channel image with one channel for each class and corresponding probabilities for each pixel
  154. */
  155. void semanticseg ( CachedExample *ce,
  156. NICE::Image & segresult,
  157. GenericImage<double> & probabilities );
  158. /** this procedure is equal semanticseg, if there is no post process
  159. * @param ce image data
  160. * @param segresult result of the semantic segmentation with a label for each pixel
  161. * @param probabilities multi-channel image with one channel for each class and corresponding probabilities for each pixel
  162. * @param Regionen the output regions
  163. * @param mask the positions of the regions
  164. */
  165. void classifyregions ( CachedExample *ce, NICE::Image & segresult, GenericImage<double> & probabilities, Examples &Regionen, NICE::Matrix &mask );
  166. };
  167. } //namespace
  168. #endif