FIShotton.cpp 3.4 KB

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