LFColorWeijer.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /**
  2. * @file LFColorWeijer.cpp
  3. * @brief implementation of the color features mentioned in van de Weijer, J. & Schmid, C. Applying Color Names to Image Description (2007)
  4. * @author Björn Fröhlich
  5. * @date 01/28/2010
  6. */
  7. #ifndef LFColorWeijerINCLUDE
  8. #define LFColorWeijerINCLUDE
  9. #include "core/vector/VectorT.h"
  10. #include "core/vector/MatrixT.h"
  11. #include "core/image/ImageT.h"
  12. #include "core/imagedisplay/ImageDisplay.h"
  13. #include "LocalFeature.h"
  14. #include "core/basics/Config.h"
  15. namespace OBJREC {
  16. /** interface to ColorSande implementation */
  17. class LFColorWeijer : public LocalFeature
  18. {
  19. protected:
  20. //! enum for 11 main colors
  21. enum
  22. {
  23. BLACK = 0,
  24. BLUE,
  25. BROWN,
  26. GREY,
  27. GREEN,
  28. ORANGE,
  29. PINK,
  30. PURPLE,
  31. RED,
  32. WHITE,
  33. YELLOW,
  34. LASTCOLOR
  35. };
  36. //! bins for L*, a* and b* chanel of L*a*b*
  37. int bin[3];
  38. //! upper limits for L*, a* and b* chanel of L*a*b*
  39. double maxv[3];
  40. //! lower limits for L*, a* and b* chanel of L*a*b*
  41. double minv[3];
  42. //! quantization interval for L*, a* and b* chanel of L*a*b* depending on bin, maxv and minv
  43. double interval[3];
  44. //! destination of the computed lookuptable
  45. std::string tfile;
  46. //! lookuptable for the probabilities (4d: colors, L-channel, a-channel, b-channel)
  47. std::vector<std::vector<std::vector<std::vector<double> > > > hist;
  48. //! configuration file
  49. const NICE::Config *conf;
  50. public:
  51. /** simple constructor */
  52. LFColorWeijer( const NICE::Config *c);
  53. /** simple destructor */
  54. virtual ~LFColorWeijer();
  55. /**
  56. * get the size of the descriptor
  57. * @return size of descriptor
  58. */
  59. int getDescSize () const;
  60. /**
  61. * get the colorWeijer features
  62. * @param img grayvalue input image
  63. * @param features features (output)
  64. * @param positions position of the features
  65. * @return
  66. */
  67. int getDescriptors ( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & features ) const;
  68. /**
  69. * get the colorWeijer features
  70. * @param img color input image
  71. * @param features features (output)
  72. * @param positions given positions of the features
  73. * @return
  74. */
  75. int getDescriptors ( const NICE::ColorImage & img, NICE::VVector & positions, NICE::VVector & features ) const;
  76. /**
  77. * visualize the features
  78. * @param mark
  79. * @param positions
  80. * @param color
  81. */
  82. void visualizeFeatures ( NICE::Image & mark, const NICE::VVector & positions, size_t color ) const;
  83. /**
  84. * visualize the features
  85. * @param mark
  86. * @param positions
  87. * @param color
  88. */
  89. void visualizeFeatures ( NICE::ColorImage & mark, const NICE::VVector & features, const NICE::VVector & position ) const;
  90. /**
  91. * visualize the features
  92. * @param cimg
  93. */
  94. void visualizeFeatures ( const NICE::ColorImage & cimg) const;
  95. /**
  96. * visualize the features
  97. * @param cimg
  98. * @param out
  99. */
  100. void visualizeFeatures ( const NICE::ColorImage & cimg, NICE::ColorImage & out) const;
  101. /**
  102. * save parameters
  103. */
  104. void store();
  105. /**
  106. * load parameters
  107. */
  108. void restore();
  109. /**
  110. * smooths the look up table
  111. */
  112. void smooth();
  113. /**
  114. * normalizes the sum of a 3d histogram to 1
  115. * @param tab 3d histogram
  116. */
  117. void normalize(std::vector<std::vector<std::vector<double> > > &tab);
  118. /**
  119. * creates a new and empty table
  120. * @return table of the size bin[0]xbin[1]xbin[2]
  121. */
  122. std::vector<std::vector<std::vector<double > > > createTable();
  123. /**
  124. * finds a colorname in a given string
  125. * @param fn input string
  126. * @return number of the color
  127. */
  128. int findColor(std::string &fn);
  129. /**
  130. * creates a new Histogram for input image depending on the image mask
  131. * @param cimg input image
  132. * @param hist histogram
  133. * @param mask which pixel should be consider
  134. */
  135. void createHist(const NICE::ColorImage &cimg, std::vector<std::vector<std::vector<double> > > &hist, NICE::Image &mask);
  136. /**
  137. * train the lookuptable
  138. */
  139. void train();
  140. /**
  141. * add a 3d table to a 3d table elementwise
  142. * @param dest destination table
  143. * @param src source table
  144. */
  145. void add(std::vector<std::vector<std::vector<double> > > &dest, std::vector<std::vector<std::vector<double> > > &src);
  146. /**
  147. * transform each pixel of an image
  148. * @param img input image
  149. * @param feats feature vector for each pixel
  150. */
  151. void getFeats(const NICE::ColorImage &img, std::vector<std::vector<std::vector<double> > > &feats);
  152. };
  153. } // namespace
  154. #endif