LFColorWeijer.h 4.4 KB

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