SemSegNovelty.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. inline void computeClassificationResults( const NICE::MultiChannelImageT<double> & feats,
  70. NICE::Image & segresult,
  71. NICE::MultiChannelImageT<double> & probabilities,
  72. const int & xsize,
  73. const int & ysize,
  74. const int & featdim );
  75. void computeNoveltyByVariance( NICE::FloatImage & noveltyImage,
  76. const NICE::MultiChannelImageT<double> & feats,
  77. NICE::Image & segresult,
  78. NICE::MultiChannelImageT<double> & probabilities,
  79. const int & xsize, const int & ysize, const int & featdim );
  80. void computeNoveltyByGPUncertainty ( NICE::FloatImage & noveltyImage,
  81. const NICE::MultiChannelImageT<double> & feats,
  82. NICE::Image & segresult,
  83. NICE::MultiChannelImageT<double> & probabilities,
  84. const int & xsize, const int & ysize, const int & featdim );
  85. public:
  86. /** constructor
  87. * @param conf needs a configfile
  88. * @param md and a MultiDataset (contains images and other things)
  89. */
  90. SemSegNovelty ( const NICE::Config *conf, const MultiDataset *md );
  91. /** simple destructor */
  92. virtual ~SemSegNovelty();
  93. /** The trainingstep
  94. * @param md and a MultiDataset (contains images and other things)
  95. */
  96. void train ( const MultiDataset *md );
  97. /** The main procedure. Input: Image, Output: Segmented Image with pixelwise labeles and the probabilities
  98. * @param ce image data
  99. * @param segresult result of the semantic segmentation with a label for each pixel
  100. * @param probabilities multi-channel image with one channel for each class and corresponding probabilities for each pixel
  101. */
  102. void semanticseg ( CachedExample *ce,
  103. NICE::Image & segresult,
  104. NICE::MultiChannelImageT<double> & probabilities );
  105. /**
  106. * @brief visualize a specific region in the original image
  107. *
  108. * @param img input image
  109. * @param regions map of the regions
  110. * @param region visualize this region
  111. * @param outimage result
  112. * @return void
  113. **/
  114. void visualizeRegion(const NICE::ColorImage &img, const NICE::Matrix &regions, int region, NICE::ColorImage &outimage);
  115. };
  116. } //namespace
  117. #endif