SemSegCsurka.h 6.2 KB

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