FIShotton.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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; pce.y = y*subsampley + yi;
  40. fpcrf->getLeafNodes ( pce, leafs, maxdepthSegmentationForest );
  41. SparseVector v;
  42. for ( vector<DecisionNode *>::const_iterator i = leafs.begin();
  43. i != leafs.end();
  44. i++ )
  45. v.insert ( pair<int, double> ( index[*i].first, 1.0 ) );
  46. textonIndices[offset_s].add(v);
  47. }
  48. }
  49. }
  50. }
  51. fprintf (stderr, "Building Texton Integral NICE::Image !!\n");
  52. ce->buildIntegralSV ( CachedExample::SVTEXTON, textonIndices, xsize_s, ysize_s );
  53. }
  54. void FIShotton::buildSemanticMap ( CachedExample *ce,
  55. FPCRandomForests *fpcrf,
  56. int subsamplex, int subsampley,
  57. int numClasses )
  58. {
  59. int xsize, ysize;
  60. ce->getImageSize ( xsize, ysize );
  61. int xsize_s = xsize / subsamplex;
  62. int ysize_s = ysize / subsampley;
  63. NICE::MultiChannelImageT<double> & priorMap = ce->getDChannel ( CachedExample::D_INTEGRALPRIOR );
  64. priorMap.reInit ( xsize_s, ysize_s, numClasses, true );
  65. priorMap.setAll ( 0.0 );
  66. vector<DecisionNode *> leafs;
  67. Example pce ( ce, 0, 0 );
  68. long offset = 0;
  69. long offset_s = 0;
  70. for ( int y = 0 ; y < ysize_s ; y++ )
  71. {
  72. for ( int x = 0 ; x < xsize_s ; x++, offset_s++ )
  73. {
  74. for ( int yi = 0 ; yi < subsampley ; yi++ )
  75. {
  76. for ( int xi = 0 ; xi < subsamplex ; xi++ )
  77. {
  78. leafs.clear();
  79. pce.x = x*subsamplex + xi; pce.y = y*subsampley + yi;
  80. fpcrf->getLeafNodes ( pce, leafs );
  81. for ( vector<DecisionNode *>::const_iterator i = leafs.begin();
  82. i != leafs.end();
  83. i++ )
  84. {
  85. const FullVector & sv = (*i)->distribution;
  86. for ( int i = 0 ; i < sv.size(); i++ )
  87. {
  88. priorMap.data[i][offset_s] += sv[i];
  89. }
  90. }
  91. }
  92. }
  93. double sum = 0.0;
  94. for ( uint i = 0 ; i < priorMap.numChannels; i++ )
  95. sum += priorMap.data[i][offset_s];
  96. if ( sum < 10e-13 )
  97. {
  98. fprintf (stderr, "x*subsamplex %d y*subsampley %d xsize %d ysize %d\n",
  99. x*subsamplex, y*subsampley, xsize, ysize );
  100. exit(-1);
  101. } else {
  102. for ( uint i = 0 ; i < priorMap.numChannels; i++ )
  103. priorMap.data[i][offset_s] /= sum;
  104. }
  105. }
  106. }
  107. for ( uint i = 0 ; i < priorMap.numChannels ; i++ )
  108. GenericImageTools::calcIntegralImage ( priorMap.data[i], priorMap.data[i], priorMap.xsize, priorMap.ysize );
  109. }