SemanticSegmentation.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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; //mutable
  33. /** enum type for imagetype */
  34. enum
  35. {
  36. IMAGETYPE_RGB = 0,
  37. IMAGETYPE_GRAY
  38. };
  39. /** whether to load images with color information */
  40. int imagetype;
  41. int iterationCountSuffix;
  42. /////////////////////////
  43. /////////////////////////
  44. // PROTECTED METHODS //
  45. /////////////////////////
  46. /////////////////////////
  47. public:
  48. ///////////////////// ///////////////////// /////////////////////
  49. // CONSTRUCTORS / DESTRUCTORS
  50. ///////////////////// ///////////////////// /////////////////////
  51. /** simple constructor
  52. @param conf global settings
  53. @param classNames this ClassNames object while be stored as a attribute
  54. */
  55. SemanticSegmentation ( const NICE::Config *conf,
  56. const ClassNames *classNames );
  57. /** simple destructor */
  58. virtual ~SemanticSegmentation();
  59. ///////////////////// ///////////////////// /////////////////////
  60. // SEGMENTATION STUFF
  61. ///////////////////// ///////////////////// /////////////////////
  62. /** load img from file call localize(CachedExample *ce) etc. */
  63. void semanticseg ( const std::string & filename,
  64. NICE::Image & segresult,
  65. NICE::MultiChannelImageT<double> & probabilities );
  66. /** this function has to be overloaded by all subclasses
  67. @param ce image data
  68. @param segresult result of the semantic segmentation with a label for each
  69. pixel
  70. @param probabilities multi-channel image with one channel for each class and
  71. corresponding probabilities for each pixel
  72. */
  73. virtual void semanticseg ( OBJREC::CachedExample *ce,
  74. NICE::Image & segresult,
  75. NICE::MultiChannelImageT<double> & probabilities ) = 0;
  76. ///////////////////// ///////////////////// /////////////////////
  77. // DATA CONVERSION
  78. ///////////////////// ///////////////////// /////////////////////
  79. /**
  80. * convert different datatypes
  81. */
  82. void convertVVectorToExamples ( NICE::VVector &feats,OBJREC::Examples &examples, std::vector<int> &label );
  83. void convertExamplesToVVector ( NICE::VVector &feats,OBJREC::Examples &examples, std::vector<int> &label );
  84. void convertExamplesToLSet ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec );
  85. void convertLSetToExamples ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec, const bool & removeOldDataPointer=false );
  86. void convertLSetToSparseExamples ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec );
  87. ///////////////////// ///////////////////// /////////////////////
  88. // ONLINE LEARNING
  89. ///////////////////// ///////////////////// /////////////////////
  90. virtual void addNewExample(const NICE::Vector & newExample, const int & newClassNo)
  91. {
  92. ROADWORKSADD;
  93. };
  94. /**
  95. * @brief Add those examples, which belong to the most novel region seen so far
  96. *
  97. * @return void
  98. **/
  99. virtual void addNovelExamples()
  100. {
  101. ROADWORKSADDNOVEL;
  102. };
  103. ///////////////////// ///////////////////// /////////////////////
  104. // GET / SET
  105. ///////////////////// ///////////////////// /////////////////////
  106. /**
  107. * @brief Get a pointer to the examples extracted from the most novel region seen so far
  108. *
  109. * @return Examples *
  110. **/
  111. virtual const Examples * getNovelExamples() const
  112. {
  113. ROADWORKSGETNOVEL;
  114. };
  115. void setIterationCountSuffix( const int & _iterationCountSuffix) { iterationCountSuffix = _iterationCountSuffix; };
  116. ///////////////////// INTERFACE PERSISTENT /////////////////////
  117. // interface specific methods for store and restore
  118. ///////////////////// INTERFACE PERSISTENT /////////////////////
  119. /**
  120. * @brief Load active-segmentation-object from external file (stream)
  121. * @author Alexander Freytag
  122. */
  123. virtual void restore ( std::istream & is, int format = 0 );
  124. /**
  125. * @brief Save active-segmentation-object to external file (stream)
  126. * @author Alexander Freytag
  127. */
  128. virtual void store( std::ostream & os, int format = 0 ) const;
  129. /**
  130. * @brief Clear active-segmentation-object object
  131. * @author Alexander Freytag
  132. */
  133. virtual void clear ();
  134. };
  135. } // namespace
  136. #endif