SemSegCsurka.h 6.2 KB

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