PSSBackgroundModel.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * @file PSSBackgroundModel.cpp
  3. * @brief simple background models
  4. * @author Erik Rodner
  5. * @date 03/19/2009
  6. */
  7. #ifdef NOVISUAL
  8. #include <objrec/nice_nonvis.h>
  9. #else
  10. #include <objrec/nice.h>
  11. #endif
  12. #include <iostream>
  13. #include "PSSBackgroundModel.h"
  14. using namespace OBJREC;
  15. using namespace std;
  16. // refactor-nice.pl: check this substitution
  17. // old: using namespace ice;
  18. using namespace NICE;
  19. PSSBackgroundModel::PSSBackgroundModel( int backgroundModelType, double threshold, int backgroundClass )
  20. {
  21. this->backgroundModelType = backgroundModelType;
  22. this->threshold = threshold;
  23. this->backgroundClass = backgroundClass;
  24. }
  25. PSSBackgroundModel::~PSSBackgroundModel()
  26. {
  27. }
  28. // refactor-nice.pl: check this substitution
  29. // old: void PSSBackgroundModel::postprocess ( Image & result, GenericImage<double> & probabilities )
  30. void PSSBackgroundModel::postprocess ( NICE::Image & result, GenericImage<double> & probabilities )
  31. {
  32. if ( backgroundModelType == BGM_FIXED_ENTROPY_THRESHOLD )
  33. {
  34. if ( threshold >= 1.0 ) return;
  35. int numClasses = probabilities.numChannels;
  36. double t = log(numClasses)*threshold;
  37. int xsize = probabilities.xsize;
  38. int ysize = probabilities.ysize;
  39. int offset_s = 0;
  40. for ( int ys = 0 ; ys < ysize ; ys ++ )
  41. for ( int xs = 0 ; xs < xsize ; xs++,offset_s++ )
  42. {
  43. double entropy = 0.0;
  44. double sum = 0.0;
  45. for ( int i = 0 ; i < numClasses ; i++ )
  46. {
  47. double val = probabilities.data[i][offset_s];
  48. if ( val <= 0.0 ) continue;
  49. entropy -= val*log(val);
  50. sum += val;
  51. }
  52. entropy /= sum;
  53. entropy += log(sum);
  54. if ( entropy > t )
  55. result.setPixel(xs,ys,backgroundClass);
  56. }
  57. } else if ( backgroundModelType == BGM_ADAPTIVE_ENTROPY_THRESHOLD ) {
  58. fprintf (stderr, "not yet implemented !!\n");
  59. exit(-1);
  60. }
  61. }