FIGradients.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "FIGradients.h"
  2. #include "vislearning/baselib/FastFilter.h"
  3. #include "vislearning/image/GenericImageTools.h"
  4. using namespace OBJREC;
  5. using namespace NICE;
  6. using namespace std;
  7. void FIGradients::buildEOHMap ( CachedExample *ce,
  8. int subsamplex, int subsampley,
  9. int numBins, bool usesigned )
  10. {
  11. int xsize;
  12. int ysize;
  13. ce->getImageSize ( xsize, ysize );
  14. int xsize_s = xsize / subsamplex;
  15. int ysize_s = ysize / subsampley;
  16. NICE::MultiChannelImage3DT<double> & eohimg = ce->getDChannel ( CachedExample::D_EOH );
  17. eohimg.reInit ( xsize_s, ysize_s, 1, numBins);
  18. double *gradient = new double[xsize*ysize];
  19. int *dir = new int[xsize*ysize];
  20. if ( ce->colorInformationAvailable() ) {
  21. NICE::MultiChannelImage3DT<int> & colorimg = ce->getIChannel ( CachedExample::I_COLOR );
  22. std::vector<int*> data = colorimg.getDataPointer();
  23. const int *r = data[0];
  24. const int *g = data[1];
  25. const int *b = data[2];
  26. FastFilter::calcColorGradient ( r, g, b, xsize, ysize,
  27. gradient, dir, numBins, usesigned );
  28. } else {
  29. NICE::MultiChannelImage3DT<int> & grayvalues = ce->getIChannel ( CachedExample::I_GRAYVALUES );
  30. std::vector<int*> data = grayvalues.getDataPointer();
  31. const int *gr = data[0];
  32. FastFilter::calcGradient ( gr, xsize, ysize, gradient, dir, numBins, usesigned );
  33. }
  34. eohimg.setAll ( 0 );
  35. std::vector<double*> data = eohimg.getDataPointer();
  36. long korig = 0;
  37. for ( int y = 0 ; y < ysize ; y++ )
  38. for ( int x = 0 ; x < xsize ; x++, korig++ )
  39. {
  40. int xs = x / subsamplex;
  41. int ys = y / subsampley;
  42. if ( xs >= xsize_s ) xs = xsize_s - 1;
  43. if ( xs < 0 ) xs = 0;
  44. if ( ys >= ysize_s ) ys = ysize_s - 1;
  45. if ( ys < 0 ) ys = 0;
  46. int k = xs + ys * xsize_s;
  47. int val = dir[korig];
  48. double strength = gradient[korig];
  49. assert ( val < eohimg.channels() );
  50. data[val][k] += strength;
  51. if ( !NICE::isFinite( data[val][k] ) ) {
  52. fprintf ( stderr, "EOH Image failed: %f\n", data[val][k] );
  53. exit ( -1 );
  54. }
  55. }
  56. delete [] gradient;
  57. delete [] dir;
  58. NICE::MultiChannelImage3DT<double> & eohintimg = ce->getDChannel ( CachedExample::D_INTEGRALEOH );
  59. eohintimg.reInit ( xsize_s, ysize_s, 1, numBins );
  60. for ( uint i = 0 ; i < ( uint ) numBins ; i++ )
  61. {
  62. ImageT<double> tmpEohImg = eohimg.getChannelT(i);
  63. ImageT<double> tmpEohIntegralImg = eohintimg.getChannelT(i);
  64. GenericImageTools::calcIntegralImage ( tmpEohIntegralImg, tmpEohImg, xsize_s, ysize_s );
  65. }
  66. }