NoveltyDetectorCodebookLevel.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @file NoveltyDetectorCodebookLevel.h
  3. * @brief Compute novelty of images based on relations between extracted features and current codebook
  4. * @author Alexander Freytag
  5. * @date 02-05-2013 (dd-mm-yyyy)
  6. */
  7. #ifndef _INCLUDENOVELTYDETECTIONCODEBOOKLEVEL
  8. #define _INCLUDENOVELTYDETECTIONCODEBOOKLEVEL
  9. #include "NoveltyDetector.h"
  10. //core
  11. #include <core/vector/Distance.h>
  12. #include <core/vector/VVector.h>
  13. // vislearning
  14. #include <vislearning/cbaselib/MultiDataset.h>
  15. //
  16. #include <vislearning/features/localfeatures/GenericLocalFeatureSelection.h>
  17. //
  18. #include <vislearning/math/cluster/ClusterAlgorithm.h>
  19. namespace OBJREC
  20. {
  21. /**
  22. * @class NoveltyDetectorCodebookLevel
  23. * @brief Compute novelty of images based on relations between extracted features and current codebook
  24. * @author Alexander Freytag
  25. * @date 02-05-2013 (dd-mm-yyyy)
  26. */
  27. class NoveltyDetectorCodebookLevel : public NoveltyDetector
  28. {
  29. protected:
  30. /************************
  31. *
  32. * protected variables
  33. *
  34. **************************/
  35. NICE::VectorDistance<double> * distFunction;
  36. LocalFeatureRepresentation * featureExtractor;
  37. //! The currently known "cluster" centers, which are used for BoW histogram computation (i.e., the codebook)
  38. NICE::VVector * prototypes;
  39. //! was an initial codebook already computed?
  40. bool b_loadInitialCodebook;
  41. //!shall the initially computed codebook be stored somewhere?
  42. bool b_saveInitialCodebook;
  43. //! where should an initial codebook be located, i.e., read from and written to?
  44. std::string cacheInitialCodebook;
  45. //! did we compute a codebook on our own or do we use simply a pointer to an external codebook?
  46. bool externalCodebook;
  47. /************************
  48. *
  49. * protected methods
  50. *
  51. **************************/
  52. void setFeatureExtractor( const bool & _setForTraining = false);
  53. void extractFeaturesFromTrainingImages( const OBJREC::MultiDataset *_md, NICE::VVector & examplesTraining );
  54. virtual bool loadInitialCodebook ( );
  55. virtual bool writeInitialCodebook ( );
  56. public:
  57. /** constructor
  58. * @param _conf needs a configfile
  59. * @param _md and a MultiDataset (contains images and other things)
  60. * @param _section section information for parsing config files
  61. */
  62. NoveltyDetectorCodebookLevel ( const NICE::Config *_conf, const OBJREC::MultiDataset *_md , const std::string & _section = "noveltyDetector");
  63. /** simple destructor */
  64. virtual ~NoveltyDetectorCodebookLevel();
  65. /**
  66. * @brief Evaluate whether or not the image of the specified filename is novel with respect to the current known examples or not
  67. * @author Alexander Freytag
  68. * @date 02-05-2013 (dd-mm-yyyy)
  69. * @param _filename of the new image
  70. * @return bool (true: class/content/... of image is novel, false: class/content/... of image is known)
  71. * @note This function has to be overloaded by all subclasses!
  72. */
  73. virtual bool evaluateNoveltyOfImage ( const std::string & _filename ) = 0;
  74. /**
  75. * @brief Evaluate whether or not the image of the specified filename is novel with respect to the current known examples or not
  76. * @author Alexander Freytag
  77. * @date 02-05-2013 (dd-mm-yyyy)
  78. * @param _noveltyImage contains min distances of features to the current codebook
  79. * @return bool (true: class/content/... of image is novel, false: class/content/... of image is known)
  80. */
  81. virtual bool evaluateNoveltyOfImage ( const NICE::FloatImage & _noveltyImage ) = 0;
  82. /**
  83. * @brief Hand over a previously computed codebook
  84. * @author Alexander Freytag
  85. * @date 02-05-2013 (dd-mm-yyyy)
  86. * @param _prototypes pointer to a codebook
  87. * @note we check whether we just use the pointer to the external codebook, or alternatively copy it and have it as internal codebook available lateron
  88. */
  89. virtual void setCodebook( NICE::VVector * _prototypes);
  90. };
  91. } // namespace
  92. #endif