ImagePyramid.cpp 2.4 KB

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