SemanticSegmentation.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. // standard library includes
  10. #include <vector>
  11. // nice-core includes
  12. #include <core/basics/Persistent.h>
  13. #include "core/image/MultiChannelImage3DT.h"
  14. // nice-vislearning includes
  15. #include "vislearning/cbaselib/MultiDataset.h"
  16. #include "vislearning/cbaselib/LocalizationResult.h"
  17. #include "vislearning/cbaselib/CachedExample.h"
  18. #include "vislearning/cbaselib/Example.h"
  19. #define ROADWORKSADD fthrow(NICE::Exception, "addNewExample(const NICE::Vector & newExample, const int & newClassNo): not yet implemented!");
  20. #define ROADWORKSADDNOVEL fthrow(NICE::Exception, "addNovelExamples(): not yet implemented!");
  21. #define ROADWORKSGETNOVEL fthrow(NICE::Exception, "getNovelExamples(): not yet implemented!");
  22. namespace OBJREC
  23. {
  24. /** abstract interface for semantic segmentation algorithms */
  25. class SemanticSegmentation : public NICE::Persistent
  26. {
  27. protected:
  28. /////////////////////////
  29. /////////////////////////
  30. // PROTECTED VARIABLES //
  31. /////////////////////////
  32. /////////////////////////
  33. /** accessible class names and information about
  34. number of classes etc. */
  35. const ClassNames * classNames;
  36. /** enum type for imagetype */
  37. enum IMAGETYP
  38. {
  39. IMAGETYPE_RGB = 0,
  40. IMAGETYPE_GRAY
  41. };
  42. /** whether to load images with color information */
  43. IMAGETYP imagetype;
  44. int iterationCountSuffix;
  45. /////////////////////////
  46. /////////////////////////
  47. // PROTECTED METHODS //
  48. /////////////////////////
  49. /////////////////////////
  50. public:
  51. ///////////////////// ///////////////////// /////////////////////
  52. // CONSTRUCTORS / DESTRUCTORS
  53. ///////////////////// ///////////////////// /////////////////////
  54. /** default constructor
  55. * @author Alexander Freytag
  56. * @date 06-02-2014 ( dd-mm-yyy )
  57. */
  58. SemanticSegmentation ( );
  59. /** simple constructor
  60. @param conf global settings
  61. @param classNames this ClassNames object while be stored as a attribute
  62. */
  63. SemanticSegmentation ( const NICE::Config *conf,
  64. const ClassNames *classNames );
  65. /** simple destructor */
  66. virtual ~SemanticSegmentation();
  67. /**
  68. * @brief Setup internal variables and objects used
  69. * @author Alexander Freytag
  70. * @param conf Config file to specify variable settings
  71. * @param s_confSection
  72. */
  73. void initFromConfig(const NICE::Config *conf, const std::string & s_confSection = "SemanticSegmentation");
  74. ///////////////////// ///////////////////// /////////////////////
  75. // SEGMENTATION STUFF
  76. ///////////////////// ///////////////////// /////////////////////
  77. /** load img from file call localize(CachedExample *ce) etc. */
  78. void semanticseg ( const std::string & filename,
  79. NICE::Image & segresult,
  80. NICE::MultiChannelImageT<double> & probabilities );
  81. /**
  82. * Classify each voxel of a 3D image (image stack)
  83. * @author Sven Sickert
  84. * @param filelist filename list of images that represent slices of a stack
  85. * @param segresult segmentation results (output)
  86. * @param probabilities probabilities for each pixel (output)
  87. */
  88. virtual void classify ( const std::vector<std::string> & filelist,
  89. NICE::MultiChannelImageT<double> & segresult,
  90. NICE::MultiChannelImage3DT<double> & probabilities );
  91. /** this function has to be overloaded by all subclasses
  92. @param ce image data
  93. @param segresult result of the semantic segmentation with a label for each
  94. pixel
  95. @param probabilities multi-channel image with one channel for each class and
  96. corresponding probabilities for each pixel
  97. */
  98. virtual void semanticseg ( OBJREC::CachedExample *ce,
  99. NICE::Image & segresult,
  100. NICE::MultiChannelImageT<double> & probabilities ) = 0;
  101. /** training function (has to be overloaded by all subclasses)
  102. * @param md the data set
  103. */
  104. virtual void train ( const MultiDataset * md ) = 0;
  105. /**
  106. * @brief train the actual training method
  107. * @param trainp pointer to training data
  108. */
  109. virtual void train ( const LabeledSet * trainp ){}
  110. /**
  111. * @brief Load image slices into a MultiChannelImage3DT
  112. * @author Sven Sickert
  113. * @param filelist filename list of images that represent slices of a stack
  114. * @param imgData output
  115. */
  116. void make3DImage ( const std::vector<std::string> & filelist,
  117. NICE::MultiChannelImage3DT<double> & imgData );
  118. ///////////////////// ///////////////////// /////////////////////
  119. // DATA CONVERSION
  120. ///////////////////// ///////////////////// /////////////////////
  121. /**
  122. * convert different datatypes
  123. */
  124. void convertVVectorToExamples ( NICE::VVector &feats,OBJREC::Examples &examples, std::vector<int> &label );
  125. void convertExamplesToVVector ( NICE::VVector &feats,OBJREC::Examples &examples, std::vector<int> &label );
  126. void convertExamplesToLSet ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec );
  127. void convertLSetToExamples ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec, const bool & removeOldDataPointer=false );
  128. void convertLSetToSparseExamples ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec );
  129. ///////////////////// ///////////////////// /////////////////////
  130. // ONLINE LEARNING
  131. ///////////////////// ///////////////////// /////////////////////
  132. virtual void addNewExample(const NICE::Vector & newExample, const int & newClassNo)
  133. {
  134. ROADWORKSADD;
  135. }
  136. /**
  137. * @brief Add those examples, which belong to the most novel region seen so far
  138. *
  139. * @return void
  140. **/
  141. virtual void addNovelExamples()
  142. {
  143. ROADWORKSADDNOVEL;
  144. }
  145. ///////////////////// ///////////////////// /////////////////////
  146. // GET / SET
  147. ///////////////////// ///////////////////// /////////////////////
  148. /**
  149. * @brief Get a pointer to the examples extracted from the most novel region seen so far
  150. *
  151. * @return Examples *
  152. **/
  153. virtual const Examples * getNovelExamples() const
  154. {
  155. ROADWORKSGETNOVEL;
  156. }
  157. /**
  158. * @brief Collect information about the depth of 3d images
  159. * @author Sven Sickert
  160. * @param Files a labeled set of data
  161. * @param depthVec output of depth values
  162. * @param run3dseg whether slice counting is necessary or not
  163. */
  164. void getDepthVector ( const LabeledSet *Files, std::vector<int> & depthVec, const bool run3dseg );
  165. /**
  166. * @brief Save probability maps of all classes to iamge files
  167. * @author Sven Sickert
  168. * @param prob class probability maps
  169. */
  170. void getProbabilityMap( const NICE::MultiChannelImage3DT<double> & prob );
  171. /**
  172. * @author Alexander Freytag
  173. * @date 06-02-2014 ( dd-mm-yyyy )
  174. */
  175. void setClassNames ( const OBJREC::ClassNames * _classNames ) ;
  176. void setIterationCountSuffix( const int & _iterationCountSuffix);
  177. ///////////////////// INTERFACE PERSISTENT /////////////////////
  178. // interface specific methods for store and restore
  179. ///////////////////// INTERFACE PERSISTENT /////////////////////
  180. /**
  181. * @brief Load active-segmentation-object from external file (stream)
  182. * @author Alexander Freytag
  183. */
  184. virtual void restore ( std::istream & is, int format = 0 );
  185. /**
  186. * @brief Save active-segmentation-object to external file (stream)
  187. * @author Alexander Freytag
  188. */
  189. virtual void store( std::ostream & os, int format = 0 ) const;
  190. /**
  191. * @brief Clear active-segmentation-object object
  192. * @author Alexander Freytag
  193. */
  194. virtual void clear ();
  195. };
  196. } // namespace
  197. #endif