LocalFeatureColorWeijer.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /**
  2. * @file LocalFeatureColorWeijer.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, Alexander Freytag
  5. * @date 01/28/2010
  6. */
  7. #ifndef LOCALFEATURECOLORWEIJERINCLUDE
  8. #define LOCALFEATURECOLORWEIJERINCLUDE
  9. // nice-core includes
  10. #include <core/basics/Config.h>
  11. //
  12. #include <core/image/ImageT.h>
  13. #include <core/image/MultiChannelImageT.h>
  14. #include <core/imagedisplay/ImageDisplay.h>
  15. //
  16. #include <core/vector/VectorT.h>
  17. #include <core/vector/MatrixT.h>
  18. // nice-vislearning includes
  19. #include "LocalFeature.h"
  20. namespace OBJREC {
  21. /** interface to ColorSande implementation */
  22. class LocalFeatureColorWeijer : public LocalFeature
  23. {
  24. protected:
  25. //! enum for 11 main colors
  26. enum NAMEBLECOLORS
  27. {
  28. BLACK = 0,
  29. BLUE,
  30. BROWN,
  31. GREY,
  32. GREEN,
  33. ORANGE,
  34. PINK,
  35. PURPLE,
  36. RED,
  37. WHITE,
  38. YELLOW,
  39. LASTCOLOR
  40. };
  41. //! lookup table
  42. double hist[32][32][32][11];
  43. //! destination of the precomputed lookuptable
  44. std::string tfile;
  45. public:
  46. ///////////////////// ///////////////////// /////////////////////
  47. // CONSTRUCTORS / DESTRUCTORS
  48. ///////////////////// ///////////////////// /////////////////////
  49. /**
  50. * @brief default constructor
  51. * @author Alexander Freytag
  52. * @date 06-02-2014 ( dd-mm-yyyy )
  53. */
  54. LocalFeatureColorWeijer ( );
  55. /**
  56. * @brief recommended constructor, calls initFromConfig
  57. * @author Alexander Freytag
  58. * @date 06-02-2014 ( dd-mm-yyyy )
  59. */
  60. LocalFeatureColorWeijer ( const NICE::Config * _conf );
  61. /**
  62. * @brief simple destructor
  63. */
  64. virtual ~LocalFeatureColorWeijer();
  65. /**
  66. * @brief Jobs previously performed in the config-version of the constructor, read settings etc.
  67. * @author Alexander Freytag
  68. * @date 06-02-2014 ( dd-mm-yyyy )
  69. */
  70. virtual void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "LocalFeatureColorWeijer");
  71. ///////////////////// ///////////////////// /////////////////////
  72. // FEATURE STUFF
  73. ///////////////////// ///////////////////// //////////////////
  74. /**
  75. * get the size of the descriptor
  76. * @return size of descriptor
  77. */
  78. int getDescSize () const;
  79. /**
  80. * get the colorWeijer features
  81. * @param img grayvalue input image
  82. * @param features features (output)
  83. * @param positions position of the features
  84. * @return
  85. */
  86. int getDescriptors ( const NICE::Image & img, NICE::VVector & positions, NICE::VVector & features ) const;
  87. /**
  88. * get the colorWeijer features
  89. * @param img color input image
  90. * @param features features (output)
  91. * @param positions given positions of the features
  92. * @return
  93. */
  94. int getDescriptors ( const NICE::ColorImage & img, NICE::VVector & positions, NICE::VVector & features ) const;
  95. /**
  96. * visualize the features
  97. * @param mark
  98. * @param positions
  99. * @param color
  100. */
  101. void visualizeFeatures ( NICE::Image & mark, const NICE::VVector & positions, size_t color ) const;
  102. /**
  103. * visualize the features
  104. * @param mark
  105. * @param positions
  106. * @param color
  107. */
  108. void visualizeFeatures ( NICE::ColorImage & mark, const NICE::VVector & features, const NICE::VVector & position ) const;
  109. /**
  110. * visualize the features
  111. * @param cimg
  112. */
  113. void visualizeFeatures ( const NICE::ColorImage & cimg ) const;
  114. /**
  115. * visualize the features
  116. * @param cimg
  117. * @param out
  118. */
  119. void visualizeFeatures ( const NICE::ColorImage & cimg, NICE::ColorImage & out ) const;
  120. /**
  121. * @brief load parameters (look up table for color correspondences) from external file (~3MB)
  122. */
  123. void restoreLUT();
  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. * transform each pixel of an image
  132. * @param img input image
  133. * @param feats feature vector for each pixel
  134. */
  135. void getFeats ( const NICE::ColorImage &img, NICE::MultiChannelImageT<double> &feats );
  136. /**
  137. * transform each pixel of an image
  138. * @param img input image
  139. * @param feats feature value for each pixel
  140. * @param color which color name
  141. */
  142. void getFeats ( const NICE::ColorImage &img, NICE::ImageT<double> &feats, int color);
  143. ///////////////////// INTERFACE PERSISTENT /////////////////////
  144. // interface specific methods for store and restore
  145. ///////////////////// INTERFACE PERSISTENT /////////////////////
  146. /**
  147. * @brief Load object from external file (stream)
  148. * @author Alexander Freytag
  149. * @date 06-02-2014 ( dd-mmyyyy)
  150. */
  151. virtual void restore ( std::istream & is, int format = 0 );
  152. /**
  153. * @brief Save object to external file (stream)
  154. * @author Alexander Freytag
  155. * @date 06-02-2014 ( dd-mmyyyy)
  156. */
  157. virtual void store( std::ostream & os, int format = 0 ) const;
  158. /**
  159. * @brief Clear object
  160. * @author Alexander Freytag
  161. * @date 06-02-2014 ( dd-mmyyyy)
  162. */
  163. virtual void clear ();
  164. };
  165. } // namespace
  166. #endif