FCCodebookHistBin.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @file FCCodebookHistBin.h
  3. * @brief create features with a predefined codebook
  4. * @author Erik Rodner
  5. * @date 02/05/2008
  6. */
  7. #ifndef FCCODEBOOKHISTBININCLUDE
  8. #define FCCODEBOOKHISTBININCLUDE
  9. #include "core/vector/VectorT.h"
  10. #include "core/vector/MatrixT.h"
  11. #include "core/basics/Config.h"
  12. #include "vislearning/features/fbase/FeatureFactory.h"
  13. #include "vislearning/features/localfeatures/LocalFeatureRepresentation.h"
  14. #include "Codebook.h"
  15. namespace OBJREC {
  16. /** create features with codebook */
  17. class FCCodebookHistBin : public FeatureFactory
  18. {
  19. protected:
  20. //! normalization method used (enum type)
  21. int n_method;
  22. //! local feature method
  23. const LocalFeatureRepresentation *lfrep;
  24. //! pointer to our codebook
  25. const Codebook *codebook;
  26. void calcHistogram ( const NICE::VVector & features,
  27. NICE::Vector & histogram );
  28. void calcHistogram ( const NICE::VVector & features,
  29. NICE::Vector & histogram,
  30. NICE::Matrix & assignments);
  31. void normalizeHistogram ( NICE::Vector & histogram );
  32. public:
  33. //! enum type used for normalization method
  34. enum {
  35. NORMALIZE_RAW = 0,
  36. NORMALIZE_BINZERO,
  37. NORMALIZE_SUM,
  38. NORMALIZE_THRESH
  39. };
  40. /**
  41. * @brief standard constructor
  42. *
  43. * @param conf pointer to a Config object with some parameter settings (currently not used)
  44. * @param lfrep local feature extraction method (keep the pointer!)
  45. * @param normalizationMethod name of the normalization method (sum, binzero, raw, thresh)
  46. * @param codebook pointer to the codebook (keep the pointer!)
  47. */
  48. FCCodebookHistBin( const NICE::Config *conf,
  49. const LocalFeatureRepresentation *lfrep,
  50. const std::string & normalizationMethod,
  51. const Codebook *codebook );
  52. /** simple destructor */
  53. virtual ~FCCodebookHistBin();
  54. /**
  55. * @brief calculate a BoV histogram vector (no local information, only global)
  56. *
  57. * @param img input image
  58. * @param vec resulting feature vector
  59. *
  60. * @return -1 if something fails (no local features found for example) and zero if everything was okay
  61. */
  62. int convert ( const NICE::Image & img, NICE::Vector & vec );
  63. /**
  64. * @brief calculate a BoV histogram vector and also store the assignments of each local feature to a BoV cluster (codebook element)
  65. *
  66. * @param features input local features (size is N)
  67. * @param vec resulting BoV feature vector
  68. * @param assignments assignments of local features to BoV clusters given as a 3xN matrix, with assignments(0,*) representing the distance
  69. * of a local feature to the nearest BoV cluster, assignments(1,*) storing the BoV cluster index, and assignments(2,*) being the index of the local feature
  70. *
  71. * @return
  72. */
  73. int calcAssignments ( const NICE::VVector & features, NICE::Vector & vec, NICE::Matrix & assignments );
  74. /**
  75. * @brief set the type of the normalization method (see the enum of the class)
  76. *
  77. * @param normalizationMethod see enum type
  78. */
  79. void setNormalizationMethod ( int normalizationMethod );
  80. /**
  81. * @brief get the currently used normalization method
  82. *
  83. * @return see enum type
  84. */
  85. int getNormalizationMethod () const;
  86. };
  87. } // namespace
  88. #endif