/** * @file FIShotton.cpp * @brief feature images * @author Erik Rodner * @date 05/30/2008 */ #ifdef NOVISUAL #include #else #include #endif #include #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 > index, int subsamplex, int subsampley, int maxdepthSegmentationForest ) { vector 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::const_iterator i = leafs.begin(); i != leafs.end(); i++ ) v.insert ( pair ( 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 & priorMap = ce->getDChannel ( CachedExample::D_INTEGRALPRIOR ); priorMap.reInit ( xsize_s, ysize_s, numClasses, true ); priorMap.setAll ( 0.0 ); vector 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::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 ); }