123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- /**
- * @file FIShotton.cpp
- * @brief feature images
- * @author Erik Rodner
- * @date 05/30/2008
- */
- #ifdef NOVISUAL
- #include <objrec/nice_nonvis.h>
- #else
- #include <objrec/nice.h>
- #endif
- #include <iostream>
- #include "FIShotton.h"
- #include "objrec/baselib/FastFilter.h"
- #include "objrec/image/GenericImageTools.h"
- using namespace OBJREC;
- using namespace std;
- using namespace NICE;
- void FIShotton::buildTextonMap ( CachedExample *ce,
- FPCRandomForests *fpcrf,
- map<DecisionNode *, pair<long, int> > index,
- int subsamplex,
- int subsampley,
- int maxdepthSegmentationForest )
- {
- vector<DecisionNode *> leafs;
- int xsize, ysize;
- ce->getImageSize ( xsize, ysize );
- int xsize_s = xsize / subsamplex;
- int ysize_s = ysize / subsampley;
- SparseVector *textonIndices = new SparseVector [xsize_s*ysize_s];
-
- Example pce ( ce, 0, 0 );
- long offset = 0;
- long offset_s = 0;
- for ( int y = 0 ; y < ysize_s ; y++ )
- {
- for ( int x = 0 ; x < xsize_s ; x++, offset_s++ )
- {
- for ( int yi = 0 ; yi < subsampley ; yi++ )
- {
- for ( int xi = 0 ; xi < subsamplex ; xi++, offset++ )
- {
- leafs.clear();
- pce.x = x*subsamplex + xi; pce.y = y*subsampley + yi;
- fpcrf->getLeafNodes ( pce, leafs, maxdepthSegmentationForest );
- SparseVector v;
- for ( vector<DecisionNode *>::const_iterator i = leafs.begin();
- i != leafs.end();
- i++ )
- v.insert ( pair<int, double> ( index[*i].first, 1.0 ) );
- textonIndices[offset_s].add(v);
- }
- }
- }
- }
- fprintf (stderr, "Building Texton Integral NICE::Image !!\n");
- ce->buildIntegralSV ( CachedExample::SVTEXTON, textonIndices, xsize_s, ysize_s );
- }
- void FIShotton::buildSemanticMap ( CachedExample *ce,
- FPCRandomForests *fpcrf,
- int subsamplex, int subsampley,
- int numClasses )
- {
- int xsize, ysize;
- ce->getImageSize ( xsize, ysize );
- int xsize_s = xsize / subsamplex;
- int ysize_s = ysize / subsampley;
- GenericImage<double> & priorMap = ce->getDChannel ( CachedExample::D_INTEGRALPRIOR );
- priorMap.reInit ( xsize_s, ysize_s, numClasses, true );
- priorMap.setAll ( 0.0 );
-
- vector<DecisionNode *> leafs;
-
- Example pce ( ce, 0, 0 );
- long offset = 0;
- long offset_s = 0;
- for ( int y = 0 ; y < ysize_s ; y++ )
- {
- for ( int x = 0 ; x < xsize_s ; x++, offset_s++ )
- {
- for ( int yi = 0 ; yi < subsampley ; yi++ )
- {
- for ( int xi = 0 ; xi < subsamplex ; xi++ )
- {
- leafs.clear();
- pce.x = x*subsamplex + xi; pce.y = y*subsampley + yi;
- fpcrf->getLeafNodes ( pce, leafs );
-
- for ( vector<DecisionNode *>::const_iterator i = leafs.begin();
- i != leafs.end();
- i++ )
- {
- const FullVector & sv = (*i)->distribution;
- for ( int i = 0 ; i < sv.size(); i++ )
- {
- priorMap.data[i][offset_s] += sv[i];
- }
- }
- }
- }
- double sum = 0.0;
- for ( uint i = 0 ; i < priorMap.numChannels; i++ )
- sum += priorMap.data[i][offset_s];
-
- if ( sum < 10e-13 )
- {
- fprintf (stderr, "x*subsamplex %d y*subsampley %d xsize %d ysize %d\n",
- x*subsamplex, y*subsampley, xsize, ysize );
- exit(-1);
- } else {
- for ( uint i = 0 ; i < priorMap.numChannels; i++ )
- priorMap.data[i][offset_s] /= sum;
- }
- }
- }
- for ( uint i = 0 ; i < priorMap.numChannels ; i++ )
- GenericImageTools::calcIntegralImage ( priorMap.data[i], priorMap.data[i], priorMap.xsize, priorMap.ysize );
- }
|