SemSegNovelty.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. * @file SemSegNovelty.h
  3. * @brief semantic segmentation using the method from Csurka08
  4. * @author Björn Fröhlich
  5. * @date 04/24/2009
  6. */
  7. #ifndef SemSegNoveltyINCLUDE
  8. #define SemSegNoveltyINCLUDE
  9. #include "SemanticSegmentation.h"
  10. #include "SemSegTools.h"
  11. #include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
  12. #include "vislearning/features/localfeatures/LFColorWeijer.h"
  13. #include "segmentation/RegionSegmentationMethod.h"
  14. /** @brief pixelwise labeling systems */
  15. namespace OBJREC {
  16. class SemSegNovelty : public SemanticSegmentation
  17. {
  18. protected:
  19. //! boolean whether to save the cache or not
  20. bool save_cache;
  21. //! boolean whether to read the cache or not, if read_cache is false, everything will be trained
  22. bool read_cache;
  23. //! The cached Data
  24. std::string cache;
  25. //! Classifier
  26. FeaturePoolClassifier *classifier;
  27. //! feature extraction
  28. LFColorWeijer *featExtract;
  29. //! Configuration File
  30. const NICE::Config *conf;
  31. //! distance between features for training
  32. int trainWsize;
  33. //! half of the window size for local features
  34. int whs;
  35. //! rectangle size for classification, 1 means pixelwise
  36. int testWSize;
  37. //! name of all classes
  38. ClassNames cn;
  39. //! low level Segmentation method
  40. RegionSegmentationMethod *regionSeg;
  41. //! set of forbidden/background classes
  42. std::set<int> forbidden_classes;
  43. std::set<int> forbidden_classesTrain;
  44. std::set<int> classesInUse;
  45. //! obviously, the number of classes used for training
  46. int numberOfClasses;
  47. //! where to save the uncertainty
  48. std::string uncertdir;
  49. //! find the maximum uncertainty or not
  50. bool findMaximumUncert;
  51. //! image with most uncertain region
  52. NICE::ColorImage maskedImg;
  53. //! maximum uncertainty over all images
  54. double globalMaxUncert;
  55. //! current examples for most uncertain region
  56. Examples newTrainExamples;
  57. enum NoveltyMethod{
  58. GPVARIANCE, // novel = large variance
  59. GPUNCERTAINTY, //novel = small uncertainty (mean / var)
  60. GPMINMEAN, //novel = small mean
  61. GPMEANRATIO, //novel = small difference between mean of most plausible class and mean of snd
  62. // most plausible class (not useful in binary settings)
  63. GPWEIGHTALL, // novel = large weight in alpha vector after updating the model (can be predicted exactly)
  64. GPWEIGHTRATIO // novel = small difference between weights for alpha vectors with assumptions of GT label to be the most
  65. // plausible against the second most plausible class
  66. };
  67. //! specify how "novelty" shall be computed, e.g., using GP-variance, GP-uncertainty, or predicted weight entries
  68. NoveltyMethod noveltyMethod;
  69. std::string noveltyMethodString;
  70. inline void computeClassificationResults( const NICE::MultiChannelImageT<double> & feats,
  71. NICE::Image & segresult,
  72. NICE::MultiChannelImageT<double> & probabilities,
  73. const int & xsize,
  74. const int & ysize,
  75. const int & featdim );
  76. void computeNoveltyByVariance( NICE::FloatImage & noveltyImage,
  77. const NICE::MultiChannelImageT<double> & feats,
  78. NICE::Image & segresult,
  79. NICE::MultiChannelImageT<double> & probabilities,
  80. const int & xsize, const int & ysize, const int & featdim );
  81. void computeNoveltyByGPUncertainty ( NICE::FloatImage & noveltyImage,
  82. const NICE::MultiChannelImageT<double> & feats,
  83. NICE::Image & segresult,
  84. NICE::MultiChannelImageT<double> & probabilities,
  85. const int & xsize, const int & ysize, const int & featdim );
  86. void computeNoveltyByGPMean ( NICE::FloatImage & noveltyImage,
  87. const NICE::MultiChannelImageT<double> & feats,
  88. NICE::Image & segresult,
  89. NICE::MultiChannelImageT<double> & probabilities,
  90. const int & xsize, const int & ysize, const int & featdim );
  91. void computeNoveltyByGPMeanRatio ( NICE::FloatImage & noveltyImage,
  92. const NICE::MultiChannelImageT<double> & feats,
  93. NICE::Image & segresult,
  94. NICE::MultiChannelImageT<double> & probabilities,
  95. const int & xsize, const int & ysize, const int & featdim );
  96. void computeNoveltyByGPWeightAll ( NICE::FloatImage & noveltyImage,
  97. const NICE::MultiChannelImageT<double> & feats,
  98. NICE::Image & segresult,
  99. NICE::MultiChannelImageT<double> & probabilities,
  100. const int & xsize, const int & ysize, const int & featdim );
  101. void computeNoveltyByGPWeightRatio ( NICE::FloatImage & noveltyImage,
  102. const NICE::MultiChannelImageT<double> & feats,
  103. NICE::Image & segresult,
  104. NICE::MultiChannelImageT<double> & probabilities,
  105. const int & xsize, const int & ysize, const int & featdim );
  106. public:
  107. /** constructor
  108. * @param conf needs a configfile
  109. * @param md and a MultiDataset (contains images and other things)
  110. */
  111. SemSegNovelty ( const NICE::Config *conf, const MultiDataset *md );
  112. /** simple destructor */
  113. virtual ~SemSegNovelty();
  114. /** The trainingstep
  115. * @param md and a MultiDataset (contains images and other things)
  116. */
  117. void train ( const MultiDataset *md );
  118. /** The main procedure. Input: Image, Output: Segmented Image with pixelwise labeles and the probabilities
  119. * @param ce image data
  120. * @param segresult result of the semantic segmentation with a label for each pixel
  121. * @param probabilities multi-channel image with one channel for each class and corresponding probabilities for each pixel
  122. */
  123. void semanticseg ( CachedExample *ce,
  124. NICE::Image & segresult,
  125. NICE::MultiChannelImageT<double> & probabilities );
  126. /**
  127. * @brief visualize a specific region in the original image
  128. *
  129. * @param img input image
  130. * @param regions map of the regions
  131. * @param region visualize this region
  132. * @param outimage result
  133. * @return void
  134. **/
  135. void visualizeRegion(const NICE::ColorImage &img, const NICE::Matrix &regions, int region, NICE::ColorImage &outimage);
  136. };
  137. } //namespace
  138. #endif