SemanticSegmentation.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**
  2. * @file SemanticSegmentation.h
  3. * @brief abstract interface for semantic segmentation algorithms
  4. * @author Erik Rodner, Alexander Freytag
  5. * @date 03/19/2009, latest update: 29-01-2014 (dd-mm-yyyy)
  6. */
  7. #ifndef SEMANTICSEGMENTATIONINCLUDE
  8. #define SEMANTICSEGMENTATIONINCLUDE
  9. // nice-core includes
  10. #include <core/basics/Persistent.h>
  11. // nice-vislearning includes
  12. #include <vislearning/cbaselib/MultiDataset.h>
  13. #include <vislearning/cbaselib/LocalizationResult.h>
  14. #include <vislearning/cbaselib/CachedExample.h>
  15. #include <vislearning/cbaselib/Example.h>
  16. #define ROADWORKSADD fthrow(NICE::Exception, "addNewExample(const NICE::Vector & newExample, const int & newClassNo): not yet implemented!");
  17. #define ROADWORKSADDNOVEL fthrow(NICE::Exception, "addNovelExamples(): not yet implemented!");
  18. #define ROADWORKSGETNOVEL fthrow(NICE::Exception, "getNovelExamples(): not yet implemented!");
  19. namespace OBJREC
  20. {
  21. /** abstract interface for semantic segmentation algorithms */
  22. class SemanticSegmentation : public NICE::Persistent
  23. {
  24. protected:
  25. /////////////////////////
  26. /////////////////////////
  27. // PROTECTED VARIABLES //
  28. /////////////////////////
  29. /////////////////////////
  30. /** accessible class names and information about
  31. number of classes etc. */
  32. const ClassNames * classNames;
  33. /** enum type for imagetype */
  34. enum IMAGETYP
  35. {
  36. IMAGETYPE_RGB = 0,
  37. IMAGETYPE_GRAY
  38. };
  39. /** whether to load images with color information */
  40. IMAGETYP imagetype;
  41. int iterationCountSuffix;
  42. /////////////////////////
  43. /////////////////////////
  44. // PROTECTED METHODS //
  45. /////////////////////////
  46. /////////////////////////
  47. public:
  48. ///////////////////// ///////////////////// /////////////////////
  49. // CONSTRUCTORS / DESTRUCTORS
  50. ///////////////////// ///////////////////// /////////////////////
  51. /** default constructor
  52. * @author Alexander Freytag
  53. * @date 06-02-2014 ( dd-mm-yyy )
  54. */
  55. SemanticSegmentation ( );
  56. /** simple constructor
  57. @param conf global settings
  58. @param classNames this ClassNames object while be stored as a attribute
  59. */
  60. SemanticSegmentation ( const NICE::Config *conf,
  61. const ClassNames *classNames );
  62. /** simple destructor */
  63. virtual ~SemanticSegmentation();
  64. /**
  65. * @brief Setup internal variables and objects used
  66. * @author Alexander Freytag
  67. * @param conf Config file to specify variable settings
  68. * @param s_confSection
  69. */
  70. void initFromConfig(const NICE::Config *conf, const std::string & s_confSection = "SemanticSegmentation");
  71. ///////////////////// ///////////////////// /////////////////////
  72. // SEGMENTATION STUFF
  73. ///////////////////// ///////////////////// /////////////////////
  74. /** load img from file call localize(CachedExample *ce) etc. */
  75. void semanticseg ( const std::string & filename,
  76. NICE::Image & segresult,
  77. NICE::MultiChannelImageT<double> & probabilities );
  78. /** this function has to be overloaded by all subclasses
  79. @param ce image data
  80. @param segresult result of the semantic segmentation with a label for each
  81. pixel
  82. @param probabilities multi-channel image with one channel for each class and
  83. corresponding probabilities for each pixel
  84. */
  85. virtual void semanticseg ( OBJREC::CachedExample *ce,
  86. NICE::Image & segresult,
  87. NICE::MultiChannelImageT<double> & probabilities ) = 0;
  88. ///////////////////// ///////////////////// /////////////////////
  89. // DATA CONVERSION
  90. ///////////////////// ///////////////////// /////////////////////
  91. /**
  92. * convert different datatypes
  93. */
  94. void convertVVectorToExamples ( NICE::VVector &feats,OBJREC::Examples &examples, std::vector<int> &label );
  95. void convertExamplesToVVector ( NICE::VVector &feats,OBJREC::Examples &examples, std::vector<int> &label );
  96. void convertExamplesToLSet ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec );
  97. void convertLSetToExamples ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec, const bool & removeOldDataPointer=false );
  98. void convertLSetToSparseExamples ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec );
  99. ///////////////////// ///////////////////// /////////////////////
  100. // ONLINE LEARNING
  101. ///////////////////// ///////////////////// /////////////////////
  102. virtual void addNewExample(const NICE::Vector & newExample, const int & newClassNo)
  103. {
  104. ROADWORKSADD;
  105. };
  106. /**
  107. * @brief Add those examples, which belong to the most novel region seen so far
  108. *
  109. * @return void
  110. **/
  111. virtual void addNovelExamples()
  112. {
  113. ROADWORKSADDNOVEL;
  114. };
  115. ///////////////////// ///////////////////// /////////////////////
  116. // GET / SET
  117. ///////////////////// ///////////////////// /////////////////////
  118. /**
  119. * @brief Get a pointer to the examples extracted from the most novel region seen so far
  120. *
  121. * @return Examples *
  122. **/
  123. virtual const Examples * getNovelExamples() const
  124. {
  125. ROADWORKSGETNOVEL;
  126. };
  127. /**
  128. * @author Alexander Freytag
  129. * @date 06-02-2014 ( dd-mm-yyyy )
  130. */
  131. void setClassNames ( const OBJREC::ClassNames * _classNames ) ;
  132. void setIterationCountSuffix( const int & _iterationCountSuffix);
  133. ///////////////////// INTERFACE PERSISTENT /////////////////////
  134. // interface specific methods for store and restore
  135. ///////////////////// INTERFACE PERSISTENT /////////////////////
  136. /**
  137. * @brief Load active-segmentation-object from external file (stream)
  138. * @author Alexander Freytag
  139. */
  140. virtual void restore ( std::istream & is, int format = 0 );
  141. /**
  142. * @brief Save active-segmentation-object to external file (stream)
  143. * @author Alexander Freytag
  144. */
  145. virtual void store( std::ostream & os, int format = 0 ) const;
  146. /**
  147. * @brief Clear active-segmentation-object object
  148. * @author Alexander Freytag
  149. */
  150. virtual void clear ();
  151. };
  152. } // namespace
  153. #endif