PDFImage.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @file PDFImage.cpp
  3. * @brief accumulate two dimensional density
  4. * @author Erik Rodner
  5. * @date 04/16/2008
  6. */
  7. #include <iostream>
  8. #include <assert.h>
  9. #include "vislearning/math/pdf/PDFImage.h"
  10. using namespace OBJREC;
  11. using namespace std;
  12. using namespace NICE;
  13. PDFImage::PDFImage( const NICE::FloatImage & _imgd )
  14. {
  15. imgd.resize (_imgd.width(), _imgd.height());
  16. double sum = 0.0;
  17. for ( int y = 0 ; y < _imgd.height(); y++ )
  18. for ( int x = 0 ; x < _imgd.width(); x++ )
  19. sum += _imgd.getPixel(x,y);
  20. for ( int y = 0 ; y < _imgd.height(); y++ )
  21. for ( int x = 0 ; x < _imgd.width(); x++ )
  22. imgd.setPixel( x, y, _imgd.getPixel(x,y) / sum );
  23. }
  24. PDFImage::~PDFImage()
  25. {
  26. }
  27. // refactor-nice.pl: check this substitution
  28. // old: double PDFImage::getNLogDensity ( const Vector & x ) const
  29. double PDFImage::getNLogDensity ( const NICE::Vector & x ) const
  30. {
  31. return - log ( getProb(x) );
  32. }
  33. // refactor-nice.pl: check this substitution
  34. // old: double PDFImage::getProb ( const Vector & x ) const
  35. double PDFImage::getProb ( const NICE::Vector & x ) const
  36. {
  37. assert (x.size() == 2);
  38. assert ((x[0] < 1) && (x[1] < 1));
  39. assert ((x[0]>=0) && (x[1]>=0));
  40. // refactor-nice.pl: check this substitution
  41. // old: double val = GetValD(imgd, (int)(x[0]*imgd->xsize), (int)(x[1]*imgd->ysize));
  42. double val = imgd.getPixel((int)(x[0]*imgd.width()),(int)(x[1]*imgd.height()));
  43. return val;
  44. }
  45. int PDFImage::getDimension () const
  46. {
  47. return 2;
  48. }