FIShotton.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. * @file FIShotton.cpp
  3. * @brief feature images
  4. * @author Erik Rodner
  5. * @date 05/30/2008
  6. */
  7. #include <iostream>
  8. #include "FIShotton.h"
  9. #include "vislearning/baselib/FastFilter.h"
  10. #include "vislearning/image/GenericImageTools.h"
  11. using namespace OBJREC;
  12. using namespace std;
  13. using namespace NICE;
  14. void FIShotton::buildTextonMap( CachedExample *ce,
  15. FPCRandomForests *fpcrf,
  16. map<DecisionNode *, pair<long, int> > index,
  17. int subsamplex,
  18. int subsampley,
  19. int maxdepthSegmentationForest )
  20. {
  21. vector<DecisionNode *> leafs;
  22. int xsize, ysize;
  23. ce->getImageSize( xsize, ysize );
  24. int xsize_s = xsize / subsamplex;
  25. int ysize_s = ysize / subsampley;
  26. SparseVector *textonIndices = new SparseVector [xsize_s*ysize_s];
  27. Example pce( ce, 0, 0 );
  28. long offset = 0;
  29. long offset_s = 0;
  30. for ( int y = 0 ; y < ysize_s ; y++ )
  31. {
  32. for ( int x = 0 ; x < xsize_s ; x++, offset_s++ )
  33. {
  34. for ( int yi = 0 ; yi < subsampley ; yi++ )
  35. {
  36. for ( int xi = 0 ; xi < subsamplex ; xi++, offset++ )
  37. {
  38. leafs.clear();
  39. pce.x = x * subsamplex + xi;
  40. pce.y = y * subsampley + yi;
  41. fpcrf->getLeafNodes( pce, leafs, maxdepthSegmentationForest );
  42. SparseVector v;
  43. for ( vector<DecisionNode *>::const_iterator i = leafs.begin();
  44. i != leafs.end();
  45. i++ )
  46. v.insert( pair<int, double> ( index[*i].first, 1.0 ) );
  47. textonIndices[offset_s].add( v );
  48. }
  49. }
  50. }
  51. }
  52. fprintf( stderr, "Building Texton Integral NICE::Image !!\n" );
  53. ce->buildIntegralSV( CachedExample::SVTEXTON, textonIndices, xsize_s, ysize_s );
  54. }
  55. void FIShotton::buildSemanticMap( CachedExample *ce,
  56. FPCRandomForests *fpcrf,
  57. int subsamplex, int subsampley,
  58. int numClasses )
  59. {
  60. int xsize, ysize;
  61. ce->getImageSize( xsize, ysize );
  62. int xsize_s = xsize / subsamplex;
  63. int ysize_s = ysize / subsampley;
  64. NICE::MultiChannelImageT<double> & priorMap = ce->getDChannel( CachedExample::D_INTEGRALPRIOR );
  65. priorMap.reInit( xsize_s, ysize_s, numClasses, true );
  66. priorMap.setAll( 0.0 );
  67. vector<DecisionNode *> leafs;
  68. Example pce( ce, 0, 0 );
  69. long offset = 0;
  70. long offset_s = 0;
  71. for ( int y = 0 ; y < ysize_s ; y++ )
  72. {
  73. for ( int x = 0 ; x < xsize_s ; x++, offset_s++ )
  74. {
  75. for ( int yi = 0 ; yi < subsampley ; yi++ )
  76. {
  77. for ( int xi = 0 ; xi < subsamplex ; xi++ )
  78. {
  79. leafs.clear();
  80. pce.x = x * subsamplex + xi;
  81. pce.y = y * subsampley + yi;
  82. fpcrf->getLeafNodes( pce, leafs );
  83. for ( vector<DecisionNode *>::const_iterator i = leafs.begin();
  84. i != leafs.end();
  85. i++ )
  86. {
  87. const FullVector & sv = ( *i )->distribution;
  88. for ( int i = 0 ; i < sv.size(); i++ )
  89. {
  90. priorMap.data[i][offset_s] += sv[i];
  91. }
  92. }
  93. }
  94. }
  95. double sum = 0.0;
  96. for ( uint i = 0 ; i < priorMap.numChannels; i++ )
  97. sum += priorMap.data[i][offset_s];
  98. if ( sum < 10e-13 )
  99. {
  100. fprintf( stderr, "x*subsamplex %d y*subsampley %d xsize %d ysize %d\n",
  101. x*subsamplex, y*subsampley, xsize, ysize );
  102. exit( -1 );
  103. } else {
  104. for ( uint i = 0 ; i < priorMap.numChannels; i++ )
  105. priorMap.data[i][offset_s] /= sum;
  106. }
  107. }
  108. }
  109. for ( uint i = 0 ; i < priorMap.numChannels ; i++ )
  110. GenericImageTools::calcIntegralImage( priorMap.data[i], priorMap.data[i], priorMap.xsize, priorMap.ysize );
  111. }