LFColorWeijer.h 4.4 KB

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