SemSegTools.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * @file SemSegTools.h
  3. * @brief tools for semantic segmentation
  4. * @author Erik Rodner
  5. * @date 03/19/2009
  6. */
  7. #ifndef SEMSEGTOOLSINCLUDE
  8. #define SEMSEGTOOLSINCLUDE
  9. #include "core/basics/Config.h"
  10. #include "core/basics/ResourceStatistics.h"
  11. #include "vislearning/cbaselib/MultiDataset.h"
  12. #include "vislearning/cbaselib/Example.h"
  13. #include "vislearning/cbaselib/CachedExample.h"
  14. namespace OBJREC
  15. {
  16. /** tools for semantic segmentation */
  17. class SemSegTools
  18. {
  19. protected:
  20. public:
  21. /**
  22. * @brief produce an image with segmentation result as overlay
  23. * @param orig original input image
  24. * @param segment segmentation result
  25. * @param result overlay image
  26. */
  27. static void segmentToOverlay (
  28. const NICE::Image * orig,
  29. const NICE::ColorImage & segment,
  30. NICE::ColorImage & result );
  31. /**
  32. * @brief update confusion matrix with results of current image
  33. * @param img segmentation result
  34. * @param gt ground truth data
  35. * @param M confusion matrix
  36. * @param forbidden_classes set of classes, that should be ignored
  37. * @param classMapping mapping for a subset of classes
  38. */
  39. static void updateConfusionMatrix (
  40. const NICE::ImageT<int> & img,
  41. const NICE::ImageT<int> & gt,
  42. NICE::Matrix & M,
  43. const std::set<int> & forbiddenClasses,
  44. std::map<int,int> & classMapping );
  45. /**
  46. * @brief compute typical classification statistics using confusion matrix
  47. * @param confMat confusion matrix
  48. * @param classNames class names object
  49. * @param forbidden_classes set of classes, that should be ignored
  50. * @param classMappingInv mapping for a subset of classes
  51. */
  52. static void computeClassificationStatistics (
  53. NICE::Matrix & confMat,
  54. const OBJREC::ClassNames & classNames,
  55. const std::set<int> & forbiddenClasses,
  56. std::map<int,int> & classMappingInv );
  57. /**
  58. * @brief compute some resource statistics
  59. * @param rs resource statistics object
  60. */
  61. static void computeResourceStatistics (
  62. NICE::ResourceStatistics & rs );
  63. /**
  64. * @brief save results to image file
  65. * @param conf Config file
  66. * @param section section in config file
  67. * @param orig input image
  68. * @param gtruth ground truth data
  69. * @param segment segmentation result
  70. */
  71. static void saveResultsToImageFile (
  72. const NICE::Config * conf,
  73. const std::string & section,
  74. const NICE::ColorImage & orig,
  75. const NICE::ColorImage & gtruth,
  76. const NICE::ColorImage & segment,
  77. const std::string & file,
  78. std::string & outStr );
  79. /**
  80. * @brief Collect information about the depth of 3d images
  81. * @author Sven Sickert
  82. * @param Files a labeled set of data
  83. * @param depthVec output of depth values
  84. * @param run3dseg whether slice counting is necessary or not
  85. */
  86. static void getDepthVector (
  87. const LabeledSet *Files,
  88. std::vector<int> & depthVec,
  89. const bool run3dseg );
  90. /** collect pixel-wise training examples
  91. from a set of images
  92. @param conf includes settings about grid size etc.
  93. @param section section of the config
  94. @param train set of training images with localization information
  95. @param cn classNames object
  96. @param examples resulting pixel-wise examples
  97. @param imgexamples image based caching structure referenced by pixel-wise examples
  98. @param run3Dseg whether to run in 3D segmentation mode or not
  99. */
  100. static void collectTrainingExamples (
  101. const NICE::Config * conf,
  102. const std::string & section,
  103. const LabeledSet & train,
  104. const ClassNames & cn,
  105. Examples & examples,
  106. std::vector<CachedExample *> & imgexamples,
  107. const bool run3Dseg = false );
  108. };
  109. } // namespace
  110. #endif