SemSegCsurka.h 6.2 KB

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