FIGradients.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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::MultiChannelImageT<double> & eohimg = ce->getDChannel ( CachedExample::D_EOH );
  17. eohimg.reInit ( xsize_s, ysize_s, numBins, true );
  18. double *gradient = new double[xsize*ysize];
  19. int *dir = new int[xsize*ysize];
  20. if ( ce->colorInformationAvailable() ) {
  21. NICE::MultiChannelImageT<int> & colorimg = ce->getIChannel ( CachedExample::I_COLOR );
  22. const int *r = colorimg.data[0];
  23. const int *g = colorimg.data[1];
  24. const int *b = colorimg.data[2];
  25. FastFilter::calcColorGradient ( r,g,b,xsize,ysize,
  26. gradient, dir, numBins, usesigned );
  27. } else {
  28. NICE::MultiChannelImageT<int> & grayvalues = ce->getIChannel ( CachedExample::I_GRAYVALUES );
  29. const int *gr = grayvalues.data[0];
  30. FastFilter::calcGradient ( gr, xsize, ysize, gradient, dir, numBins, usesigned );
  31. }
  32. eohimg.setAll ( 0 );
  33. long korig = 0;
  34. for ( int y = 0 ; y < ysize ; y++ )
  35. for ( int x = 0 ; x < xsize ; x++,korig++ )
  36. {
  37. int xs = x / subsamplex;
  38. int ys = y / subsampley;
  39. if ( xs >= xsize_s ) xs = xsize_s-1;
  40. if ( xs < 0 ) xs = 0;
  41. if ( ys >= ysize_s ) ys = ysize_s-1;
  42. if ( ys < 0 ) ys = 0;
  43. int k = xs + ys*xsize_s;
  44. int val = dir[korig];
  45. double strength = gradient[korig];
  46. assert ( val < eohimg.numChannels );
  47. eohimg.data[val][k] += strength;
  48. if ( !finite(eohimg.data[val][k]) ) {
  49. fprintf (stderr, "EOH Image failed: %f\n", eohimg.data[val][k]);
  50. exit(-1);
  51. }
  52. }
  53. delete [] gradient;
  54. delete [] dir;
  55. NICE::MultiChannelImageT<double> & eohintimg = ce->getDChannel ( CachedExample::D_INTEGRALEOH );
  56. eohintimg.reInit ( xsize_s, ysize_s, numBins, true );
  57. for ( uint i = 0 ; i < (uint)numBins ; i++ )
  58. GenericImageTools::calcIntegralImage ( eohintimg.data[i], eohimg.data[i], xsize_s, ysize_s );
  59. }