ImagePyramid.cpp 2.6 KB

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