PDFImage.cpp 1.5 KB

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