PSSBackgroundModel.cpp 1.5 KB

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