ImagePyramid.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * @file ImagePyramid.cpp
  3. * @brief gauss image pyramid
  4. * @author Erik Rodner
  5. * @date 02/06/2008
  6. */
  7. #include <iostream>
  8. #include "vislearning/image/ImagePyramid.h"
  9. using namespace OBJREC;
  10. using namespace std;
  11. using namespace NICE;
  12. ImagePyramid::ImagePyramid( const NICE::Image & img,
  13. int maxLevels,
  14. double scaleSpacing,
  15. int max_xsize,
  16. int max_ysize )
  17. {
  18. pyramid.push_back ( NICE::Image(img) );
  19. for ( int i = 1 ; i < maxLevels ; i++ )
  20. {
  21. int old_xsize = pyramid[i-1].width();
  22. int old_ysize = pyramid[i-1].height();
  23. double new_xsize = old_xsize / scaleSpacing;
  24. double new_ysize = old_ysize / scaleSpacing;
  25. if ( (new_xsize < max_xsize) || (new_ysize < max_ysize) )
  26. break;
  27. NICE::Image gauss (old_xsize, old_ysize);
  28. filterGauss(pyramid[i-1], 2, &gauss);
  29. NICE::Image newLevel ((int)new_xsize, (int)new_ysize);
  30. // Trafo trafo;
  31. // trafo.Scale(0, 0, (new_xsize-1)/(old_xsize-1),
  32. // (new_ysize-1)/(old_ysize-1));
  33. // Transform(trafo, gauss, newLevel);
  34. NICE::scale ( gauss, &newLevel );
  35. NICE::scale ( gauss, &newLevel );
  36. pyramid.push_back(newLevel);
  37. }
  38. }
  39. ImagePyramid::~ImagePyramid()
  40. {
  41. }
  42. const NICE::Image & ImagePyramid::getLevel ( int i ) const
  43. {
  44. return pyramid[i];
  45. }
  46. int ImagePyramid::getNumLevels () const
  47. {
  48. return pyramid.size();
  49. }
  50. void ImagePyramid::getOriginalCoordinates ( int x, int y, int level, double & xo, double & yo ) const
  51. {
  52. int xsize_orig = pyramid[0].width();
  53. int ysize_orig = pyramid[0].height();
  54. int xsize = pyramid[level].width();
  55. int ysize = pyramid[level].height();
  56. xo = x*(double)(xsize_orig)/xsize;
  57. yo = y*(double)(ysize_orig)/ysize;
  58. }
  59. void ImagePyramid::getLevelCoordinates ( double xo, double yo, int level, double & xl, double & yl ) const
  60. {
  61. int xsize_orig = pyramid[0].width();
  62. int ysize_orig = pyramid[0].height();
  63. int xsize = pyramid[level].width();
  64. int ysize = pyramid[level].height();
  65. xl = xo*(double)(xsize)/xsize_orig;
  66. yl = yo*(double)(ysize)/ysize_orig;
  67. }
  68. void ImagePyramid::show() const
  69. {
  70. #ifndef NOVISUAL
  71. for ( size_t i = 0 ; i < pyramid.size() ; i++ )
  72. showImage(pyramid[i]);
  73. /* skipped because of new visualization functions
  74. GetChar();
  75. for ( size_t i = 0 ; i < pyramid.size() ; i++ )
  76. Show(OFF, pyramid[i]);
  77. */
  78. #else
  79. fprintf (stderr, "ImagePyramid::show(): visualization disabled !\n");
  80. #endif
  81. }