SemSegCsurka.h 6.7 KB

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