SemanticSegmentation.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**
  2. * @file SemanticSegmentation.h
  3. * @brief abstract interface for semantic segmentation algorithms
  4. * @author Erik Rodner, Alexander Freytag, Sven Sickert
  5. * @date 03/19/2009, latest update: 14-05-2014 (dd-mm-yyyy)
  6. */
  7. #ifndef SEMANTICSEGMENTATIONINCLUDE
  8. #define SEMANTICSEGMENTATIONINCLUDE
  9. // nice-core includes
  10. #include <core/basics/Persistent.h>
  11. #include <vector>
  12. #include "core/image/MultiChannelImage3DT.h"
  13. #include "vislearning/cbaselib/MultiDataset.h"
  14. #include "vislearning/cbaselib/LocalizationResult.h"
  15. #include "vislearning/cbaselib/CachedExample.h"
  16. #include "vislearning/cbaselib/Example.h"
  17. namespace OBJREC
  18. {
  19. /** abstract interface for semantic segmentation algorithms */
  20. class SemanticSegmentation : public NICE::Persistent
  21. {
  22. protected:
  23. /** accessible class names and information about
  24. number of classes etc. */
  25. const ClassNames *classNames;
  26. /** enum type for imagetype */
  27. enum IMAGETYP
  28. {
  29. IMAGETYPE_RGB = 0,
  30. IMAGETYPE_GRAY
  31. };
  32. /** whether to load images with color information */
  33. IMAGETYP imagetype;
  34. int iterationCountSuffix;
  35. public:
  36. ///////////////////// ///////////////////// /////////////////////
  37. // CONSTRUCTORS / DESTRUCTORS
  38. ///////////////////// ///////////////////// /////////////////////
  39. /** default constructor */
  40. SemanticSegmentation ( );
  41. /** simple constructor
  42. @param conf global settings
  43. @param classNames this ClassNames object while be stored as a attribute
  44. */
  45. SemanticSegmentation ( const NICE::Config *conf,
  46. const ClassNames *classNames );
  47. /** simple destructor */
  48. virtual ~SemanticSegmentation();
  49. /**
  50. * @brief Setup internal variables and objects used
  51. * @author Alexander Freytag
  52. * @param conf Config file to specify variable settings
  53. * @param s_confSection
  54. */
  55. void initFromConfig(const NICE::Config *conf, const std::string & s_confSection = "SemanticSegmentation");
  56. ///////////////////// ///////////////////// /////////////////////
  57. // SEGMENTATION STUFF
  58. ///////////////////// ///////////////////// /////////////////////
  59. /**
  60. * @brief Classification function (has to be overloaded by all subclasses)
  61. * @author Sven Sickert
  62. * @param imgData image data
  63. * @param segresult result of the semantic segmentation with a label for each pixel
  64. * @param probabilities multi-channel image with one channel for each class and
  65. * corresponding probabilities for each pixel
  66. * @param filelist filename list of images that represent slices of a stack
  67. */
  68. virtual void classify ( NICE::MultiChannelImage3DT<double> & imgData,
  69. NICE::MultiChannelImageT<double> & segresult,
  70. NICE::MultiChannelImage3DT<double> & probabilities,
  71. const std::vector<std::string> & filelist ) = 0;
  72. /** training function (has to be overloaded by all subclasses)
  73. * @param md the data set
  74. */
  75. virtual void train ( const MultiDataset * md ) = 0;
  76. /**
  77. * @brief Load image slices into a MultiChannelImage3DT
  78. * @author Sven Sickert
  79. * @param filelist filename list of images that represent slices of a stack
  80. * @param imgData output
  81. */
  82. void make3DImage ( const std::vector<std::string> & filelist,
  83. NICE::MultiChannelImage3DT<double> & imgData );
  84. ///////////////////// ///////////////////// /////////////////////
  85. // DATA CONVERSION
  86. ///////////////////// ///////////////////// /////////////////////
  87. /**
  88. * convert different datatypes
  89. */
  90. void convertVVectorToExamples ( NICE::VVector &feats,OBJREC::Examples &examples, std::vector<int> &label );
  91. void convertExamplesToVVector ( NICE::VVector &feats,OBJREC::Examples &examples, std::vector<int> &label );
  92. void convertExamplesToLSet ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec );
  93. void convertLSetToExamples ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec );
  94. void convertLSetToSparseExamples ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec );
  95. ///////////////////// ///////////////////// /////////////////////
  96. // GET / SET
  97. ///////////////////// ///////////////////// /////////////////////
  98. /**
  99. * @brief Collect information about the depth of 3d images
  100. * @author Sven Sickert
  101. * @param Files a labeled set of data
  102. * @param depthVec output of depth values
  103. * @param run3dseg whether slice counting is necessary or not
  104. */
  105. void getDepthVector ( const LabeledSet *Files, std::vector<int> & depthVec, const bool run3dseg );
  106. /**
  107. * @brief Save probability maps of all classes to iamge files
  108. * @author Sven Sickert
  109. * @param prob class probability maps
  110. */
  111. void getProbabilityMap( const NICE::MultiChannelImage3DT<double> & prob );
  112. /**
  113. * @author Alexander Freytag
  114. * @date 06-02-2014 ( dd-mm-yyyy )
  115. */
  116. void setClassNames ( const OBJREC::ClassNames * _classNames ) ;
  117. void setIterationCountSuffix( const int & _iterationCountSuffix);
  118. ///////////////////// INTERFACE PERSISTENT /////////////////////
  119. // interface specific methods for store and restore
  120. ///////////////////// INTERFACE PERSISTENT /////////////////////
  121. /**
  122. * @brief Load active-segmentation-object from external file (stream)
  123. * @author Alexander Freytag
  124. */
  125. virtual void restore ( std::istream & is, int format = 0 );
  126. /**
  127. * @brief Save active-segmentation-object to external file (stream)
  128. * @author Alexander Freytag
  129. */
  130. virtual void store( std::ostream & os, int format = 0 ) const;
  131. /**
  132. * @brief Clear active-segmentation-object object
  133. * @author Alexander Freytag
  134. */
  135. virtual void clear ();
  136. };
  137. } // namespace
  138. #endif