LocalFeatureColorWeijer.h 4.8 KB

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