LFColorWeijer.h 4.3 KB

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