SemSegCsurka.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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/LocalFeatureColorWeijer.h"
  15. #include "vislearning/features/localfeatures/LFReadCache.h"
  16. #include "vislearning/features/localfeatures/LFWriteCache.h"
  17. #include "vislearning/features/fpfeatures/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 "segmentation/RegionSegmentationMethod.h"
  23. #include "segmentation/RSMeanShift.h"
  24. #include "segmentation/RSGraphBased.h"
  25. #include "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/genericClassifierSelection.h>
  30. #include <vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h>
  31. #include <vislearning/classifier/fpclassifier/gphik/FPCGPHIK.h>
  32. #include <vislearning/classifier/fpclassifier/logisticregression/FPCSMLR.h>
  33. #include "semseg/semseg/postsegmentation/RelativeLocationPrior.h"
  34. #include "semseg/semseg/postsegmentation/PPSuperregion.h"
  35. #include "semseg/semseg/postsegmentation/PPGraphCut.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 NICE::Config *conf;
  60. //! name of all classes
  61. ClassNames cn;
  62. //! set of forbidden/background classes
  63. std::set<int> forbidden_classes;
  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. //! Shape pp
  106. PPSuperregion *srg;
  107. //! Graph Cut pp
  108. PPGraphCut *gcopt;
  109. //! smooth high level features or not
  110. bool smoothhl;
  111. //! sigma for high level smoothing
  112. double smoothfactor;
  113. //! which OpponentSIFT implementation to use {NICE, VANDESANDE}
  114. std::string opSiftImpl;
  115. //! read features?
  116. bool readfeat;
  117. //! write features?
  118. bool writefeat;
  119. /**
  120. * converts the low level features in high level features
  121. * @param ex input and output features
  122. * @param reduce reduce the dataset (1.0 means no reduction)
  123. */
  124. void convertLowToHigh ( Examples &ex, double reduce = 1.0 );
  125. /**
  126. * Starts the PCA
  127. * @param ex input features
  128. */
  129. void initializePCA ( Examples &ex );
  130. /**
  131. * using PCA on al input features
  132. * @param ex input features
  133. */
  134. void doPCA ( Examples &ex );
  135. /**
  136. * normalize the features between 0 and 1
  137. * @param ex input features
  138. */
  139. void normalize ( Examples &ex );
  140. /**
  141. * smooth the high level features
  142. * @param ex input features
  143. */
  144. void smoothHL ( Examples ex );
  145. public:
  146. /** constructor
  147. * @param conf needs a configfile
  148. * @param md and a MultiDataset (contains images and other things)
  149. */
  150. SemSegCsurka ( const NICE::Config *conf, const MultiDataset *md );
  151. /** simple destructor */
  152. virtual ~SemSegCsurka();
  153. /** The trainingstep
  154. * @param md and a MultiDataset (contains images and other things)
  155. */
  156. void train ( const MultiDataset *md );
  157. /** The trainingstep for the postprocess
  158. * @param md and a MultiDataset (contains images and other things)
  159. */
  160. void trainpostprocess ( const MultiDataset *md );
  161. /** The main procedure. Input: Image, Output: Segmented Image with pixelwise labeles and the probabilities
  162. * @param ce image data
  163. * @param segresult result of the semantic segmentation with a label for each pixel
  164. * @param probabilities multi-channel image with one channel for each class and corresponding probabilities for each pixel
  165. */
  166. void semanticseg ( CachedExample *ce,
  167. NICE::ImageT<int> & segresult,
  168. NICE::MultiChannelImageT<double> & probabilities );
  169. void semanticseg ( CachedExample *ce,
  170. NICE::MultiChannelImageT<int> & segresult,
  171. NICE::MultiChannelImage3DT<double> & probabilities )
  172. {}
  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::ImageT<int> & segresult, NICE::MultiChannelImageT<double> & probabilities, Examples &Regionen, NICE::Matrix &mask );
  181. void getFeats ( NICE::Image arg1, NICE::VVector arg2, NICE::VVector arg3 );
  182. };
  183. } //namespace
  184. #endif