Bjoern Froehlich 13 жил өмнө
parent
commit
a3805cf1bf

+ 0 - 1
progs/testSemanticSegmentation.cpp

@@ -17,7 +17,6 @@
 
 
 #include <objrec-froehlichexp/semseg/SemanticSegmentation.h>
 #include <objrec-froehlichexp/semseg/SemanticSegmentation.h>
 #include <objrec-froehlichexp/semseg/SemSegLocal.h>
 #include <objrec-froehlichexp/semseg/SemSegLocal.h>
-#include <objrec-froehlichexp/semseg/SemSegSTF.h>
 #include <objrec-froehlichexp/semseg/SemSegCsurka.h>
 #include <objrec-froehlichexp/semseg/SemSegCsurka.h>
 #include <objrec-froehlichexp/semseg/SemSegRegionBased.h>
 #include <objrec-froehlichexp/semseg/SemSegRegionBased.h>
 #include <objrec-froehlichexp/semseg/SemSegContextTree.h>
 #include <objrec-froehlichexp/semseg/SemSegContextTree.h>

+ 0 - 143
semseg/FIShotton.cpp

@@ -1,143 +0,0 @@
-/**
-* @file FIShotton.cpp
-* @brief feature images
-* @author Erik Rodner
-* @date 05/30/2008
-
-*/
-#include <iostream>
-
-#include "FIShotton.h"
-#include "vislearning/baselib/FastFilter.h"
-#include "vislearning/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;
-
-  NICE::MultiChannelImageT<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 );
-
-}
-

+ 0 - 42
semseg/FIShotton.h

@@ -1,42 +0,0 @@
-/**
-* @file FIShotton.h
-* @brief feature images for preprocessing according to shotton
-* @author Erik Rodner
-* @date 05/30/2008
-
-*/
-#ifndef FIShottonINCLUDE
-#define FIShottonINCLUDE
-
-#include "core/vector/SparseVectorT.h"
-#include "vislearning/cbaselib/CachedExample.h"
-#include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
-
-namespace OBJREC {
-
-/** feature images */
-
-class FIShotton
-{
-
-protected:
-
-public:
-
-  static void buildSemanticMap( CachedExample *ce,
-                                FPCRandomForests *fpcrf,
-                                int subsamplex, int subsampley,
-                                int numClasses );
-
-  static void buildTextonMap( CachedExample *ce,
-                              FPCRandomForests *fpcrf,
-                              std::map<DecisionNode *, std::pair<long, int> > index,
-                              int subsamplex,
-                              int subsampley,
-                              int maxdepthSegmentationForest );
-};
-
-
-} // namespace
-
-#endif

+ 5 - 4
semseg/SemSegContextTree.cpp

@@ -664,7 +664,7 @@ void SemSegContextTree::train ( const MultiDataset *md )
 #ifdef LOCALFEATS
 #ifdef LOCALFEATS
     lfcw->getFeats ( img, allfeats[imgcounter] );
     lfcw->getFeats ( img, allfeats[imgcounter] );
 #else
 #else
-    allfeats[imgcounter].reInit ( xsize, ysize, 3, true );
+    allfeats[imgcounter].reInit ( xsize, ysize, 3 );
 
 
     for ( int x = 0; x < xsize; x++ )
     for ( int x = 0; x < xsize; x++ )
     {
     {
@@ -1166,7 +1166,7 @@ void SemSegContextTree::semanticseg ( CachedExample *ce, NICE::Image & segresult
 
 
   fprintf ( stderr, "ContextTree classification !\n" );
   fprintf ( stderr, "ContextTree classification !\n" );
 
 
-  probabilities.reInit ( xsize, ysize, numClasses, true );
+  probabilities.reInit ( xsize, ysize, numClasses );
   probabilities.setAll ( 0 );
   probabilities.setAll ( 0 );
 
 
   NICE::ColorImage img;
   NICE::ColorImage img;
@@ -1192,7 +1192,7 @@ void SemSegContextTree::semanticseg ( CachedExample *ce, NICE::Image & segresult
 #ifdef LOCALFEATS
 #ifdef LOCALFEATS
   lfcw->getFeats ( img, feats );
   lfcw->getFeats ( img, feats );
 #else
 #else
-  feats.reInit ( xsize, ysize, 3, true );
+  feats.reInit ( xsize, ysize, 3 );
 
 
   for ( int x = 0; x < xsize; x++ )
   for ( int x = 0; x < xsize; x++ )
   {
   {
@@ -1261,6 +1261,7 @@ void SemSegContextTree::semanticseg ( CachedExample *ce, NICE::Image & segresult
     allleaf = true;
     allleaf = true;
     
     
     MultiChannelImageT<unsigned short int> lastfeats = currentfeats;
     MultiChannelImageT<unsigned short int> lastfeats = currentfeats;
+    
     int tree;
     int tree;
 #pragma omp parallel for private(tree)
 #pragma omp parallel for private(tree)
     for ( tree = 0; tree < nbTrees; tree++ )
     for ( tree = 0; tree < nbTrees; tree++ )
@@ -1356,7 +1357,7 @@ void SemSegContextTree::semanticseg ( CachedExample *ce, NICE::Image & segresult
 #endif
 #endif
 
 
   string cndir = conf->gS ( "SSContextTree", "cndir", "" );
   string cndir = conf->gS ( "SSContextTree", "cndir", "" );
-  int classes = ( int ) probabilities.numChannels;
+  int classes = ( int ) probabilities.channels();
   vector<int> useclass ( classes, 1 );
   vector<int> useclass ( classes, 1 );
 #ifdef WRITEGLOB
 #ifdef WRITEGLOB
   
   

+ 32 - 34
semseg/SemSegCsurka.cpp

@@ -1,12 +1,11 @@
+#include <sstream>
 #include <iostream>
 #include <iostream>
 
 
 #include "SemSegCsurka.h"
 #include "SemSegCsurka.h"
-
 #include "vislearning/baselib/ICETools.h"
 #include "vislearning/baselib/ICETools.h"
-
 #include "core/image/Filter.h"
 #include "core/image/Filter.h"
+#include "objrec-froehlichexp/semseg/postsegmentation/PSSImageLevelPrior.h"
 
 
-#include <sstream>
 
 
 using namespace std;
 using namespace std;
 using namespace NICE;
 using namespace NICE;
@@ -1204,7 +1203,7 @@ void SemSegCsurka::trainpostprocess ( const MultiDataset *md )
 
 
       NICE::Image segresult;
       NICE::Image segresult;
 
 
-      NICE::MultiChannelImageT<double> probabilities ( xsize, ysize, classno, true );
+      NICE::MultiChannelImageT<double> probabilities ( xsize, ysize, classno );
 
 
       Examples regions;
       Examples regions;
 
 
@@ -1295,8 +1294,8 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
 
 
   ce->getImageSize ( xsize, ysize );
   ce->getImageSize ( xsize, ysize );
 
 
-  probabilities.reInit ( xsize, ysize, classNames->getMaxClassno() + 1, true/*allocMem*/ );
-  clog << "[log] SemSegCsruka::classifyregions: probabilities.numChannels = " << probabilities.numChannels << endl;
+  probabilities.reInit ( xsize, ysize, classNames->getMaxClassno() + 1 );
+  clog << "[log] SemSegCsruka::classifyregions: probabilities.channels() = " << probabilities.channels() << endl;
 
 
   segresult.resize ( xsize, ysize );
   segresult.resize ( xsize, ysize );
 
 
@@ -1427,25 +1426,23 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
   /////////////////////////////////////////
   /////////////////////////////////////////
   // Wahrscheinlichkeitskarten erstellen //
   // Wahrscheinlichkeitskarten erstellen //
   /////////////////////////////////////////
   /////////////////////////////////////////
-  int klassen = probabilities.numChannels;
-  NICE::MultiChannelImageT<double> preMap ( xsize, ysize, klassen*scales.size(), true );
-
-  long int offset = 0;
+  int klassen = probabilities.channels();
+  NICE::MultiChannelImageT<double> preMap ( xsize, ysize, klassen*scales.size() );
 
 
   // initialisieren
   // initialisieren
   for ( int y = 0 ; y < ysize ; y++ )
   for ( int y = 0 ; y < ysize ; y++ )
-    for ( int x = 0 ; x < xsize ; x++, offset++ )
+    for ( int x = 0 ; x < xsize ; x++ )
     {
     {
       // alles zum Hintergrund machen
       // alles zum Hintergrund machen
       segresult.setPixel ( x, y, 0 );
       segresult.setPixel ( x, y, 0 );
       // Die Wahrscheinlichkeitsmaps auf 0 initialisieren
       // Die Wahrscheinlichkeitsmaps auf 0 initialisieren
-      for ( int i = 0 ; i < ( int ) probabilities.numChannels; i++ )
+      for ( int i = 0 ; i < ( int ) probabilities.channels(); i++ )
       {
       {
-        probabilities.data[i][offset] = 0.0;
+        probabilities[i](x,y) = 0.0;
       }
       }
-      for ( int j = 0; j < ( int ) preMap.numChannels; j++ )
+      for ( int j = 0; j < ( int ) preMap.channels(); j++ )
       {
       {
-        preMap.data[j][offset] = 0.0;
+        preMap[j](x,y) = 0.0;
       }
       }
     }
     }
 
 
@@ -1453,7 +1450,7 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
   int scalesize = scales.size();
   int scalesize = scales.size();
 
 
   // Globale Häufigkeiten akkumulieren
   // Globale Häufigkeiten akkumulieren
-  FullVector fV ( ( int ) probabilities.numChannels );
+  FullVector fV ( ( int ) probabilities.channels() );
 
 
   for ( int i = 0; i < fV.size(); i++ )
   for ( int i = 0; i < fV.size(); i++ )
     fV[i] = 0.0;
     fV[i] = 0.0;
@@ -1461,7 +1458,7 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
   // read allowed classes
   // read allowed classes
 
 
   string cndir = conf->gS ( "SemSegCsurka", "cndir", "" );
   string cndir = conf->gS ( "SemSegCsurka", "cndir", "" );
-  int classes = ( int ) probabilities.numChannels;
+  int classes = ( int ) probabilities.channels();
   vector<int> useclass ( classes, 1 );
   vector<int> useclass ( classes, 1 );
 
 
   std::vector< std::string > list;
   std::vector< std::string > list;
@@ -1585,7 +1582,7 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
 #undef VISSEMSEG
 #undef VISSEMSEG
 #ifdef VISSEMSEG
 #ifdef VISSEMSEG
 
 
-  for ( int j = 0 ; j < ( int ) preMap.numChannels; j++ )
+  for ( int j = 0 ; j < ( int ) preMap.channels(); j++ )
   {
   {
     cout << "klasse: " << j << endl;//" " << cn.text ( j ) << endl;
     cout << "klasse: " << j << endl;//" " << cn.text ( j ) << endl;
 
 
@@ -1631,35 +1628,36 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
 
 
       int pos = i + s * klassen;
       int pos = i + s * klassen;
 
 
-      double maxval = preMap.data[pos][0];
-      double minval = preMap.data[pos][0];
+      double maxval = preMap[pos](0,0);
+      double minval = maxval;
 
 
-      for ( int z = 1; z < xsize*ysize; z++ )
+      for ( int y = 0; y < ysize; y++ )
       {
       {
-        maxval = std::max ( maxval, preMap.data[pos][z] );
-        minval = std::min ( minval, preMap.data[pos][z] );
+        for ( int x = 0; x < xsize; x++ )
+        {
+          maxval = std::max ( maxval, preMap[pos](x,y) );
+          minval = std::min ( minval, preMap[pos](x,y) );
+        }
       }
       }
 
 
       NICE::FloatImage dblImg ( xsize, ysize );
       NICE::FloatImage dblImg ( xsize, ysize );
       NICE::FloatImage gaussImg ( xsize, ysize );
       NICE::FloatImage gaussImg ( xsize, ysize );
 
 
-      long int offset2 = 0;
       for ( int y = 0; y < ysize; y++ )
       for ( int y = 0; y < ysize; y++ )
       {
       {
-        for ( int x = 0; x < xsize; x++, offset2++ )
+        for ( int x = 0; x < xsize; x++ )
         {
         {
-          dblImg.setPixel ( x, y, preMap.data[pos][offset2] );
+          dblImg.setPixel ( x, y, preMap[pos](x,y) );
         }
         }
       }
       }
 
 
       filterGaussSigmaApproximate<float, float, float> ( dblImg, sigma, &gaussImg );
       filterGaussSigmaApproximate<float, float, float> ( dblImg, sigma, &gaussImg );
 
 
-      offset2 = 0;
       for ( int y = 0; y < ysize; y++ )
       for ( int y = 0; y < ysize; y++ )
       {
       {
-        for ( int x = 0; x < xsize; x++, offset2++ )
+        for ( int x = 0; x < xsize; x++ )
         {
         {
-          preMap.data[pos][offset2] = gaussImg.getPixel ( x, y );
+          preMap[pos](x,y) = gaussImg.getPixel ( x, y );
         }
         }
       }
       }
     }
     }
@@ -1676,7 +1674,7 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
   {
   {
     for ( int y = 0; y < ysize; y++ )
     for ( int y = 0; y < ysize; y++ )
     {
     {
-      for ( int j = 0 ; j < ( int ) probabilities.numChannels; j++ )
+      for ( int j = 0 ; j < ( int ) probabilities.channels(); j++ )
       {
       {
         double prob = 0.0;
         double prob = 0.0;
         for ( int s = 0; s < ( int ) scalesize; s++ )
         for ( int s = 0; s < ( int ) scalesize; s++ )
@@ -1751,7 +1749,7 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
 
 
   probabilities.store ( s );
   probabilities.store ( s );
 
 
-  for ( int j = 0 ; j < ( int ) probabilities.numChannels; j++ )
+  for ( int j = 0 ; j < ( int ) probabilities.channels(); j++ )
   {
   {
     cout << "klasse: " << j << endl;//" " << cn.text ( j ) << endl;
     cout << "klasse: " << j << endl;//" " << cn.text ( j ) << endl;
 
 
@@ -1807,7 +1805,7 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
     for ( int i = 0; i < regionsize; i++ )
     for ( int i = 0; i < regionsize; i++ )
     {
     {
       vector<double> tmp;
       vector<double> tmp;
-      for ( int j = 0; j < ( int ) probabilities.numChannels; j++ )
+      for ( int j = 0; j < ( int ) probabilities.channels(); j++ )
       {
       {
         tmp.push_back ( 0.0 );
         tmp.push_back ( 0.0 );
       }
       }
@@ -1827,7 +1825,7 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
         Regionen[pos].second.weight += 1.0;
         Regionen[pos].second.weight += 1.0;
         Regionen[pos].second.x += x;
         Regionen[pos].second.x += x;
         Regionen[pos].second.y += y;
         Regionen[pos].second.y += y;
-        for ( int j = 0 ; j < ( int ) probabilities.numChannels; j++ )
+        for ( int j = 0 ; j < ( int ) probabilities.channels(); j++ )
         {
         {
           double val = probabilities.get ( x, y, j );
           double val = probabilities.get ( x, y, j );
           regionprob[pos][j] += val;
           regionprob[pos][j] += val;
@@ -1993,7 +1991,7 @@ void SemSegCsurka::semanticseg ( CachedExample *ce, NICE::Image & segresult, NIC
 #undef VISSEMSEG
 #undef VISSEMSEG
 #ifdef VISSEMSEG
 #ifdef VISSEMSEG
 //  showImage(img);
 //  showImage(img);
-  for ( int j = 0 ; j < ( int ) probabilities.numChannels; j++ )
+  for ( int j = 0 ; j < ( int ) probabilities.channels(); j++ )
   {
   {
     cout << "klasse: " << j << " " << cn.text ( j ) << endl;
     cout << "klasse: " << j << " " << cn.text ( j ) << endl;
 
 

+ 0 - 1
semseg/SemSegCsurka.h

@@ -38,7 +38,6 @@
 #include "vislearning/classifier/fpclassifier/logisticregression/FPCSMLR.h"
 #include "vislearning/classifier/fpclassifier/logisticregression/FPCSMLR.h"
 #include "fast-hik/GPHIKClassifier.h"
 #include "fast-hik/GPHIKClassifier.h"
 
 
-#include "objrec-froehlichexp/semseg/postsegmentation/PSSImageLevelPrior.h"
 #include "objrec-froehlichexp/semseg/postsegmentation/RelativeLocationPrior.h"
 #include "objrec-froehlichexp/semseg/postsegmentation/RelativeLocationPrior.h"
 #include "objrec-froehlichexp/semseg/postsegmentation/PPSuperregion.h"
 #include "objrec-froehlichexp/semseg/postsegmentation/PPSuperregion.h"
 #include "objrec-froehlichexp/semseg/postsegmentation/PPGraphCut.h"
 #include "objrec-froehlichexp/semseg/postsegmentation/PPGraphCut.h"

+ 73 - 72
semseg/SemSegLocal.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file SemSegLocal.cpp
 * @file SemSegLocal.cpp
 * @brief semantic segmentation using image patches only
 * @brief semantic segmentation using image patches only
 * @author Erik Rodner
 * @author Erik Rodner
@@ -12,7 +12,7 @@
 #include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
 #include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
 #include "vislearning/features/fpfeatures/PixelPairFeature.h"
 #include "vislearning/features/fpfeatures/PixelPairFeature.h"
 
 
-#include "SemSegTools.h" 
+#include "SemSegTools.h"
 
 
 using namespace OBJREC;
 using namespace OBJREC;
 
 
@@ -20,88 +20,89 @@ using namespace std;
 using namespace NICE;
 using namespace NICE;
 
 
 
 
-SemSegLocal::SemSegLocal( const Config *conf, 
-			  const MultiDataset *md  )
-    : SemanticSegmentation ( conf, &(md->getClassNames("train")) )
+SemSegLocal::SemSegLocal ( const Config *conf,
+                           const MultiDataset *md )
+    : SemanticSegmentation ( conf, & ( md->getClassNames ( "train" ) ) )
 {
 {
-    save_cache = conf->gB("FPCPixel", "save_cache", true );
-    read_cache = conf->gB("FPCPixel", "read_cache", false );
-    cache = conf->gS("FPCPixel", "cache", "fpc.data" );
-    fpc = new FPCRandomForests ( conf, "FPCPixel" );
-    fpc->setMaxClassNo ( classNames->getMaxClassno() );
-
-    
-    if ( read_cache ) {
-	fprintf (stderr, "LocSSimpleFP:: Reading classifier data from %s\n", cache.c_str() );
-	fpc->read ( cache );
-	fprintf (stderr, "LocSSimpleFP:: successfully read\n" );
-    } else {
-	train ( conf, md );
-    }
+  save_cache = conf->gB ( "FPCPixel", "save_cache", true );
+  read_cache = conf->gB ( "FPCPixel", "read_cache", false );
+  cache = conf->gS ( "FPCPixel", "cache", "fpc.data" );
+  fpc = new FPCRandomForests ( conf, "FPCPixel" );
+  fpc->setMaxClassNo ( classNames->getMaxClassno() );
+
+
+  if ( read_cache ) {
+    fprintf ( stderr, "LocSSimpleFP:: Reading classifier data from %s\n", cache.c_str() );
+    fpc->read ( cache );
+    fprintf ( stderr, "LocSSimpleFP:: successfully read\n" );
+  } else {
+    train ( conf, md );
+  }
 }
 }
-	
+
 void SemSegLocal::train ( const Config *conf, const MultiDataset *md )
 void SemSegLocal::train ( const Config *conf, const MultiDataset *md )
 {
 {
-    Examples examples;
-    vector<CachedExample *> imgexamples;
-
-    SemSegTools::collectTrainingExamples ( 
-	conf, 
-	"FPCPixel", // config section for grid settings
-	*((*md)["train"]),
-	*classNames, 
-	examples, 
-	imgexamples );
-
-    assert ( examples.size() > 0 );
-    
-    FeaturePool fp;
-    PixelPairFeature hf (conf);
-    hf.explode ( fp );
-
-    fpc->train ( fp, examples );
-
-    // clean up memory !!
-    for ( vector<CachedExample *>::iterator i = imgexamples.begin();
-		    i != imgexamples.end();
-		    i++ )
-	delete ( *i );
-
-    if ( save_cache ) {
-	fpc->save ( cache );
-    }
+  Examples examples;
+  vector<CachedExample *> imgexamples;
+
+  SemSegTools::collectTrainingExamples (
+    conf,
+    "FPCPixel", // config section for grid settings
+    * ( ( *md ) ["train"] ),
+    *classNames,
+    examples,
+    imgexamples );
+
+  assert ( examples.size() > 0 );
 
 
-    fp.destroy();
+  FeaturePool fp;
+  PixelPairFeature hf ( conf );
+  hf.explode ( fp );
+
+  fpc->train ( fp, examples );
+
+  // clean up memory !!
+  for ( vector<CachedExample *>::iterator i = imgexamples.begin();
+        i != imgexamples.end();
+        i++ )
+    delete ( *i );
+
+  if ( save_cache ) {
+    fpc->save ( cache );
+  }
+
+  fp.destroy();
 }
 }
 
 
 
 
 SemSegLocal::~SemSegLocal()
 SemSegLocal::~SemSegLocal()
 {
 {
-    if ( fpc != NULL )
-	delete fpc;
+  if ( fpc != NULL )
+    delete fpc;
 }
 }
 
 
 
 
-void SemSegLocal::semanticseg ( CachedExample *ce, 
-			   NICE::Image & segresult,
-			   NICE::MultiChannelImageT<double> & probabilities )
+void SemSegLocal::semanticseg ( CachedExample *ce,
+                                NICE::Image & segresult,
+                                NICE::MultiChannelImageT<double> & probabilities )
 {
 {
-    // for speed optimization
-    FPCRandomForests *fpcrf = dynamic_cast<FPCRandomForests *> ( fpc );
-    int xsize, ysize;
-    ce->getImageSize ( xsize, ysize );
-    probabilities.reInit ( xsize, ysize, classNames->getMaxClassno()+1, true/*allocMem*/ );
-    segresult.resize(xsize, ysize);
-    
-    Example pce ( ce, 0, 0 );
-    long int offset = 0;
-    for ( int y = 0 ; y < ysize ; y++ ) 
-	for ( int x = 0 ; x < xsize ; x++,offset++ )  
-	{
-	    pce.x = x ; pce.y = y; 
-	    ClassificationResult r = fpcrf->classify ( pce );
-	    segresult.setPixel(x,y,r.classno);
-	    for ( int i = 0 ; i < (int)probabilities.numChannels; i++ )
-		probabilities.data[i][offset] = r.scores[i];
-	}
+  // for speed optimization
+  FPCRandomForests *fpcrf = dynamic_cast<FPCRandomForests *> ( fpc );
+  int xsize, ysize;
+  ce->getImageSize ( xsize, ysize );
+  probabilities.reInit ( xsize, ysize, classNames->getMaxClassno() + 1 );
+  segresult.resize ( xsize, ysize );
+
+  Example pce ( ce, 0, 0 );
+  long int offset = 0;
+  for ( int y = 0 ; y < ysize ; y++ )
+    for ( int x = 0 ; x < xsize ; x++, offset++ )
+    {
+      pce.x = x ;
+      pce.y = y;
+      ClassificationResult r = fpcrf->classify ( pce );
+      segresult.setPixel ( x, y, r.classno );
+      for ( int i = 0 ; i < ( int ) probabilities.channels(); i++ )
+        probabilities[i](x,y) = r.scores[i];
+    }
 }
 }

+ 1317 - 1317
semseg/SemSegRegionBased.cpp

@@ -52,1389 +52,1389 @@ using namespace NICE;
 
 
 #define DEBUG_PRINTS
 #define DEBUG_PRINTS
 
 
-SemSegRegionBased::SemSegRegionBased(const Config *c, const MultiDataset *md)
-		: SemanticSegmentation(c, &(md->getClassNames("train")))
+SemSegRegionBased::SemSegRegionBased ( const Config *c, const MultiDataset *md )
+    : SemanticSegmentation ( c, & ( md->getClassNames ( "train" ) ) )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased Constructor starts" << endl;
-	#endif
-	conf = c;	
-	
-	save_cache = conf->gB("SemSegRegion", "save_cache", true);
-	read_cache = conf->gB("SemSegRegion", "read_cache", false);
-	classifiercache = conf->gS("SemSegRegion", "cache", "classifier.data");
-	cache = conf->gS("cache", "root", "tmp/");
-	bool colorw = conf->gB("SemSegRegion", "colorw", false);
-	bool bov = conf->gB("SemSegRegion", "bov", false);
-	bool hog = conf->gB("SemSegRegion", "hog", false);
-	bool structf = conf->gB("SemSegRegion", "struct", false);
-	string classifiertype = conf->gS("SemSegRegion", "classifier", "RF");
-	bool usegcopt = conf->gB("SemSegRegion", "gcopt", false);
-	bool bovmoosmann = conf->gB("SemSegRegion", "bovmoosmann", false);
-	bool csurka = conf->gB("SemSegRegion", "csurka", false);
-	
-	if(colorw)
-	{
-		LocalFeature *lfcw = new LFColorWeijer(conf);
-		rfc = new RFColor(conf, lfcw);
-	}
-	else
-	{
-		rfc = NULL;
-	}
-	
-	if(hog)
-	{
-		rfhog = new RFHoG(conf);
-	}
-	else
-	{
-		rfhog = NULL;
-	}
-	
-	if(structf)
-	{
-		rfstruct = new RFStruct(conf);
-	}
-	else
-	{
-		rfstruct = NULL;
-	}
-	
-	LocalFeature *lfcache = NULL;
-	
-	if(bov || bovmoosmann || csurka)
-	{
-		string ftype = conf->gS("BOV", "feature", "sift");
-		
-		siftFeats = NULL;
-		
-		if(ftype == "sift")
-		{
-			siftFeats = new LocalFeatureSift ( conf );
-			lfcache = new LFCache(conf, siftFeats);
-		}
-		
-		if(ftype == "osift")
-		{
-			siftFeats = new LocalFeatureOpponnentSift ( conf );
-			lfcache = new LFCache(conf, siftFeats);
-		}
-		
-		if(ftype == "rsift")
-		{
-			siftFeats = new LocalFeatureRGBSift ( conf );
-			lfcache = new LFCache(conf, siftFeats);
-		}
-		
-		if(ftype == "sande")
-		{
-			LocalFeatureRepresentation *sande = new LFColorSande(conf, "LFColorSandeTrain");
-			siftFeats = new LocalFeatureLFInterface ( conf, sande);
-			
-			LocalFeatureRepresentation *sande2 = new LFColorSande(conf, "LFColorSandeTest");
-			LocalFeature *siftFeats2 = new LocalFeatureLFInterface ( conf, sande2);
-			lfcache = new LFCache(conf, siftFeats2);
-		}
-		
-		if(siftFeats == NULL)
-		{
-			throw "please choose one of the following features für BOV: osift, rsift, sift, sande";
-		}
-	}
-
-	if(csurka)
-	{
-		rfCsurka = new RFCsurka(conf, lfcache);
-	}
-	else
-	{
-		rfCsurka = NULL;
-	}
-
-	if(bov)
-	{
-		rfbov = new RFBoV (conf, lfcache);
-	}
-	else 
-	{
-		rfbov = NULL;
-	}
-	
-	if(bovmoosmann)
-	{
-		rfbovcrdf = new RFBoVCodebook (conf, lfcache);
-	}
-	else
-	{
-		rfbovcrdf = NULL;
-	}
-	
-	// setting classifier
-	fpc = NULL;
-	vclassifier = NULL;
-	
-	if(classifiertype == "RF")
-	{
-		fpc = new FPCRandomForests(conf, "ClassifierForest");
-	}
-	else if(classifiertype == "SMLR")
-	{
-		fpc = new FPCSMLR(conf, "ClassifierSMLR");
-	}
-	else if(classifiertype == "VECC")
-	{
-		vclassifier = CSGeneric::selectVecClassifier ( conf, "vecClassifier" );
-	}
-	else
-	{
-		throw "classifiertype not (yet) supported";
-	}
-	
-	if(fpc != NULL)
-		fpc->setMaxClassNo(classNames->getMaxClassno());
-	else if(vclassifier != NULL)
-		vclassifier->setMaxClassNo(classNames->getMaxClassno());
-
-	cn = md->getClassNames ( "train" );
-	
-	// setting segmentation method
-	RegionSegmentationMethod *tmprsm = new RSMeanShift(conf);
-	rsm = new RSCache ( conf, tmprsm );
-	//rsm = new RSGraphBased(conf);
-
-	// use global optimization (MRF)
-	if(usegcopt)
-		gcopt = new PPGraphCut ( conf );
-	else
-		gcopt = NULL;
-	
-	classifiercache = cache+classifiercache;
-	
-	// read training data or start training
-	if (read_cache)
-	{
-		fprintf(stderr, "SemSegRegion:: Reading classifier data from %s\n", cache.c_str());
-		if(fpc != NULL)
-			fpc->read(classifiercache);
-		else if(vclassifier != NULL)
-			vclassifier->read(classifiercache);
-		
-		if(rfCsurka != NULL)
-		{
-			bool usegmm = conf->gB("Csurka", "usegmm", false);
-			bool usepca = conf->gB("Csurka", "usepca", false);
-			
-			if(usepca || usegmm)
-			{
-				RFCsurka *_rfcsurka = dynamic_cast< RFCsurka * >(rfCsurka);
-				
-				if(usepca)
-				{
-					int pcadim = conf->gI("Csurka", "pcadim", 100);
-					PCA *pca = new PCA(pcadim);
-					string pcadst = cache+"/csurka.pca";
-
-					if (!FileMgt::fileExists(pcadst))
-					{
-						throw(pcadst+" not found");
-					}
-					else
-					{
-						pca->read ( pcadst );
-					}
-					
-					_rfcsurka->setPCA(pca);
-				}
-				
-				if(usegmm)
-				{
-					int gaussians = conf->gI("Csurka", "gaussians", 1024);
-					GMM *g = new GMM( conf, gaussians );
-					string gmmdst = cache+"/csurka.gmm";
-					
-					if ( !g->loadData ( cache+"/gmmSIFT" ) )
-					{
-						throw(gmmdst+" not found");
-					}
-
-					_rfcsurka->setGMM(g);
-				}
-			}
-		}
-		
-		if(rfbov != NULL)
-		{
-			RFBoV *rfbovdyn = dynamic_cast< RFBoV * >(rfbov);
-			
-			int gaussians = conf->gI("SIFTTrain", "gaussians", 512);
-			
-			GMM *g = new GMM( conf, gaussians );
-			PCA *pca = new PCA(100);
-			string pcadst = cache+"/bov.pca";
-	
-			if ( !g->loadData ( cache+"/gmmSIFT" ) || !FileMgt::fileExists(pcadst))
-			{
-				throw("pca or gmm not found");
-			}
-			else
-			{
-				pca->read ( pcadst );
-			}
-			rfbovdyn->setPCA(pca);
-			rfbovdyn->setGMM(g);
-		}
-		
-		fprintf(stderr, "SemSegRegion:: successfully read\n");
-	}
-	else
-	{
-		train(md);
-	}
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased Constructor finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased Constructor starts" << endl;
+#endif
+  conf = c;
+
+  save_cache = conf->gB ( "SemSegRegion", "save_cache", true );
+  read_cache = conf->gB ( "SemSegRegion", "read_cache", false );
+  classifiercache = conf->gS ( "SemSegRegion", "cache", "classifier.data" );
+  cache = conf->gS ( "cache", "root", "tmp/" );
+  bool colorw = conf->gB ( "SemSegRegion", "colorw", false );
+  bool bov = conf->gB ( "SemSegRegion", "bov", false );
+  bool hog = conf->gB ( "SemSegRegion", "hog", false );
+  bool structf = conf->gB ( "SemSegRegion", "struct", false );
+  string classifiertype = conf->gS ( "SemSegRegion", "classifier", "RF" );
+  bool usegcopt = conf->gB ( "SemSegRegion", "gcopt", false );
+  bool bovmoosmann = conf->gB ( "SemSegRegion", "bovmoosmann", false );
+  bool csurka = conf->gB ( "SemSegRegion", "csurka", false );
+
+  if ( colorw )
+  {
+    LocalFeature *lfcw = new LFColorWeijer ( conf );
+    rfc = new RFColor ( conf, lfcw );
+  }
+  else
+  {
+    rfc = NULL;
+  }
+
+  if ( hog )
+  {
+    rfhog = new RFHoG ( conf );
+  }
+  else
+  {
+    rfhog = NULL;
+  }
+
+  if ( structf )
+  {
+    rfstruct = new RFStruct ( conf );
+  }
+  else
+  {
+    rfstruct = NULL;
+  }
+
+  LocalFeature *lfcache = NULL;
+
+  if ( bov || bovmoosmann || csurka )
+  {
+    string ftype = conf->gS ( "BOV", "feature", "sift" );
+
+    siftFeats = NULL;
+
+    if ( ftype == "sift" )
+    {
+      siftFeats = new LocalFeatureSift ( conf );
+      lfcache = new LFCache ( conf, siftFeats );
+    }
+
+    if ( ftype == "osift" )
+    {
+      siftFeats = new LocalFeatureOpponnentSift ( conf );
+      lfcache = new LFCache ( conf, siftFeats );
+    }
+
+    if ( ftype == "rsift" )
+    {
+      siftFeats = new LocalFeatureRGBSift ( conf );
+      lfcache = new LFCache ( conf, siftFeats );
+    }
+
+    if ( ftype == "sande" )
+    {
+      LocalFeatureRepresentation *sande = new LFColorSande ( conf, "LFColorSandeTrain" );
+      siftFeats = new LocalFeatureLFInterface ( conf, sande );
+
+      LocalFeatureRepresentation *sande2 = new LFColorSande ( conf, "LFColorSandeTest" );
+      LocalFeature *siftFeats2 = new LocalFeatureLFInterface ( conf, sande2 );
+      lfcache = new LFCache ( conf, siftFeats2 );
+    }
+
+    if ( siftFeats == NULL )
+    {
+      throw "please choose one of the following features für BOV: osift, rsift, sift, sande";
+    }
+  }
+
+  if ( csurka )
+  {
+    rfCsurka = new RFCsurka ( conf, lfcache );
+  }
+  else
+  {
+    rfCsurka = NULL;
+  }
+
+  if ( bov )
+  {
+    rfbov = new RFBoV ( conf, lfcache );
+  }
+  else
+  {
+    rfbov = NULL;
+  }
+
+  if ( bovmoosmann )
+  {
+    rfbovcrdf = new RFBoVCodebook ( conf, lfcache );
+  }
+  else
+  {
+    rfbovcrdf = NULL;
+  }
+
+  // setting classifier
+  fpc = NULL;
+  vclassifier = NULL;
+
+  if ( classifiertype == "RF" )
+  {
+    fpc = new FPCRandomForests ( conf, "ClassifierForest" );
+  }
+  else if ( classifiertype == "SMLR" )
+  {
+    fpc = new FPCSMLR ( conf, "ClassifierSMLR" );
+  }
+  else if ( classifiertype == "VECC" )
+  {
+    vclassifier = CSGeneric::selectVecClassifier ( conf, "vecClassifier" );
+  }
+  else
+  {
+    throw "classifiertype not (yet) supported";
+  }
+
+  if ( fpc != NULL )
+    fpc->setMaxClassNo ( classNames->getMaxClassno() );
+  else if ( vclassifier != NULL )
+    vclassifier->setMaxClassNo ( classNames->getMaxClassno() );
+
+  cn = md->getClassNames ( "train" );
+
+  // setting segmentation method
+  RegionSegmentationMethod *tmprsm = new RSMeanShift ( conf );
+  rsm = new RSCache ( conf, tmprsm );
+  //rsm = new RSGraphBased(conf);
+
+  // use global optimization (MRF)
+  if ( usegcopt )
+    gcopt = new PPGraphCut ( conf );
+  else
+    gcopt = NULL;
+
+  classifiercache = cache + classifiercache;
+
+  // read training data or start training
+  if ( read_cache )
+  {
+    fprintf ( stderr, "SemSegRegion:: Reading classifier data from %s\n", cache.c_str() );
+    if ( fpc != NULL )
+      fpc->read ( classifiercache );
+    else if ( vclassifier != NULL )
+      vclassifier->read ( classifiercache );
+
+    if ( rfCsurka != NULL )
+    {
+      bool usegmm = conf->gB ( "Csurka", "usegmm", false );
+      bool usepca = conf->gB ( "Csurka", "usepca", false );
+
+      if ( usepca || usegmm )
+      {
+        RFCsurka *_rfcsurka = dynamic_cast< RFCsurka * > ( rfCsurka );
+
+        if ( usepca )
+        {
+          int pcadim = conf->gI ( "Csurka", "pcadim", 100 );
+          PCA *pca = new PCA ( pcadim );
+          string pcadst = cache + "/csurka.pca";
+
+          if ( !FileMgt::fileExists ( pcadst ) )
+          {
+            throw ( pcadst + " not found" );
+          }
+          else
+          {
+            pca->read ( pcadst );
+          }
+
+          _rfcsurka->setPCA ( pca );
+        }
+
+        if ( usegmm )
+        {
+          int gaussians = conf->gI ( "Csurka", "gaussians", 1024 );
+          GMM *g = new GMM ( conf, gaussians );
+          string gmmdst = cache + "/csurka.gmm";
+
+          if ( !g->loadData ( cache + "/gmmSIFT" ) )
+          {
+            throw ( gmmdst + " not found" );
+          }
+
+          _rfcsurka->setGMM ( g );
+        }
+      }
+    }
+
+    if ( rfbov != NULL )
+    {
+      RFBoV *rfbovdyn = dynamic_cast< RFBoV * > ( rfbov );
+
+      int gaussians = conf->gI ( "SIFTTrain", "gaussians", 512 );
+
+      GMM *g = new GMM ( conf, gaussians );
+      PCA *pca = new PCA ( 100 );
+      string pcadst = cache + "/bov.pca";
+
+      if ( !g->loadData ( cache + "/gmmSIFT" ) || !FileMgt::fileExists ( pcadst ) )
+      {
+        throw ( "pca or gmm not found" );
+      }
+      else
+      {
+        pca->read ( pcadst );
+      }
+      rfbovdyn->setPCA ( pca );
+      rfbovdyn->setGMM ( g );
+    }
+
+    fprintf ( stderr, "SemSegRegion:: successfully read\n" );
+  }
+  else
+  {
+    train ( md );
+  }
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased Constructor finished" << endl;
+#endif
 }
 }
 
 
 SemSegRegionBased::~SemSegRegionBased()
 SemSegRegionBased::~SemSegRegionBased()
 {
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased Destructor starts" << endl;
-	#endif
-	if (fpc != NULL)
-	{
-		delete fpc;
-	}
-	if(vclassifier != NULL)
-	{
-		delete vclassifier;
-	}
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased Destructor finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased Destructor starts" << endl;
+#endif
+  if ( fpc != NULL )
+  {
+    delete fpc;
+  }
+  if ( vclassifier != NULL )
+  {
+    delete vclassifier;
+  }
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased Destructor finished" << endl;
+#endif
 }
 }
 
 
-void SemSegRegionBased::train(const MultiDataset *md)
+void SemSegRegionBased::train ( const MultiDataset *md )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::train starts" << endl;
-	#endif
-	
-	Examples examples;
-	examples.filename = "training";
-	
-	const LabeledSet train = * ( *md ) ["train"];
-	
-	set<int> forbidden_classes;
-	
-	std::string forbidden_classes_s = conf->gS ( "analysis", "donttrain", "" );
-	if ( forbidden_classes_s == "" )
-	{
-		forbidden_classes_s = conf->gS ( "analysis", "forbidden_classes", "" );
-	}
-	
-	cn.getSelection ( forbidden_classes_s, forbidden_classes );
-
-	if(gcopt != NULL)
-		gcopt->setClassNo ( cn.numClasses() );
-	
-	LabeledSet::Permutation perm;
-
-	train.getPermutation(perm);
-
-	learnHighLevel(perm);
-
-	//FIXME:Moosmann
-	
-	int imgcounter = 0;
-
-	vector<vector<FeatureType> > feats;
-	// loop over all training images
-
-	for ( LabeledSet::Permutation::const_iterator i = perm.begin();
-			 i != perm.end(); i++,imgcounter++ )
-	{
-		const string fn = i->second->img();
-		Globals::setCurrentImgFN ( fn );
-		cout << fn << endl;
-		NICE::ColorImage cimg(fn);
-		NICE::Matrix mask;
-		RegionGraph rg;
-		rsm->getGraphRepresentation(cimg, mask, rg);
-		
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::train starts" << endl;
+#endif
+
+  Examples examples;
+  examples.filename = "training";
+
+  const LabeledSet train = * ( *md ) ["train"];
+
+  set<int> forbidden_classes;
+
+  std::string forbidden_classes_s = conf->gS ( "analysis", "donttrain", "" );
+  if ( forbidden_classes_s == "" )
+  {
+    forbidden_classes_s = conf->gS ( "analysis", "forbidden_classes", "" );
+  }
+
+  cn.getSelection ( forbidden_classes_s, forbidden_classes );
+
+  if ( gcopt != NULL )
+    gcopt->setClassNo ( cn.numClasses() );
+
+  LabeledSet::Permutation perm;
+
+  train.getPermutation ( perm );
+
+  learnHighLevel ( perm );
+
+  //FIXME:Moosmann
+
+  int imgcounter = 0;
+
+  vector<vector<FeatureType> > feats;
+  // loop over all training images
+
+  for ( LabeledSet::Permutation::const_iterator i = perm.begin();
+        i != perm.end(); i++, imgcounter++ )
+  {
+    const string fn = i->second->img();
+    Globals::setCurrentImgFN ( fn );
+    cout << fn << endl;
+    NICE::ColorImage cimg ( fn );
+    NICE::Matrix mask;
+    RegionGraph rg;
+    rsm->getGraphRepresentation ( cimg, mask, rg );
+
 #ifdef DEMO
 #ifdef DEMO
-		rsm->visualizeGraphRepresentation(cimg, mask);
+    rsm->visualizeGraphRepresentation ( cimg, mask );
 #endif
 #endif
 
 
-		// get label
-		const LocalizationResult *locResult = i->second->localization();
-		NICE::Image pixelLabels (cimg.width(), cimg.height());
-		pixelLabels.set(0);
-		locResult->calcLabeledImage ( pixelLabels, ( *classNames ).getBackgroundClass() );
-		getRegionLabel(mask, rg, pixelLabels);
-		
-		getFeats(cimg, mask, rg, feats);
-		
+    // get label
+    const LocalizationResult *locResult = i->second->localization();
+    NICE::Image pixelLabels ( cimg.width(), cimg.height() );
+    pixelLabels.set ( 0 );
+    locResult->calcLabeledImage ( pixelLabels, ( *classNames ).getBackgroundClass() );
+    getRegionLabel ( mask, rg, pixelLabels );
+
+    getFeats ( cimg, mask, rg, feats );
+
 //#pragma omp critical
 //#pragma omp critical
-		for(int i = 0; i < rg.size(); i++)
-		{
-			int classno = rg[i]->getLabel();
-			Example example;
-			example.position = imgcounter;
-			examples.push_back (pair<int, Example> ( classno, example ));
-		}
+    for ( int i = 0; i < rg.size(); i++ )
+    {
+      int classno = rg[i]->getLabel();
+      Example example;
+      example.position = imgcounter;
+      examples.push_back ( pair<int, Example> ( classno, example ) );
+    }
 //#pragma omp critical
 //#pragma omp critical
-		if ( gcopt !=NULL )
-			gcopt->trainImage ( rg );
-
-	}
-cout << "train classifier starts" << endl;
-	trainClassifier(feats, examples);
-cout << "train classifier finished" << endl;
-
-	if ( gcopt != NULL )
-		gcopt->finishPP ( cn );
-
-	// clean up
-	/*for(int i = 0; i < (int) examples.size(); i++)
-	{
-		examples[i].second.clean();
-	}*/
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::train finished" << endl;
-	#endif
+    if ( gcopt != NULL )
+      gcopt->trainImage ( rg );
+
+  }
+  cout << "train classifier starts" << endl;
+  trainClassifier ( feats, examples );
+  cout << "train classifier finished" << endl;
+
+  if ( gcopt != NULL )
+    gcopt->finishPP ( cn );
+
+  // clean up
+  /*for(int i = 0; i < (int) examples.size(); i++)
+  {
+   examples[i].second.clean();
+  }*/
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::train finished" << endl;
+#endif
 }
 }
 
 
-void SemSegRegionBased::getRegionLabel(NICE::Matrix &mask, RegionGraph &rg, NICE::Image &pixelLabels)
-{	
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::getRegionLabel starts" << endl;
-	#endif
-	vector<vector<int> > hists;
-	int regionsize = rg.size();
-	int xsize = pixelLabels.width();
-	int ysize = pixelLabels.height();
-
-	for ( int i = 0; i < regionsize; i++ )
-	{
-		vector<int> hist ( cn.numClasses(), 0 );
-		hists.push_back ( hist );
-	}
-
-	for ( int x = 0; x < xsize; x++ )
-	{
-		for ( int y = 0; y < ysize; y++ )
-		{
-			int numb = mask(x,y);
-			hists[numb][pixelLabels.getPixel(x,y)]++;
-		}
-	}
-
-	for ( int i = 0; i < regionsize; i++ )
-	{
-		int maxval = -numeric_limits<int>::max();
-		int smaxval = -numeric_limits<int>::max();
-		int maxpos = -1;
-		int secondpos = -1;
-		for ( int k = 0; k < ( int ) hists[i].size(); k++ )
-		{
-			if ( maxval < hists[i][k] )
-			{
-				secondpos = maxpos;
-				smaxval = maxval;
-				maxval = hists[i][k];
-				maxpos = k;
-			}
-			else
-			{
-				if ( smaxval < hists[i][k] )
-				{
-					smaxval = hists[i][k];
-					secondpos = k;
-				}
-			}
-		}
-
-		// FIXME: das für alle verbotenen Klassen einbauen
-		//if ( forbidden_classes.find ( classno ) != forbidden_classes.end() )
-
-		if ( cn.text ( maxpos ) == "various" && smaxval > 0)
-			rg[i]->setLabel(secondpos);
-		else
-			rg[i]->setLabel(maxpos);
-	}
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::getRegionLabel finished" << endl;
-	#endif
+void SemSegRegionBased::getRegionLabel ( NICE::Matrix &mask, RegionGraph &rg, NICE::Image &pixelLabels )
+{
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::getRegionLabel starts" << endl;
+#endif
+  vector<vector<int> > hists;
+  int regionsize = rg.size();
+  int xsize = pixelLabels.width();
+  int ysize = pixelLabels.height();
+
+  for ( int i = 0; i < regionsize; i++ )
+  {
+    vector<int> hist ( cn.numClasses(), 0 );
+    hists.push_back ( hist );
+  }
+
+  for ( int x = 0; x < xsize; x++ )
+  {
+    for ( int y = 0; y < ysize; y++ )
+    {
+      int numb = mask ( x, y );
+      hists[numb][pixelLabels.getPixel ( x,y ) ]++;
+    }
+  }
+
+  for ( int i = 0; i < regionsize; i++ )
+  {
+    int maxval = -numeric_limits<int>::max();
+    int smaxval = -numeric_limits<int>::max();
+    int maxpos = -1;
+    int secondpos = -1;
+    for ( int k = 0; k < ( int ) hists[i].size(); k++ )
+    {
+      if ( maxval < hists[i][k] )
+      {
+        secondpos = maxpos;
+        smaxval = maxval;
+        maxval = hists[i][k];
+        maxpos = k;
+      }
+      else
+      {
+        if ( smaxval < hists[i][k] )
+        {
+          smaxval = hists[i][k];
+          secondpos = k;
+        }
+      }
+    }
+
+    // FIXME: das für alle verbotenen Klassen einbauen
+    //if ( forbidden_classes.find ( classno ) != forbidden_classes.end() )
+
+    if ( cn.text ( maxpos ) == "various" && smaxval > 0 )
+      rg[i]->setLabel ( secondpos );
+    else
+      rg[i]->setLabel ( maxpos );
+  }
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::getRegionLabel finished" << endl;
+#endif
 }
 }
 
 
-void SemSegRegionBased::getExample(const vector<vector<FeatureType> > &feats, Examples &examples)
+void SemSegRegionBased::getExample ( const vector<vector<FeatureType> > &feats, Examples &examples )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::getExample starts" << endl;
-	#endif
-	
-	for(int j = 0; j < (int)feats.size(); j++)
-	{
-		int counter = 0;
-		for(int i = 0; i < (int)feats[0].size(); i++, counter++)
-		{
-			if(examples[counter].second.vec == NULL)
-			{
-				NICE::Vector *vec = new NICE::Vector(feats[j][i].getVec());
-				examples[counter].second.vec = vec;
-			}
-			else
-			{
-				examples[counter].second.vec->append(feats[j][i].getVec());
-			}
-		}
-	}
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::getExample finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::getExample starts" << endl;
+#endif
+
+  for ( int j = 0; j < ( int ) feats.size(); j++ )
+  {
+    int counter = 0;
+    for ( int i = 0; i < ( int ) feats[0].size(); i++, counter++ )
+    {
+      if ( examples[counter].second.vec == NULL )
+      {
+        NICE::Vector *vec = new NICE::Vector ( feats[j][i].getVec() );
+        examples[counter].second.vec = vec;
+      }
+      else
+      {
+        examples[counter].second.vec->append ( feats[j][i].getVec() );
+      }
+    }
+  }
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::getExample finished" << endl;
+#endif
 }
 }
 
 
-void SemSegRegionBased::getFeaturePool( const vector<vector<FeatureType> > &feats, FeaturePool &fp)
+void SemSegRegionBased::getFeaturePool ( const vector<vector<FeatureType> > &feats, FeaturePool &fp )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::getFeaturePool starts" << endl;
-	#endif
-	
-	int olddim = 0;
-	int fulldim = 0;
-	
-	for(int j = 0; j < (int)feats.size(); j++)
-	{
-		fulldim += feats[j][0].getDim();
-	}
-	
-	for(int j = 0; j < (int)feats.size(); j++)
-	{
-		int dimension = feats[j][0].getDim();
-		for ( int i = olddim ; i < olddim+dimension ; i++ )
-		{
-			VectorFeature *f = new VectorFeature ( fulldim );
-			f->feature_index = i;
-			fp.addFeature(f, 1.0 / dimension);
-		}
-		olddim += dimension;
-	}
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::getFeaturePool finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::getFeaturePool starts" << endl;
+#endif
+
+  int olddim = 0;
+  int fulldim = 0;
+
+  for ( int j = 0; j < ( int ) feats.size(); j++ )
+  {
+    fulldim += feats[j][0].getDim();
+  }
+
+  for ( int j = 0; j < ( int ) feats.size(); j++ )
+  {
+    int dimension = feats[j][0].getDim();
+    for ( int i = olddim ; i < olddim + dimension ; i++ )
+    {
+      VectorFeature *f = new VectorFeature ( fulldim );
+      f->feature_index = i;
+      fp.addFeature ( f, 1.0 / dimension );
+    }
+    olddim += dimension;
+  }
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::getFeaturePool finished" << endl;
+#endif
 }
 }
 
 
-void SemSegRegionBased::trainClassifier(vector<vector<FeatureType> > &feats, Examples & examples)
+void SemSegRegionBased::trainClassifier ( vector<vector<FeatureType> > &feats, Examples & examples )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::trainClassifier starts" << endl;
-	#endif
-	assert (feats.size() > 0);
-	assert (feats[0].size() > 0);
-
-	// delete nonrelevant features
-	for(int i = (int)examples.size()-1; i >= 0; i--)
-	{
-		if(cn.text ( examples[i].first ) == "various")
-		{
-			examples.erase(examples.begin()+i);
-			for(int k = 0; k < (int)feats.size(); k++)
-			{
-				feats[k].erase(feats[k].begin()+i);
-			}
-		}
-	}
-	
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::trainClassifier starts" << endl;
+#endif
+  assert ( feats.size() > 0 );
+  assert ( feats[0].size() > 0 );
+
+  // delete nonrelevant features
+  for ( int i = ( int ) examples.size() - 1; i >= 0; i-- )
+  {
+    if ( cn.text ( examples[i].first ) == "various" )
+    {
+      examples.erase ( examples.begin() + i );
+      for ( int k = 0; k < ( int ) feats.size(); k++ )
+      {
+        feats[k].erase ( feats[k].begin() + i );
+      }
+    }
+  }
+
 #ifdef WRITEFEATS
 #ifdef WRITEFEATS
-	// mermale in datei schreiben
-	ofstream fout( "trainfeats", ios_base::out );
-	//vector<int> ccounter(cn.getMaxClassno(),0);
-	//int maxv = 100;
-	for(int i = 0; i < (int)examples.size(); i++)
-	{
-		//if(ccounter[examples[i].first]++ < maxv)
-		//{
-			fout << examples[i].first << " ";
-			for(int j = 0; j < (int)feats.size(); j++)
-			{
-				for(int k = 0; k < feats[j][i].getDim(); k++)
-				{
-					fout << feats[j][i].get(k) << " ";
-				}
-			}
-			fout << endl;
-		//}
-	}
+  // mermale in datei schreiben
+  ofstream fout ( "trainfeats", ios_base::out );
+  //vector<int> ccounter(cn.getMaxClassno(),0);
+  //int maxv = 100;
+  for ( int i = 0; i < ( int ) examples.size(); i++ )
+  {
+    //if(ccounter[examples[i].first]++ < maxv)
+    //{
+    fout << examples[i].first << " ";
+    for ( int j = 0; j < ( int ) feats.size(); j++ )
+    {
+      for ( int k = 0; k < feats[j][i].getDim(); k++ )
+      {
+        fout << feats[j][i].get ( k ) << " ";
+      }
+    }
+    fout << endl;
+    //}
+  }
 #endif
 #endif
-	
-	if(fpc != NULL)
-	{
-		FeaturePool fp;
-		getExample(feats, examples);
-		getFeaturePool(feats, fp);
-
-		fpc->train ( fp, examples );
-
-		fp.destroy();
-
-		if(save_cache)
-		{
-			fpc->save(classifiercache);
-		}
-
-//#pragma omp parallel for		
-		for(int i = 0; i < (int)examples.size(); i++)
-		{
-			if(examples[i].second.vec != NULL)
-			{
-				delete examples[i].second.vec;
-				examples[i].second.vec = NULL;
-			}
-		}
-
-	}
-	else if(vclassifier != NULL)
-	{
-		LabeledSetVector lsv;
-		
+
+  if ( fpc != NULL )
+  {
+    FeaturePool fp;
+    getExample ( feats, examples );
+    getFeaturePool ( feats, fp );
+
+    fpc->train ( fp, examples );
+
+    fp.destroy();
+
+    if ( save_cache )
+    {
+      fpc->save ( classifiercache );
+    }
+
 //#pragma omp parallel for
 //#pragma omp parallel for
-		for(int i = 0; i < (int)feats[0].size(); i++)
-		{
-			NICE::Vector *v = new NICE::Vector(feats[0][i].getVec());
-			for(int j = 1; j < (int)feats.size(); j++)
-			{
-				v->append(feats[j][i].getVec());
-			}
+    for ( int i = 0; i < ( int ) examples.size(); i++ )
+    {
+      if ( examples[i].second.vec != NULL )
+      {
+        delete examples[i].second.vec;
+        examples[i].second.vec = NULL;
+      }
+    }
+
+  }
+  else if ( vclassifier != NULL )
+  {
+    LabeledSetVector lsv;
+
+//#pragma omp parallel for
+    for ( int i = 0; i < ( int ) feats[0].size(); i++ )
+    {
+      NICE::Vector *v = new NICE::Vector ( feats[0][i].getVec() );
+      for ( int j = 1; j < ( int ) feats.size(); j++ )
+      {
+        v->append ( feats[j][i].getVec() );
+      }
 //#pragma omp critical
 //#pragma omp critical
-			lsv.add_reference (examples[i].first, v );
-		}
-
-		vclassifier->teach(lsv);
-		vclassifier->finishTeaching();
-		lsv.clear();
-		if(save_cache)
-		{
-			vclassifier->save(classifiercache);
-		}
-	}
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::trainClassifier finished" << endl;
-	#endif
+      lsv.add_reference ( examples[i].first, v );
+    }
+
+    vclassifier->teach ( lsv );
+    vclassifier->finishTeaching();
+    lsv.clear();
+    if ( save_cache )
+    {
+      vclassifier->save ( classifiercache );
+    }
+  }
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::trainClassifier finished" << endl;
+#endif
 }
 }
 
 
-void SemSegRegionBased::classify(const vector<vector<FeatureType> > &feats, Examples &examples, vector<vector<double> > &probs)
+void SemSegRegionBased::classify ( const vector<vector<FeatureType> > &feats, Examples &examples, vector<vector<double> > &probs )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::classify starts" << endl;
-	#endif
-	for(int i = 0; i < (int)feats[0].size(); i++)
-	{
-		Example example;
-		examples.push_back (pair<int, Example> ( -1, example ) );
-	}
-	
-	getExample(feats, examples);
-	
-	int nbcl = classNames->getMaxClassno() + 1;
-	
-	for(int i = 0; i < (int)examples.size(); i++)
-	{
-		vector<double> p;
-		ClassificationResult r;
-			
-		if(fpc != NULL)
-		{
-			r = fpc->classify ( examples[i].second );
-		}
-		else if(vclassifier != NULL)
-		{
- 			r = vclassifier->classify(*(examples[i].second.vec));
-		}
-	
-		for ( int j = 0 ; j < nbcl; j++ )
-		{
-			p.push_back(r.scores[j]);
-		}
-
-		probs.push_back(p);
-	}
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::classify finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::classify starts" << endl;
+#endif
+  for ( int i = 0; i < ( int ) feats[0].size(); i++ )
+  {
+    Example example;
+    examples.push_back ( pair<int, Example> ( -1, example ) );
+  }
+
+  getExample ( feats, examples );
+
+  int nbcl = classNames->getMaxClassno() + 1;
+
+  for ( int i = 0; i < ( int ) examples.size(); i++ )
+  {
+    vector<double> p;
+    ClassificationResult r;
+
+    if ( fpc != NULL )
+    {
+      r = fpc->classify ( examples[i].second );
+    }
+    else if ( vclassifier != NULL )
+    {
+      r = vclassifier->classify ( * ( examples[i].second.vec ) );
+    }
+
+    for ( int j = 0 ; j < nbcl; j++ )
+    {
+      p.push_back ( r.scores[j] );
+    }
+
+    probs.push_back ( p );
+  }
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::classify finished" << endl;
+#endif
 }
 }
 
 
-void SemSegRegionBased::semanticseg(CachedExample *ce, NICE::Image & segresult,	NICE::MultiChannelImageT<double> & probabilities)
+void SemSegRegionBased::semanticseg ( CachedExample *ce, NICE::Image & segresult, NICE::MultiChannelImageT<double> & probabilities )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::semanticseg starts" << endl;
-	#endif
-	int xsize, ysize;
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::semanticseg starts" << endl;
+#endif
+  int xsize, ysize;
 
 
-	ce->getImageSize ( xsize, ysize );
+  ce->getImageSize ( xsize, ysize );
 
 
-	probabilities.reInit ( xsize, ysize, classNames->getMaxClassno() +1, true/*allocMem*/ );
-	std::string currentFile = Globals::getCurrentImgFN();
-	NICE::ColorImage cimg(currentFile);
+  probabilities.reInit ( xsize, ysize, classNames->getMaxClassno() + 1);
+  std::string currentFile = Globals::getCurrentImgFN();
+  NICE::ColorImage cimg ( currentFile );
 
 
-	NICE::Matrix mask;
-	RegionGraph rg;
-	rsm->getGraphRepresentation(cimg, mask, rg);
+  NICE::Matrix mask;
+  RegionGraph rg;
+  rsm->getGraphRepresentation ( cimg, mask, rg );
 #ifdef DEMO
 #ifdef DEMO
-	rsm->visualizeGraphRepresentation(cimg, mask);
+  rsm->visualizeGraphRepresentation ( cimg, mask );
 #endif
 #endif
-	vector<vector<FeatureType> > feats;
-
-	getFeats(cimg, mask, rg, feats);
-
-#ifdef WRITEFEATS	
-	getRegionLabel(mask, rg, segresult);
-	ofstream fout( "testfeats", ios_base::app );
-
-	for(int i = 0; i < (int)rg.size(); i++)
-	{
-		fout << rg[i]->getLabel() << " ";
-		for(int j = 0; j < (int)feats.size(); j++)
-		{
-			for(int k = 0; k < feats[j][i].getDim(); k++)
-			{
-				fout << feats[j][i].get(k) << " ";
-			}
-		}
-		fout << endl;
-	}
+  vector<vector<FeatureType> > feats;
+
+  getFeats ( cimg, mask, rg, feats );
+
+#ifdef WRITEFEATS
+  getRegionLabel ( mask, rg, segresult );
+  ofstream fout ( "testfeats", ios_base::app );
+
+  for ( int i = 0; i < ( int ) rg.size(); i++ )
+  {
+    fout << rg[i]->getLabel() << " ";
+    for ( int j = 0; j < ( int ) feats.size(); j++ )
+    {
+      for ( int k = 0; k < feats[j][i].getDim(); k++ )
+      {
+        fout << feats[j][i].get ( k ) << " ";
+      }
+    }
+    fout << endl;
+  }
 #endif
 #endif
-	
-	segresult = NICE::Image(xsize, ysize);
-	segresult.set(0);
-	
-	Examples examples; 
-	
-	vector<vector<double> > probs;
 
 
-	classify(feats, examples, probs);
+  segresult = NICE::Image ( xsize, ysize );
+  segresult.set ( 0 );
+
+  Examples examples;
+
+  vector<vector<double> > probs;
 
 
-	labelRegions(rg, probs);
+  classify ( feats, examples, probs );
 
 
-	if ( gcopt != NULL )
-		gcopt->optimizeImage ( rg, probs );
+  labelRegions ( rg, probs );
 
 
-	labelImage(segresult, mask, rg);
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::semanticseg finished" << endl;
-	#endif
+  if ( gcopt != NULL )
+    gcopt->optimizeImage ( rg, probs );
+
+  labelImage ( segresult, mask, rg );
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::semanticseg finished" << endl;
+#endif
 }
 }
 
 
-void SemSegRegionBased::labelRegions(RegionGraph &rg, vector<vector<double> > &probs)
+void SemSegRegionBased::labelRegions ( RegionGraph &rg, vector<vector<double> > &probs )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::labelRegions starts" << endl;
-	#endif
-	for(int i = 0; i < rg.size(); i++)
-	{
-		int bestclass = -1;
-		double bestval = -numeric_limits<int>::max();
-		for(int j = 0; j < (int)probs[i].size(); j++)
-		{
-			if(bestval < probs[i][j])
-			{
-				bestval = probs[i][j];
-				bestclass = j;
-			}
-		}
-		rg[i]->setLabel(bestclass);
-	}
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::labelRegions finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::labelRegions starts" << endl;
+#endif
+  for ( int i = 0; i < rg.size(); i++ )
+  {
+    int bestclass = -1;
+    double bestval = -numeric_limits<int>::max();
+    for ( int j = 0; j < ( int ) probs[i].size(); j++ )
+    {
+      if ( bestval < probs[i][j] )
+      {
+        bestval = probs[i][j];
+        bestclass = j;
+      }
+    }
+    rg[i]->setLabel ( bestclass );
+  }
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::labelRegions finished" << endl;
+#endif
 }
 }
 
 
-void SemSegRegionBased::labelImage(NICE::Image &segresult, NICE::Matrix &mask,RegionGraph &rg)
+void SemSegRegionBased::labelImage ( NICE::Image &segresult, NICE::Matrix &mask, RegionGraph &rg )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::labelImage starts" << endl;
-	#endif
-	for(int y = 0; y < segresult.height(); y++)
-	{
-		for(int x = 0; x < segresult.width(); x++)
-		{
-			int r = (int)mask(x,y);
-			segresult.setPixel(x,y,rg[r]->getLabel());
-		}
-	}
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::labelImage finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::labelImage starts" << endl;
+#endif
+  for ( int y = 0; y < segresult.height(); y++ )
+  {
+    for ( int x = 0; x < segresult.width(); x++ )
+    {
+      int r = ( int ) mask ( x, y );
+      segresult.setPixel ( x, y, rg[r]->getLabel() );
+    }
+  }
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::labelImage finished" << endl;
+#endif
 }
 }
 
 
-void SemSegRegionBased::getFeats(const NICE::ColorImage &cimg, const NICE::Matrix &mask, const RegionGraph &rg, vector<vector< FeatureType> > &feats) const
-{	
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::getFeats starts" << endl;
-	#endif
-	string fn = Globals::getCurrentImgFN();	
-	NICE::Image img(fn);
-	int featnb = 0;
-
-	const int rgcount = rg.size();
-	if(rfc != NULL)
-	{
-		if((int)feats.size() <= featnb)
-		{
-			vector<FeatureType> ftv;
-			feats.push_back(ftv);
-		}
-
-		VVector features;
-		rfc->extractRGB ( cimg, rg, mask, features );
-		
-		assert((int)features.size() == rgcount);
-		
-		for(int j = 0; j < (int)features.size(); j++)
-		{
-			feats[featnb].push_back(FeatureType(features[j]));
-		}
+void SemSegRegionBased::getFeats ( const NICE::ColorImage &cimg, const NICE::Matrix &mask, const RegionGraph &rg, vector<vector< FeatureType> > &feats ) const
+{
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::getFeats starts" << endl;
+#endif
+  string fn = Globals::getCurrentImgFN();
+  NICE::Image img ( fn );
+  int featnb = 0;
+
+  const int rgcount = rg.size();
+  if ( rfc != NULL )
+  {
+    if ( ( int ) feats.size() <= featnb )
+    {
+      vector<FeatureType> ftv;
+      feats.push_back ( ftv );
+    }
+
+    VVector features;
+    rfc->extractRGB ( cimg, rg, mask, features );
+
+    assert ( ( int ) features.size() == rgcount );
+
+    for ( int j = 0; j < ( int ) features.size(); j++ )
+    {
+      feats[featnb].push_back ( FeatureType ( features[j] ) );
+    }
 #ifdef DEMO
 #ifdef DEMO
-		LFColorWeijer lfc(conf);
-		lfc.visualizeFeatures (cimg);
+    LFColorWeijer lfc ( conf );
+    lfc.visualizeFeatures ( cimg );
+#endif
+
+    featnb++;
+  }
+
+  if ( rfbov != NULL )
+  {
+    if ( ( int ) feats.size() <= featnb )
+    {
+      vector<FeatureType> ftv;
+      feats.push_back ( ftv );
+    }
+
+    VVector features;
+    rfbov->extractRGB ( cimg, rg, mask, features );
+
+    assert ( ( int ) features.size() == rgcount );
+
+    for ( int j = 0; j < ( int ) features.size(); j++ )
+    {
+      feats[featnb].push_back ( FeatureType ( features[j] ) );
+    }
+
+    featnb++;
+  }
+
+  if ( rfhog != NULL )
+  {
+    if ( ( int ) feats.size() <= featnb )
+    {
+      vector<FeatureType> ftv;
+      feats.push_back ( ftv );
+    }
+
+    VVector features;
+
+    rfhog->extractRGB ( cimg, rg, mask, features );
+
+    assert ( ( int ) features.size() == rgcount );
+
+    for ( int j = 0; j < ( int ) features.size(); j++ )
+    {
+      feats[featnb].push_back ( FeatureType ( features[j] ) );
+    }
+
+    featnb++;
+  }
+
+  if ( rfstruct != NULL )
+  {
+    if ( ( int ) feats.size() <= featnb )
+    {
+      vector<FeatureType> ftv;
+      feats.push_back ( ftv );
+    }
+
+    VVector features;
+    rfstruct->extractRGB ( cimg, rg, mask, features );
+
+    for ( int j = 0; j < ( int ) features.size(); j++ )
+    {
+      feats[featnb].push_back ( FeatureType ( features[j] ) );
+    }
+
+    featnb++;
+  }
+
+  if ( rfbovcrdf != NULL )
+  {
+    if ( ( int ) feats.size() <= featnb )
+    {
+      vector<FeatureType> ftv;
+      feats.push_back ( ftv );
+    }
+
+    VVector features;
+    rfbovcrdf->extractRGB ( cimg, rg, mask, features );
+
+    assert ( ( int ) features.size() == rgcount );
+
+    for ( int j = 0; j < ( int ) features.size(); j++ )
+    {
+      feats[featnb].push_back ( FeatureType ( features[j] ) );
+    }
+
+    featnb++;
+  }
+
+  if ( rfCsurka != NULL )
+  {
+    if ( ( int ) feats.size() <= featnb )
+    {
+      vector<FeatureType> ftv;
+      feats.push_back ( ftv );
+    }
+
+    VVector features;
+
+    rfCsurka->extractRGB ( cimg, rg, mask, features );
+
+    assert ( ( int ) features.size() == rgcount );
+
+    for ( int j = 0; j < ( int ) features.size(); j++ )
+    {
+      feats[featnb].push_back ( FeatureType ( features[j] ) );
+    }
+
+    featnb++;
+
+  }
+
+  /* Dummy for new features:
+  if(siftFeats != NULL)
+  {
+   if((int)feats.size() <= featnb)
+   {
+    vector<FeatureType> ftv;
+    feats.push_back(ftv);
+   }
+
+   featnb++;
+  }
+  */
+
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::getFeats finished" << endl;
 #endif
 #endif
-		
-		featnb++;
-	}
-
-	if(rfbov != NULL)
-	{
-		if((int)feats.size() <= featnb)
-		{
-			vector<FeatureType> ftv;
-			feats.push_back(ftv);
-		}
-
-		VVector features;
-		rfbov->extractRGB ( cimg, rg, mask, features );
-		
-		assert((int)features.size() == rgcount);
-		
-		for(int j = 0; j < (int)features.size(); j++)
-		{
-			feats[featnb].push_back(FeatureType(features[j]));
-		}
-		
-		featnb++;
-	}
-
-	if(rfhog != NULL)
-	{
-		if((int)feats.size() <= featnb)
-		{
-			vector<FeatureType> ftv;
-			feats.push_back(ftv);
-		}
-
-		VVector features;
-
-		rfhog->extractRGB ( cimg, rg, mask, features );
-
-		assert((int)features.size() == rgcount);
-
-		for(int j = 0; j < (int)features.size(); j++)
-		{
-			feats[featnb].push_back(FeatureType(features[j]));
-		}
-
-		featnb++;
-	}
-
-	if(rfstruct != NULL)
-	{
-		if((int)feats.size() <= featnb)
-		{
-			vector<FeatureType> ftv;
-			feats.push_back(ftv);
-		}
-		
-		VVector features;
-		rfstruct->extractRGB ( cimg, rg, mask, features );
-		
-		for(int j = 0; j < (int)features.size(); j++)
-		{
-			feats[featnb].push_back(FeatureType(features[j]));
-		}
-		
-		featnb++;
-	}
-
-	if(rfbovcrdf != NULL)
-	{
-		if((int)feats.size() <= featnb)
-		{
-			vector<FeatureType> ftv;
-			feats.push_back(ftv);
-		}
-
-		VVector features;
-		rfbovcrdf->extractRGB ( cimg, rg, mask, features );
-
-		assert((int)features.size() == rgcount);
-		
-		for(int j = 0; j < (int)features.size(); j++)
-		{
-			feats[featnb].push_back(FeatureType(features[j]));
-		}
-		
-		featnb++;
-	}
-
-	if(rfCsurka != NULL)
-	{
-		if((int)feats.size() <= featnb)
-		{
-			vector<FeatureType> ftv;
-			feats.push_back(ftv);
-		}
-
-		VVector features;
-
-		rfCsurka->extractRGB ( cimg, rg, mask, features );
-
-		assert((int)features.size() == rgcount);
-
-		for(int j = 0; j < (int)features.size(); j++)
-		{
-			feats[featnb].push_back(FeatureType(features[j]));
-		}
-
-		featnb++;
-
-	}
-	
-	/* Dummy for new features:
-	if(siftFeats != NULL)
-	{
-		if((int)feats.size() <= featnb)
-		{
-			vector<FeatureType> ftv;
-			feats.push_back(ftv);
-		}
-			
-		featnb++;
-	}
-	*/
-	
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::getFeats finished" << endl;
-	#endif
 }
 }
 
 
-void SemSegRegionBased::computeLF(LabeledSet::Permutation perm, VVector &feats, vector<int> &label, Examples &examples, int mode)
+void SemSegRegionBased::computeLF ( LabeledSet::Permutation perm, VVector &feats, vector<int> &label, Examples &examples, int mode )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::computeLF starts" << endl;
-	#endif
-	string sscales = conf->gS("SIFTTrain", "scales", "1+2.0+3.0");
-	int grid = conf->gI("SIFTTrain", "grid", 20);
-	double fraction = conf->gD("SIFTTrain", "fraction", 1.0);
-
-	set<int> forbidden_classes;
-
-	std::string forbidden_classes_s = conf->gS ( "analysis", "donttrain", "" );
-	if ( forbidden_classes_s == "" )
-	{
-		forbidden_classes_s = conf->gS ( "analysis", "forbidden_classes", "" );
-	}
-	cn.getSelection ( forbidden_classes_s, forbidden_classes );
-	cerr << "forbidden: " << forbidden_classes_s << endl;
-				
-	vector<double> scales;
-	string::size_type pos = 0;
-	string::size_type oldpos = 0;
-	while(pos != string::npos)
-	{
-		pos = sscales.find("+", oldpos);
-		string val;
-		if(pos == string::npos)
-			val = sscales.substr(oldpos);
-		else
-			val = sscales.substr(oldpos, pos-oldpos);
-		double d = atof(val.c_str());
-		scales.push_back(d);
-		oldpos = pos+1;
-	}
-
-	int fsize = 0;
-	
-	string save = cache+"/siftTRAIN.dat";
-	string savep = cache +"/siftPostions.dat";
-
-	if(!FileMgt::fileExists(save) || !FileMgt::fileExists(savep))
-	{
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::computeLF starts" << endl;
+#endif
+  string sscales = conf->gS ( "SIFTTrain", "scales", "1+2.0+3.0" );
+  int grid = conf->gI ( "SIFTTrain", "grid", 20 );
+  double fraction = conf->gD ( "SIFTTrain", "fraction", 1.0 );
+
+  set<int> forbidden_classes;
+
+  std::string forbidden_classes_s = conf->gS ( "analysis", "donttrain", "" );
+  if ( forbidden_classes_s == "" )
+  {
+    forbidden_classes_s = conf->gS ( "analysis", "forbidden_classes", "" );
+  }
+  cn.getSelection ( forbidden_classes_s, forbidden_classes );
+  cerr << "forbidden: " << forbidden_classes_s << endl;
+
+  vector<double> scales;
+  string::size_type pos = 0;
+  string::size_type oldpos = 0;
+  while ( pos != string::npos )
+  {
+    pos = sscales.find ( "+", oldpos );
+    string val;
+    if ( pos == string::npos )
+      val = sscales.substr ( oldpos );
+    else
+      val = sscales.substr ( oldpos, pos - oldpos );
+    double d = atof ( val.c_str() );
+    scales.push_back ( d );
+    oldpos = pos + 1;
+  }
+
+  int fsize = 0;
+
+  string save = cache + "/siftTRAIN.dat";
+  string savep = cache + "/siftPostions.dat";
+
+  if ( !FileMgt::fileExists ( save ) || !FileMgt::fileExists ( savep ) )
+  {
 //FIXME: entfernen
 //FIXME: entfernen
-//		vector<int> counter(9,0);
-		for ( LabeledSet::Permutation::const_iterator i = perm.begin();
-					i != perm.end(); i++ )
-		{
-			const string fn = i->second->img();
-			Globals::setCurrentImgFN ( fn );
-
-			NICE::Image img(fn);
-			NICE::ColorImage cimg(fn);
-			VVector features;
-			VVector positions;
-
-			int x0 = grid/2;
-			for(int y = 0; y < (int)img.height(); y+=grid)
-			{
-				for(int x = x0; x < (int)img.width(); x+=grid)
-				{
-					for(int s = 0; s < (int)scales.size(); s++)
-					{
-						double r = (double)rand()/(double)RAND_MAX;
-						if( r < fraction)
-						{
-							fsize++;
-							NICE::Vector vec(3);
-							vec[0] = x;
-							vec[1] = y;
-							vec[2] = scales[s];
-							positions.push_back(vec);
-						}
-					}
-				}
-				if(x0 == 0)
-				{
-					x0 = grid/2;
-				}
-				else
-				{
-					x0 = 0;
-				}
-			}
-
-			siftFeats->getDescriptors(cimg, positions, features);
-
-			assert(positions.size() == features.size());
-			
-			const LocalizationResult *locResult = i->second->localization();
-			NICE::Image pixelLabels (cimg.width(), cimg.height());
-			pixelLabels.set(0);
-			locResult->calcLabeledImage ( pixelLabels, ( *classNames ).getBackgroundClass() );
-
-			for(int i = 0; i < (int)features.size(); i++)
-			{
-				int classno = pixelLabels(positions[i][0],positions[i][1]);
-//				if ( cn.text ( classno ) == "various")
-//					continue;
-
-				if ( forbidden_classes.find ( classno ) != forbidden_classes.end() )
-					continue;
-
-//				counter[classno]++;
-				label.push_back(classno);
-				feats.push_back(features[i]);
-			}
-			assert(label.size() == feats.size());
-		}
-/*		cout << "samples for class: " << endl;
-		for(int i = 0; i < 9; i++)
-		{
-			cout << i << ": " << counter[i] << endl;
-		}
-*/
-		feats.save(save,1);
-		ofstream lout(savep.c_str(),ios_base::out);
-		for(uint i = 0; i < label.size(); i++)
-		{
-			lout << label[i] << " ";
-		}
-		lout.close();
-	}
-	else
-	{
-		feats.read(save,1);
-
-		ifstream lin(savep.c_str(), ios_base::in);
-		label.clear();
-		for(int i = 0; i < (int)feats.size(); i++)
-		{
-			int l;
-			lin >> l;
-			label.push_back(l);
-		}		
-	}
-	
-	if(mode == 1)
-	{
-		convertVVectorToExamples(feats,examples, label);
-	}
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::computeLF finished" << endl;
-	#endif
+//  vector<int> counter(9,0);
+    for ( LabeledSet::Permutation::const_iterator i = perm.begin();
+          i != perm.end(); i++ )
+    {
+      const string fn = i->second->img();
+      Globals::setCurrentImgFN ( fn );
+
+      NICE::Image img ( fn );
+      NICE::ColorImage cimg ( fn );
+      VVector features;
+      VVector positions;
+
+      int x0 = grid / 2;
+      for ( int y = 0; y < ( int ) img.height(); y += grid )
+      {
+        for ( int x = x0; x < ( int ) img.width(); x += grid )
+        {
+          for ( int s = 0; s < ( int ) scales.size(); s++ )
+          {
+            double r = ( double ) rand() / ( double ) RAND_MAX;
+            if ( r < fraction )
+            {
+              fsize++;
+              NICE::Vector vec ( 3 );
+              vec[0] = x;
+              vec[1] = y;
+              vec[2] = scales[s];
+              positions.push_back ( vec );
+            }
+          }
+        }
+        if ( x0 == 0 )
+        {
+          x0 = grid / 2;
+        }
+        else
+        {
+          x0 = 0;
+        }
+      }
+
+      siftFeats->getDescriptors ( cimg, positions, features );
+
+      assert ( positions.size() == features.size() );
+
+      const LocalizationResult *locResult = i->second->localization();
+      NICE::Image pixelLabels ( cimg.width(), cimg.height() );
+      pixelLabels.set ( 0 );
+      locResult->calcLabeledImage ( pixelLabels, ( *classNames ).getBackgroundClass() );
+
+      for ( int i = 0; i < ( int ) features.size(); i++ )
+      {
+        int classno = pixelLabels ( positions[i][0], positions[i][1] );
+//    if ( cn.text ( classno ) == "various")
+//     continue;
+
+        if ( forbidden_classes.find ( classno ) != forbidden_classes.end() )
+          continue;
+
+//    counter[classno]++;
+        label.push_back ( classno );
+        feats.push_back ( features[i] );
+      }
+      assert ( label.size() == feats.size() );
+    }
+    /*  cout << "samples for class: " << endl;
+      for(int i = 0; i < 9; i++)
+      {
+       cout << i << ": " << counter[i] << endl;
+      }
+    */
+    feats.save ( save, 1 );
+    ofstream lout ( savep.c_str(), ios_base::out );
+    for ( uint i = 0; i < label.size(); i++ )
+    {
+      lout << label[i] << " ";
+    }
+    lout.close();
+  }
+  else
+  {
+    feats.read ( save, 1 );
+
+    ifstream lin ( savep.c_str(), ios_base::in );
+    label.clear();
+    for ( int i = 0; i < ( int ) feats.size(); i++ )
+    {
+      int l;
+      lin >> l;
+      label.push_back ( l );
+    }
+  }
+
+  if ( mode == 1 )
+  {
+    convertVVectorToExamples ( feats, examples, label );
+  }
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::computeLF finished" << endl;
+#endif
 }
 }
 
 
-void SemSegRegionBased::learnHighLevel(LabeledSet::Permutation perm)
+void SemSegRegionBased::learnHighLevel ( LabeledSet::Permutation perm )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::learnHighLevel starts" << endl;
-	#endif
-	srand ( time (NULL) );
-	
-	if(rfbov != NULL || rfbovcrdf != NULL || rfCsurka != NULL)
-	{		
-		if(rfbov != NULL)
-		{
-			RFBoV *rfbovdyn = dynamic_cast< RFBoV * >(rfbov);
-			
-			int gaussians = conf->gI("SIFTTrain", "gaussians", 512);
-			int pcadim = conf->gI("SIFTTrain", "pcadim", 50);
-			
-			GMM *g = new GMM( conf, gaussians );
-			PCA *pca = new PCA(pcadim);
-			string pcadst = cache+"/pca.txt";
-			
-			if ( !g->loadData ( cache+"/gmmSIFT" ) || !FileMgt::fileExists( pcadst) )
-			{
-				VVector feats;
-				vector<int> label;
-			
-				Examples ex;
-				
-				computeLF(perm, feats, label, ex, 0);
-				
-				assert(feats.size() > 0);
-				initializePCA(feats, *pca, pcadim, pcadst);
-				
-				transformFeats(feats, *pca);
-				cout << "nb of feats for learning gmm: " << feats.size() << endl;
-				g->computeMixture(feats);
-				
-				if ( save_cache )
-					g->saveData ( cache+"/gmmSIFT" );			
-			}
-			else
-			{
-				pca->read ( pcadst );
-			}
-
-			rfbovdyn->setPCA(pca);
-			rfbovdyn->setGMM(g);
-		}
-		
-		if(rfbovcrdf != NULL || rfCsurka != NULL)
-		{
-			Examples examples;
-			VVector feats;
-			vector<int> label;
-
-			computeLF(perm, feats, label, examples , 1);
-
-			FeaturePool fp;
-			FeaturePool fpsparse;
-
-			int dimension = examples[0].second.vec->size();
-	
-			for ( int i = 0 ; i < dimension ; i++ )
-			{
-				VectorFeature *f = new VectorFeature ( dimension, i );
-				fp.addFeature(f, 1.0 / dimension);
-
-				SparseVectorFeature *fs = new SparseVectorFeature ( dimension, i);
-				//fs->feature_index = i;
-				
-				fpsparse.addFeature(fs, 1.0 / dimension);
-			}
-
-			if(rfbovcrdf != NULL)
-			{
-				RFBoVCodebook *rfbovdyn = dynamic_cast< RFBoVCodebook * >(rfbovcrdf);
-				
-				int maxDepth = conf->gI("BoVMoosmann", "maxdepth", 10);
-				int csize = conf->gI("BoVMoosmann", "codebooksize", 1024);
-				
-				CodebookRandomForest *crdf = new CodebookRandomForest( maxDepth, csize );
-				
-				//RF anlernen
-				FPCRandomForests *fpcrfmoos = new FPCRandomForests(conf, "MoosForest");
-
-				fpcrfmoos->train(fp, examples);
-					
-				crdf->setClusterForest(fpcrfmoos);
-			
-				for(int i = 0; i < (int)examples.size(); i++)
-				{
-					if(examples[i].second.vec != NULL)
-					{
-						delete examples[i].second.vec;
-						examples[i].second.vec = NULL;
-					}
-				}
-				rfbovdyn->setCodebook(crdf);
-			}
-
-			if(rfCsurka != NULL)
-			{
-
-				bool usegmm = conf->gB("Csurka", "usegmm", false);
-				bool usepca = conf->gB("Csurka", "usepca", false);
-			
-				PCA *pca = NULL;
-				GMM *g = NULL;
-				
-				string classifierdst = cache+"/csurka.";
-				
-				if(usepca || usegmm)
-				{
-
-					RFCsurka *_rfcsurka = dynamic_cast< RFCsurka * >(rfCsurka);
-				
-					bool create = false;
-					string gmmdst = cache+"/csurka.gmm";
-					string pcadst = cache+"/csurka.pca";
-
-					int pcadim = conf->gI("Csurka", "pcadim", 100);
-				
-					if(usepca)
-					{
-						pca = new PCA(pcadim);
-					
-						if (!FileMgt::fileExists(pcadst))
-						{
-							create = true;
-						}
-						else
-						{
-							pca->read ( pcadst );
-						}
-					}
-
-					if(usegmm)
-					{
-						int gaussians = conf->gI("Csurka", "gaussians", 1024);
-						g = new GMM( conf, gaussians );
-					
-						if ( !g->loadData ( gmmdst ) )
-						{
-							create = true;
-						}				
-					}
-
-					if(create)
-					{
-						if(usepca)
-						{
-							convertExamplesToVVector(feats,examples, label);
-							initializePCA(feats, *pca, pcadim, pcadst);
-							transformFeats(feats, *pca);
-							convertVVectorToExamples(feats,examples, label);
-						}
-						
-						if(usegmm)
-						{							
-							g->computeMixture(examples);
-							if ( save_cache )
-								g->saveData ( gmmdst );	
-						}
-					}
-
-				
-					if(usepca)
-						_rfcsurka->setPCA(pca);
-				
-					
-					if(usegmm)
-						_rfcsurka->setGMM(g);
-
-				}
-				
-				
-				string classifiertype = conf->gS("Csurka", "classifier", "SMLR");
-				FeaturePoolClassifier *fpcrfCs = NULL;
-				VecClassifier *vecClassifier = NULL;
-				
-				if(classifiertype == "SMLR")
-				{
-					fpcrfCs = new FPCSMLR(conf, "CsurkaSMLR");
-					classifierdst += "smlr";
-				}
-				else if(classifiertype == "RF")
-				{
-					fpcrfCs = new FPCRandomForests(conf, "CsurkaForest");
-					classifierdst += "rf";
-				}
-				else
-				{
-					vecClassifier = GenericClassifierSelection::selectVecClassifier(conf, classifiertype); 
-					classifierdst += "other";
-				}
-
-				RFCsurka *rfcsurka = dynamic_cast< RFCsurka * >(rfCsurka);
-
-				if(usepca)
-				{
-					assert(examples.size() > 0);
-					if((int)examples[0].second.vec->size() != pca->getTargetDim())
-					{
-						for(int i = 0; i < (int)examples.size(); ++i)
-						{
-							*examples[i].second.vec = pca->getFeatureVector ( *examples[i].second.vec, true );
-						}
-					}
-				}
-
-								
-				if ( !FileMgt::fileExists( classifierdst) )
-				{
-					if(usegmm)
-					{
-						if(classifiertype == "SMLR")
-						{
-							for(int i = 0; i < (int)examples.size(); ++i)
-							{
-								examples[i].second.svec = new SparseVector();
-								g->getProbs(*examples[i].second.vec, *examples[i].second.svec);
-								delete examples[i].second.vec;
-								examples[i].second.vec = NULL;
-							}
-						}
-						else
-						{
-							for(int i = 0; i < (int)examples.size(); ++i)
-							{
-								g->getProbs(*examples[i].second.vec, *examples[i].second.vec);
-							}
-						}
-						if(fpcrfCs != NULL)
-						{
-						  fpcrfCs->train(fpsparse, examples);
-						}
-						else
-						{
-						  LabeledSetVector lvec;
-						  convertExamplesToLSet(examples, lvec);
-						  vecClassifier->teach(lvec);
-						  convertLSetToExamples(examples, lvec);
-						  vecClassifier->finishTeaching();
-						}
-					}
-					else
-					{
-						if(fpcrfCs != NULL)
-						{
-						  fpcrfCs->train(fp, examples);
-						}
-						else
-						{
-						  LabeledSetVector lvec;
-						  convertExamplesToLSet(examples, lvec);
-						  vecClassifier->teach(lvec);
-						  convertLSetToExamples(examples, lvec);
-						  vecClassifier->finishTeaching();
-						}
-					}
-
-					if(fpcrfCs != NULL)
-					{
-						fpcrfCs->setMaxClassNo(classNames->getMaxClassno());
-						fpcrfCs->save ( classifierdst );
-					}
-					else
-					{
-						vecClassifier->setMaxClassNo(classNames->getMaxClassno());
-						vecClassifier->save(classifierdst);
-					}
-	
-				}
-				else
-				{
-					if(fpcrfCs != NULL)
-					{
-						fpcrfCs->setMaxClassNo(classNames->getMaxClassno());
-						fpcrfCs->read ( classifierdst );
-					}
-					else
-					{
-						vecClassifier->setMaxClassNo(classNames->getMaxClassno());
-						vecClassifier->read(classifierdst);
-					}
-
-					
-				}
-	
-				if(fpcrfCs != NULL)
-				{
-					rfcsurka->setClassifier(fpcrfCs);
-				}
-				else
-				{
-					rfcsurka->setClassifier(vecClassifier);
-				}
-			}
-			fp.destroy();
-			for(int i = 0; i < (int)examples.size(); i++)
-			{
-				if(examples[i].second.vec != NULL)
-				{
-					delete examples[i].second.vec;
-					examples[i].second.vec = NULL;
-				}
-			}
-		}
-	}
-	#ifdef DEBUG_PRINTS
-	cerr << "SemSegRegionBased::learnHighLevel finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::learnHighLevel starts" << endl;
+#endif
+  srand ( time ( NULL ) );
+
+  if ( rfbov != NULL || rfbovcrdf != NULL || rfCsurka != NULL )
+  {
+    if ( rfbov != NULL )
+    {
+      RFBoV *rfbovdyn = dynamic_cast< RFBoV * > ( rfbov );
+
+      int gaussians = conf->gI ( "SIFTTrain", "gaussians", 512 );
+      int pcadim = conf->gI ( "SIFTTrain", "pcadim", 50 );
+
+      GMM *g = new GMM ( conf, gaussians );
+      PCA *pca = new PCA ( pcadim );
+      string pcadst = cache + "/pca.txt";
+
+      if ( !g->loadData ( cache + "/gmmSIFT" ) || !FileMgt::fileExists ( pcadst ) )
+      {
+        VVector feats;
+        vector<int> label;
+
+        Examples ex;
+
+        computeLF ( perm, feats, label, ex, 0 );
+
+        assert ( feats.size() > 0 );
+        initializePCA ( feats, *pca, pcadim, pcadst );
+
+        transformFeats ( feats, *pca );
+        cout << "nb of feats for learning gmm: " << feats.size() << endl;
+        g->computeMixture ( feats );
+
+        if ( save_cache )
+          g->saveData ( cache + "/gmmSIFT" );
+      }
+      else
+      {
+        pca->read ( pcadst );
+      }
+
+      rfbovdyn->setPCA ( pca );
+      rfbovdyn->setGMM ( g );
+    }
+
+    if ( rfbovcrdf != NULL || rfCsurka != NULL )
+    {
+      Examples examples;
+      VVector feats;
+      vector<int> label;
+
+      computeLF ( perm, feats, label, examples , 1 );
+
+      FeaturePool fp;
+      FeaturePool fpsparse;
+
+      int dimension = examples[0].second.vec->size();
+
+      for ( int i = 0 ; i < dimension ; i++ )
+      {
+        VectorFeature *f = new VectorFeature ( dimension, i );
+        fp.addFeature ( f, 1.0 / dimension );
+
+        SparseVectorFeature *fs = new SparseVectorFeature ( dimension, i );
+        //fs->feature_index = i;
+
+        fpsparse.addFeature ( fs, 1.0 / dimension );
+      }
+
+      if ( rfbovcrdf != NULL )
+      {
+        RFBoVCodebook *rfbovdyn = dynamic_cast< RFBoVCodebook * > ( rfbovcrdf );
+
+        int maxDepth = conf->gI ( "BoVMoosmann", "maxdepth", 10 );
+        int csize = conf->gI ( "BoVMoosmann", "codebooksize", 1024 );
+
+        CodebookRandomForest *crdf = new CodebookRandomForest ( maxDepth, csize );
+
+        //RF anlernen
+        FPCRandomForests *fpcrfmoos = new FPCRandomForests ( conf, "MoosForest" );
+
+        fpcrfmoos->train ( fp, examples );
+
+        crdf->setClusterForest ( fpcrfmoos );
+
+        for ( int i = 0; i < ( int ) examples.size(); i++ )
+        {
+          if ( examples[i].second.vec != NULL )
+          {
+            delete examples[i].second.vec;
+            examples[i].second.vec = NULL;
+          }
+        }
+        rfbovdyn->setCodebook ( crdf );
+      }
+
+      if ( rfCsurka != NULL )
+      {
+
+        bool usegmm = conf->gB ( "Csurka", "usegmm", false );
+        bool usepca = conf->gB ( "Csurka", "usepca", false );
+
+        PCA *pca = NULL;
+        GMM *g = NULL;
+
+        string classifierdst = cache + "/csurka.";
+
+        if ( usepca || usegmm )
+        {
+
+          RFCsurka *_rfcsurka = dynamic_cast< RFCsurka * > ( rfCsurka );
+
+          bool create = false;
+          string gmmdst = cache + "/csurka.gmm";
+          string pcadst = cache + "/csurka.pca";
+
+          int pcadim = conf->gI ( "Csurka", "pcadim", 100 );
+
+          if ( usepca )
+          {
+            pca = new PCA ( pcadim );
+
+            if ( !FileMgt::fileExists ( pcadst ) )
+            {
+              create = true;
+            }
+            else
+            {
+              pca->read ( pcadst );
+            }
+          }
+
+          if ( usegmm )
+          {
+            int gaussians = conf->gI ( "Csurka", "gaussians", 1024 );
+            g = new GMM ( conf, gaussians );
+
+            if ( !g->loadData ( gmmdst ) )
+            {
+              create = true;
+            }
+          }
+
+          if ( create )
+          {
+            if ( usepca )
+            {
+              convertExamplesToVVector ( feats, examples, label );
+              initializePCA ( feats, *pca, pcadim, pcadst );
+              transformFeats ( feats, *pca );
+              convertVVectorToExamples ( feats, examples, label );
+            }
+
+            if ( usegmm )
+            {
+              g->computeMixture ( examples );
+              if ( save_cache )
+                g->saveData ( gmmdst );
+            }
+          }
+
+
+          if ( usepca )
+            _rfcsurka->setPCA ( pca );
+
+
+          if ( usegmm )
+            _rfcsurka->setGMM ( g );
+
+        }
+
+
+        string classifiertype = conf->gS ( "Csurka", "classifier", "SMLR" );
+        FeaturePoolClassifier *fpcrfCs = NULL;
+        VecClassifier *vecClassifier = NULL;
+
+        if ( classifiertype == "SMLR" )
+        {
+          fpcrfCs = new FPCSMLR ( conf, "CsurkaSMLR" );
+          classifierdst += "smlr";
+        }
+        else if ( classifiertype == "RF" )
+        {
+          fpcrfCs = new FPCRandomForests ( conf, "CsurkaForest" );
+          classifierdst += "rf";
+        }
+        else
+        {
+          vecClassifier = GenericClassifierSelection::selectVecClassifier ( conf, classifiertype );
+          classifierdst += "other";
+        }
+
+        RFCsurka *rfcsurka = dynamic_cast< RFCsurka * > ( rfCsurka );
+
+        if ( usepca )
+        {
+          assert ( examples.size() > 0 );
+          if ( ( int ) examples[0].second.vec->size() != pca->getTargetDim() )
+          {
+            for ( int i = 0; i < ( int ) examples.size(); ++i )
+            {
+              *examples[i].second.vec = pca->getFeatureVector ( *examples[i].second.vec, true );
+            }
+          }
+        }
+
+
+        if ( !FileMgt::fileExists ( classifierdst ) )
+        {
+          if ( usegmm )
+          {
+            if ( classifiertype == "SMLR" )
+            {
+              for ( int i = 0; i < ( int ) examples.size(); ++i )
+              {
+                examples[i].second.svec = new SparseVector();
+                g->getProbs ( *examples[i].second.vec, *examples[i].second.svec );
+                delete examples[i].second.vec;
+                examples[i].second.vec = NULL;
+              }
+            }
+            else
+            {
+              for ( int i = 0; i < ( int ) examples.size(); ++i )
+              {
+                g->getProbs ( *examples[i].second.vec, *examples[i].second.vec );
+              }
+            }
+            if ( fpcrfCs != NULL )
+            {
+              fpcrfCs->train ( fpsparse, examples );
+            }
+            else
+            {
+              LabeledSetVector lvec;
+              convertExamplesToLSet ( examples, lvec );
+              vecClassifier->teach ( lvec );
+              convertLSetToExamples ( examples, lvec );
+              vecClassifier->finishTeaching();
+            }
+          }
+          else
+          {
+            if ( fpcrfCs != NULL )
+            {
+              fpcrfCs->train ( fp, examples );
+            }
+            else
+            {
+              LabeledSetVector lvec;
+              convertExamplesToLSet ( examples, lvec );
+              vecClassifier->teach ( lvec );
+              convertLSetToExamples ( examples, lvec );
+              vecClassifier->finishTeaching();
+            }
+          }
+
+          if ( fpcrfCs != NULL )
+          {
+            fpcrfCs->setMaxClassNo ( classNames->getMaxClassno() );
+            fpcrfCs->save ( classifierdst );
+          }
+          else
+          {
+            vecClassifier->setMaxClassNo ( classNames->getMaxClassno() );
+            vecClassifier->save ( classifierdst );
+          }
+
+        }
+        else
+        {
+          if ( fpcrfCs != NULL )
+          {
+            fpcrfCs->setMaxClassNo ( classNames->getMaxClassno() );
+            fpcrfCs->read ( classifierdst );
+          }
+          else
+          {
+            vecClassifier->setMaxClassNo ( classNames->getMaxClassno() );
+            vecClassifier->read ( classifierdst );
+          }
+
+
+        }
+
+        if ( fpcrfCs != NULL )
+        {
+          rfcsurka->setClassifier ( fpcrfCs );
+        }
+        else
+        {
+          rfcsurka->setClassifier ( vecClassifier );
+        }
+      }
+      fp.destroy();
+      for ( int i = 0; i < ( int ) examples.size(); i++ )
+      {
+        if ( examples[i].second.vec != NULL )
+        {
+          delete examples[i].second.vec;
+          examples[i].second.vec = NULL;
+        }
+      }
+    }
+  }
+#ifdef DEBUG_PRINTS
+  cerr << "SemSegRegionBased::learnHighLevel finished" << endl;
+#endif
 }
 }
 
 
-void SemSegRegionBased::transformFeats(VVector &feats, PCA &pca)
+void SemSegRegionBased::transformFeats ( VVector &feats, PCA &pca )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cerr << "SemSegRegionBased::transformFeats starts"<< endl;
-	#endif
-	for(int i = 0; i < (int)feats.size(); i++)
-	{
-		feats[i] = pca.getFeatureVector ( feats[i], true );
-	}
-	#ifdef DEBUG_PRINTS
-	cerr << "SemSegRegionBased::transformFeats finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cerr << "SemSegRegionBased::transformFeats starts" << endl;
+#endif
+  for ( int i = 0; i < ( int ) feats.size(); i++ )
+  {
+    feats[i] = pca.getFeatureVector ( feats[i], true );
+  }
+#ifdef DEBUG_PRINTS
+  cerr << "SemSegRegionBased::transformFeats finished" << endl;
+#endif
 }
 }
 
 
 void SemSegRegionBased::initializePCA ( const VVector &feats, PCA &pca, int dim, string &fn )
 void SemSegRegionBased::initializePCA ( const VVector &feats, PCA &pca, int dim, string &fn )
 {
 {
-	#ifdef DEBUG_PRINTS
-	cerr << "SemSegRegionBased::initializePCA starts"<< endl;
-	#endif
-	pca = PCA(dim);
-
-	if (!FileMgt::fileExists(fn))
-	{
-		srand ( time ( NULL ) );
-
-		int featsize = (int)feats.size();
-		int maxfeatures = std::min ( dim*20, featsize );
-
-		NICE::Matrix features ( maxfeatures, (int)feats[0].size() );
-
-		for ( int i = 0; i < maxfeatures; i++ )
-		{
-			int k = rand() % featsize;
-
-			int vsize = (int)feats[k].size();
-			for(int j = 0; j < vsize; j++)
-			{
-				features(i,j) = feats[k][j];
-			}
-		}
-		pca.calculateBasis ( features, dim);
-
-		if ( save_cache )
-			pca.save ( fn );
-
-	}
-	else
-	{
-		pca.read ( fn );
-	}
-	#ifdef DEBUG_PRINTS
-	cerr << "SemSegRegionBased::initializePCA finished"<< endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cerr << "SemSegRegionBased::initializePCA starts" << endl;
+#endif
+  pca = PCA ( dim );
+
+  if ( !FileMgt::fileExists ( fn ) )
+  {
+    srand ( time ( NULL ) );
+
+    int featsize = ( int ) feats.size();
+    int maxfeatures = std::min ( dim * 20, featsize );
+
+    NICE::Matrix features ( maxfeatures, ( int ) feats[0].size() );
+
+    for ( int i = 0; i < maxfeatures; i++ )
+    {
+      int k = rand() % featsize;
+
+      int vsize = ( int ) feats[k].size();
+      for ( int j = 0; j < vsize; j++ )
+      {
+        features ( i, j ) = feats[k][j];
+      }
+    }
+    pca.calculateBasis ( features, dim );
+
+    if ( save_cache )
+      pca.save ( fn );
+
+  }
+  else
+  {
+    pca.read ( fn );
+  }
+#ifdef DEBUG_PRINTS
+  cerr << "SemSegRegionBased::initializePCA finished" << endl;
+#endif
 }
 }

+ 0 - 225
semseg/SemSegSTF.cpp

@@ -1,225 +0,0 @@
-/**
-* @file SemSegSTF.cpp
-* @brief Localization system
-* @author Erik Rodner
-* @date 02/11/2008
-
-*/
-#include <iostream>
-
-#include "SemSegSTF.h"
-#include "vislearning/baselib/Globals.h"
-#include "vislearning/baselib/Preprocess.h"
-#include "vislearning/baselib/ProgressBar.h"
-#include "core/basics/StringTools.h"
-#include "vislearning/baselib/Globals.h"
-
-#include "vislearning/cbaselib/CachedExample.h"
-#include "vislearning/cbaselib/PascalResults.h"
-
-#include "vislearning/features/fpfeatures/PixelPairFeature.h"
-#include "vislearning/features/fpfeatures/SemanticFeature.h"
-
-#include "vislearning/features/fpfeatures/FIGradients.h"
-
-#include "FIShotton.h"
-
-#include "SemSegTools.h"
-
-using namespace OBJREC;
-using namespace std;
-using namespace NICE;
-
-SemSegSTF::SemSegSTF ( const Config *conf,
-                       const MultiDataset *md )
-    : SemanticSegmentation ( conf, & ( md->getClassNames ( "train" ) ) )
-{
-  use_semantic_features = conf->gB ( "bost", "use_semantic_features", true );
-  use_pixelpair_features = conf->gB ( "bost", "use_pixelpair_features", true );
-  subsamplex = conf->gI ( "bost", "subsamplex", 5 );
-  subsampley = conf->gI ( "bost", "subsampley", 5 );
-  numClasses = md->getClassNames ( "train" ).numClasses();
-
-  read_pixel_cache = conf->gB ( "FPCPixel", "read_cache", false );
-  cachepixel = conf->gS ( "FPCPixel", "cache", "fpc.data" );
-
-  read_seg_cache = conf->gB ( "FPCSeg", "read_cache", true );
-  cacheseg = conf->gS ( "FPCSeg", "cache", "segforest.data" );
-
-  Examples examples;
-  vector<CachedExample *> imgexamples;
-
-  fpcPixel = new FPCRandomForests ( conf, "FPCPixel" );
-  fpcPixel->setMaxClassNo ( classNames->getMaxClassno() );
-  if ( !read_pixel_cache || !read_seg_cache )
-  {
-    // Generate Positioned Examples
-    SemSegTools::collectTrainingExamples ( conf, "FPCPixel", * ( ( *md ) ["train"] ), *classNames,
-                                           examples, imgexamples );
-  }
-
-  if ( ! read_pixel_cache )
-  {
-    ///////////////////////////////////
-    // Train Single Pixel Classifier
-    //////////////////////////////////
-
-    FeaturePool fp;
-    for ( vector<CachedExample *>::const_iterator k = imgexamples.begin();
-          k != imgexamples.end();
-          k++ )
-      fillCachePixel ( *k );
-
-    PixelPairFeature hf ( conf );
-    hf.explode ( fp );
-
-    fpcPixel->train ( fp, examples );
-    fpcPixel->save ( cachepixel );
-
-    fp.destroy();
-  } else {
-    fprintf ( stderr, "SemSegSTF:: Reading pixel classifier data from %s\n", cachepixel.c_str() );
-    fpcPixel->read ( cachepixel );
-  }
-
-  fpcSeg = new FPCRandomForests ( conf, "FPCSeg" );
-  fpcSeg->setMaxClassNo ( classNames->getMaxClassno() );
-  maxdepthSegmentationForest = conf->gI ( "bost", "maxdepth", 5 );
-  maxdepthSegmentationForestScores = conf->gI ( "bost", "maxdepth_scores", 9999 );
-
-  if ( ! read_seg_cache )
-  {
-    ///////////////////////////////////
-    // Train Segmentation Forest
-    //////////////////////////////////
-
-    fprintf ( stderr, "Calculating Prior Statistics\n" );
-    ProgressBar pbseg ( "Calculating Prior Statistics" );
-    pbseg.show();
-    for ( vector<CachedExample *>::const_iterator k = imgexamples.begin();
-          k != imgexamples.end();
-          k++ )
-    {
-      pbseg.update ( imgexamples.size() );
-      fillCacheSegmentation ( *k );
-    }
-    pbseg.hide();
-
-    FeaturePool fp;
-
-    if ( use_semantic_features )
-    {
-      set<int> classnos;
-      classNames->getSelection ( conf->gS ( "FPCSeg", "train_selection" )
-                                 , classnos );
-      SemanticFeature sf ( conf, &classnos );
-      sf.explode ( fp );
-    }
-
-    fprintf ( stderr, "Training Segmentation Forest\n" );
-
-    fpcSeg->train ( fp, examples );
-    fpcSeg->save ( cacheseg );
-
-    // clean up memory !!
-    for ( vector<CachedExample *>::iterator i = imgexamples.begin();
-          i != imgexamples.end();
-          i++ )
-      delete ( *i );
-
-    fp.destroy();
-
-  } else {
-    fprintf ( stderr, "SemSegSTF:: Reading region classifier data from %s\n", cacheseg.c_str() );
-    fpcSeg->read ( cacheseg );
-    fprintf ( stderr, "SemSegSTF:: successfully read\n" );
-  }
-}
-
-SemSegSTF::~SemSegSTF()
-{
-}
-
-void SemSegSTF::fillCacheSegmentation ( CachedExample *ce )
-{
-  FIShotton::buildSemanticMap ( ce,
-                                fpcPixel,
-                                subsamplex,
-                                subsampley,
-                                numClasses );
-}
-
-void SemSegSTF::fillCachePixel ( CachedExample *ce )
-{
-}
-
-void SemSegSTF::semanticseg ( CachedExample *ce,
-                              NICE::Image & segresult,
-                              NICE::MultiChannelImageT<double> & probabilities )
-{
-  int xsize;
-  int ysize;
-  ce->getImageSize ( xsize, ysize );
-
-  int numClasses = classNames->numClasses();
-
-  fillCachePixel ( ce );
-  fillCacheSegmentation ( ce );
-
-  fprintf ( stderr, "BoST classification !\n" );
-
-  Example pce ( ce, 0, 0 );
-
-  int xsize_s = xsize / subsamplex;
-  int ysize_s = ysize / subsampley;
-  ClassificationResult *results = new ClassificationResult [xsize_s*ysize_s];
-
-  /** classify each pixel of the image */
-  FullVector prior ( classNames->getMaxClassno() );
-
-  probabilities.reInit ( xsize_s, ysize_s, numClasses, true );
-  probabilities.setAll ( 0 );
-
-  long offset_s = 0;
-  for ( int ys = 0 ; ys < ysize_s ; ys ++ )
-    for ( int xs = 0 ; xs < xsize_s ; xs++, offset_s++ )
-    {
-      int x = xs * subsamplex;
-      int y = ys * subsampley;
-      pce.x = x ;
-      pce.y = y ;
-      results[offset_s] = fpcSeg->classify ( pce );
-
-      for ( int i = 0 ; i < results[offset_s].scores.size(); i++ )
-        probabilities.data[i][offset_s] = results[offset_s].scores[i];
-
-      /*
-      if ( imagePriorMethod != IMAGE_PRIOR_NONE )
-      prior.add ( results[offset_s].scores );
-      */
-    }
-
-
-  fprintf ( stderr, "BoST classification ready\n" );
-
-  /** save results */
-  segresult.resize ( xsize_s, ysize_s );
-  segresult.set ( classNames->classno ( "various" ) );
-
-  long int offset = 0;
-  for ( int y = 0 ; y < ysize_s ; y++ )
-    for ( int x = 0 ; x < xsize_s ; x++, offset++ )
-    {
-      double maxvalue = - numeric_limits<double>::max();
-      int maxindex = 0;
-      for ( int i = 0 ; i < ( int ) probabilities.numChannels; i++ )
-        if ( probabilities.data[i][offset] > maxvalue )
-        {
-          maxindex = i;
-          maxvalue = probabilities.data[i][offset];
-        }
-
-      segresult.setPixel ( x, y, maxindex );
-    }
-
-}

+ 0 - 82
semseg/SemSegSTF.h

@@ -1,82 +0,0 @@
-/**
-* @file SemSegSTF.h
-* @brief Localization system
-* @author Erik Rodner
-* @date 02/11/2008
-
-*/
-#ifndef SemSegSTFINCLUDE
-#define SemSegSTFINCLUDE
-
-#include "SemanticSegmentation.h"
-#include "vislearning/classifier/fpclassifier/randomforest/DecisionNode.h"
-#include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
-
-namespace OBJREC {
-
-/** Localization system */
-class SemSegSTF : public SemanticSegmentation
-{
-  protected:
-
-    int numClasses;
-    int maxdepthSegmentationForest;
-    int maxdepthSegmentationForestScores;
-
-    bool use_semantic_features;
-    bool use_pixelpair_features;
-
-    int subsamplex;
-    int subsampley;
-
-    bool read_seg_cache;
-    bool read_pixel_cache;
-
-    std::string cacheseg;
-
-    std::string cachepixel;
-
-    std::string resultsdatadir;
-
-    double alphaDetectionPrior;
-    double alphaImagePrior;
-
-    int imagePriorMethod;
-    int priorK;
-
-    int detectionPriorMethod;
-
-    /**
-        assign all pixels with
-        normalized entropy $E/log(n)$ above
-        this threshold to the
-        background class
-    */
-    double entropyThreshold;
-
-    int backgroundModelType;
-
-    std::map<DecisionNode *, std::pair<long, int> > index;
-    FPCRandomForests *fpcSeg;
-    FPCRandomForests *fpcPixel;
-
-    std::map<std::string, LocalizationResult *> detresults;
-
-    void fillCachePixel ( CachedExample *ce );
-    void fillCacheSegmentation ( CachedExample *ce );
-
-  public:
-    /** simple constructor */
-    SemSegSTF ( const NICE::Config *conf,
-                const MultiDataset *md );
-
-    /** simple destructor */
-    virtual ~SemSegSTF();
-
-    void semanticseg ( CachedExample *ce,
-                       NICE::Image & segresult,
-                       NICE::MultiChannelImageT<double> & probabilities );
-};
-} // namespace
-
-#endif

+ 0 - 65
semseg/postsegmentation/PSSBackgroundModel.cpp

@@ -1,65 +0,0 @@
-/** 
-* @file PSSBackgroundModel.cpp
-* @brief simple background models
-* @author Erik Rodner
-* @date 03/19/2009
-
-*/
-#include <iostream>
-
-#include "PSSBackgroundModel.h"
-
-using namespace OBJREC;
-
-using namespace std;
-
-using namespace NICE;
-
-
-
-PSSBackgroundModel::PSSBackgroundModel( int backgroundModelType, double threshold, int backgroundClass )
-{
-    this->backgroundModelType = backgroundModelType;
-    this->threshold = threshold;
-    this->backgroundClass = backgroundClass;
-}
-
-PSSBackgroundModel::~PSSBackgroundModel()
-{
-}
-
-void PSSBackgroundModel::postprocess ( NICE::Image & result, NICE::MultiChannelImageT<double> & probabilities )
-{
-    if ( backgroundModelType == BGM_FIXED_ENTROPY_THRESHOLD )
-    {
-	if ( threshold >= 1.0 ) return;
-
-	int numClasses = probabilities.numChannels;
-	double t = log(numClasses)*threshold;
-	int xsize = probabilities.xsize;
-	int ysize = probabilities.ysize;
-	int offset_s = 0;
-	for (  int ys = 0 ; ys < ysize ; ys ++ ) 
-	    for ( int xs = 0 ; xs < xsize ; xs++,offset_s++ )  
-	    {
-		double entropy = 0.0;
-		double sum = 0.0;
-		for ( int i = 0 ; i < numClasses ; i++ )
-		{
-		    double val = probabilities.data[i][offset_s];
-		    if ( val <= 0.0 ) continue;
-		    entropy -= val*log(val);
-		    sum += val;
-		}
-		entropy /= sum;
-		entropy += log(sum);
-		
-		if ( entropy > t )
-		    result.setPixel(xs,ys,backgroundClass);
-	    }
-    } else if ( backgroundModelType == BGM_ADAPTIVE_ENTROPY_THRESHOLD ) {
-	fprintf (stderr, "not yet implemented !!\n");
-	exit(-1);
-    }
-
-}

+ 0 - 50
semseg/postsegmentation/PSSBackgroundModel.h

@@ -1,50 +0,0 @@
-/**
-* @file PSSBackgroundModel.h
-* @brief simple background models
-* @author Erik Rodner
-* @date 03/19/2009
-
-*/
-#ifndef PSSBACKGROUNDMODELINCLUDE
-#define PSSBACKGROUNDMODELINCLUDE
-
-#include "PostSemSeg.h"
-
-
-namespace OBJREC
-{
-
-/** simple background models */
-class PSSBackgroundModel : public PostSemSeg
-{
-
-  protected:
-    int backgroundModelType;
-    double threshold;
-    int backgroundClass;
-
-  public:
-    enum
-    {
-      BGM_FIXED_ENTROPY_THRESHOLD = 0,
-      BGM_ADAPTIVE_ENTROPY_THRESHOLD,
-      BGM_NONE
-    };
-
-    /**
-        @param backgroundModelType select one method from the enum type of this class
-        @param threshold some methods need a threshold or parameter
-    */
-    PSSBackgroundModel ( int backgroundModelType, double threshold, int backgroundClass );
-
-    /** simple destructor */
-    virtual ~PSSBackgroundModel();
-
-    virtual void postprocess ( NICE::Image & result, NICE::MultiChannelImageT<double> & probabilities );
-
-};
-
-
-} // namespace
-
-#endif

+ 80 - 83
semseg/postsegmentation/PSSImageLevelPrior.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file PSSImageLevelPrior.cpp
 * @file PSSImageLevelPrior.cpp
 * @brief incorporate prior from image categorization method
 * @brief incorporate prior from image categorization method
 * @author Erik Rodner
 * @author Erik Rodner
@@ -20,11 +20,11 @@ using namespace NICE;
 
 
 
 
 
 
-PSSImageLevelPrior::PSSImageLevelPrior( int imagePriorMethod, int priorK, double alphaImagePrior )
+PSSImageLevelPrior::PSSImageLevelPrior ( int imagePriorMethod, int priorK, double alphaImagePrior )
 {
 {
-    this->imagePriorMethod = imagePriorMethod;
-    this->priorK = priorK;
-    this->alphaImagePrior = alphaImagePrior;
+  this->imagePriorMethod = imagePriorMethod;
+  this->priorK = priorK;
+  this->alphaImagePrior = alphaImagePrior;
 }
 }
 
 
 PSSImageLevelPrior::~PSSImageLevelPrior()
 PSSImageLevelPrior::~PSSImageLevelPrior()
@@ -33,86 +33,83 @@ PSSImageLevelPrior::~PSSImageLevelPrior()
 
 
 void PSSImageLevelPrior::setPrior ( FullVector & prior )
 void PSSImageLevelPrior::setPrior ( FullVector & prior )
 {
 {
-    this->prior = prior;
+  this->prior = prior;
 }
 }
 
 
 void PSSImageLevelPrior::postprocess ( NICE::Image & result, NICE::MultiChannelImageT<double> & probabilities )
 void PSSImageLevelPrior::postprocess ( NICE::Image & result, NICE::MultiChannelImageT<double> & probabilities )
 {
 {
-    assert ( prior.size() == (int)probabilities.numChannels );
-    int xsize = probabilities.xsize;
-    int ysize = probabilities.ysize;
-
-    if ( imagePriorMethod == IMAGE_PRIOR_BEST_K ) 
-    {
-	vector<int> indices;
-	prior.getSortedIndices ( indices );
-
-	reverse ( indices.begin(), indices.end() );
-	set<int> bestComponents;
-	vector<int>::const_iterator j = indices.begin();
-	if ( indices.size() > (size_t)priorK )
-	    advance ( j, priorK );
-	else
-	    j = indices.end();
-
-	for ( vector<int>::const_iterator jj = indices.begin();
-			    jj != j ; jj++ )
-	    bestComponents.insert ( *jj );
-	
-	int offset_s = 0;
-
-	for (  int ys = 0 ; ys < ysize ; ys ++ ) 
-	    for ( int xs = 0 ; xs < xsize ; xs++,offset_s++ )  
-	    {
-		int maxindex = 0;
-		double maxvalue = - numeric_limits<double>::max();
-		double sum = 0.0;
-		for ( int i = 0 ; i < (int)probabilities.numChannels ; i++ )
-		{
-		    if ( bestComponents.find(i) == bestComponents.end()  )
-			probabilities.data[i][offset_s] = 0.0;
-		    sum += probabilities.data[i][offset_s];
-
-		    if ( probabilities.data[i][offset_s] > maxvalue )
-		    {
-			maxindex = i;
-			maxvalue = probabilities.data[i][offset_s];
-		    }
-		}
-	    	
-		if ( sum > 1e-11 )
-		    for ( int i = 0 ; i < (int)probabilities.numChannels ; i++ )
-		    {
-			probabilities.data[i][offset_s] /= sum;
-		    }
-		
-		result.setPixel(xs,ys,maxindex);
-	    }
-    } else if ( imagePriorMethod == IMAGE_PRIOR_PSEUDOPROB ) {
-	int offset_s = 0;
-	for (  int ys = 0 ; ys < ysize ; ys ++ ) 
-	    for ( int xs = 0 ; xs < xsize ; xs++,offset_s++ )  
-	    {
-		int maxindex = 0;
-		double maxvalue = - numeric_limits<double>::max();
-		double sum = 0.0;
-
-		for ( int i = 0 ; i < (int)probabilities.numChannels ; i++ )
-		{
-		    probabilities.data[i][offset_s] *= pow ( prior[i], alphaImagePrior );
-		    sum += probabilities.data[i][offset_s];
-		    if ( probabilities.data[i][offset_s] > maxvalue )
-                    {
-                        maxindex = i;
-                        maxvalue = probabilities.data[i][offset_s];
-		    }										                    
-		}
-		if ( sum > 1e-11 )
-		    for ( int i = 0 ; i < (int)probabilities.numChannels ; i++ )
-		    {
-			probabilities.data[i][offset_s] /= sum;
-		    }
-		result.setPixel(xs,ys,maxindex);
-	    }
-    }
+  assert ( prior.size() == ( int ) probabilities.channels() );
+  int xsize = probabilities.width();
+  int ysize = probabilities.height();
+
+  if ( imagePriorMethod == IMAGE_PRIOR_BEST_K )
+  {
+    vector<int> indices;
+    prior.getSortedIndices ( indices );
+
+    reverse ( indices.begin(), indices.end() );
+    set<int> bestComponents;
+    vector<int>::const_iterator j = indices.begin();
+    if ( indices.size() > ( size_t ) priorK )
+      advance ( j, priorK );
+    else
+      j = indices.end();
+
+    for ( vector<int>::const_iterator jj = indices.begin();
+          jj != j ; jj++ )
+      bestComponents.insert ( *jj );
+
+    for ( int ys = 0 ; ys < ysize ; ys ++ )
+      for ( int xs = 0 ; xs < xsize ; xs++)
+      {
+        int maxindex = 0;
+        double maxvalue = - numeric_limits<double>::max();
+        double sum = 0.0;
+        for ( int i = 0 ; i < ( int ) probabilities.channels() ; i++ )
+        {
+          if ( bestComponents.find ( i ) == bestComponents.end() )
+            probabilities[i](xs,ys) = 0.0;
+          sum += probabilities[i](xs,ys);
+
+          if ( probabilities[i](xs,ys) > maxvalue )
+          {
+            maxindex = i;
+            maxvalue = probabilities[i](xs,ys);
+          }
+        }
+
+        if ( sum > 1e-11 )
+          for ( int i = 0 ; i < ( int ) probabilities.channels() ; i++ )
+          {
+            probabilities[i](xs,ys) /= sum;
+          }
+
+        result.setPixel ( xs, ys, maxindex );
+      }
+  } else if ( imagePriorMethod == IMAGE_PRIOR_PSEUDOPROB ) {
+    for ( int ys = 0 ; ys < ysize ; ys ++ )
+      for ( int xs = 0 ; xs < xsize ; xs++)
+      {
+        int maxindex = 0;
+        double maxvalue = - numeric_limits<double>::max();
+        double sum = 0.0;
+
+        for ( int i = 0 ; i < ( int ) probabilities.channels() ; i++ )
+        {
+          probabilities[i](xs,ys) *= pow ( prior[i], alphaImagePrior );
+          sum += probabilities[i](xs,ys);
+          if ( probabilities[i](xs,ys) > maxvalue )
+          {
+            maxindex = i;
+            maxvalue = probabilities[i](xs,ys);
+          }
+        }
+        if ( sum > 1e-11 )
+          for ( int i = 0 ; i < ( int ) probabilities.channels() ; i++ )
+          {
+            probabilities[i](xs,ys) /= sum;
+          }
+        result.setPixel ( xs, ys, maxindex );
+      }
+  }
 }
 }

+ 0 - 34
semseg/postsegmentation/PSSQueue.cpp

@@ -1,34 +0,0 @@
-/** 
-* @file PSSQueue.cpp
-* @brief application of multiple post semantic segmentation methods
-* @author Erik Rodner
-* @date 03/19/2009
-
-*/
-#ifdef NOVISUAL
-#include <objrec/nice_nonvis.h>
-#else
-#include <objrec/nice.h>
-#endif
-
-#include <iostream>
-
-#include "PSSQueue.h"
-
-using namespace OBJREC;
-
-using namespace std;
-// refactor-nice.pl: check this substitution
-// old: using namespace ice;
-using namespace NICE;
-
-
-
-PSSQueue::PSSQueue()
-{
-}
-
-PSSQueue::~PSSQueue()
-{
-}
-

+ 0 - 40
semseg/postsegmentation/PSSQueue.h

@@ -1,40 +0,0 @@
-/**
-* @file PSSQueue.h
-* @brief application of multiple post semantic segmentation methods
-* @author Erik Rodner
-* @date 03/19/2009
-
-*/
-#ifndef PSSQUEUEINCLUDE
-#define PSSQUEUEINCLUDE
-
-#ifdef NOVISUAL
-#include <objrec/nice_nonvis.h>
-#else
-#include <objrec/nice.h>
-#endif
-
-
-namespace OBJREC
-{
-
-/** application of multiple post semantic segmentation methods */
-class PSSQueue
-{
-
-  protected:
-
-  public:
-
-    /** simple constructor */
-    PSSQueue();
-
-    /** simple destructor */
-    virtual ~PSSQueue();
-
-};
-
-
-} // namespace
-
-#endif

+ 494 - 493
semseg/postsegmentation/RelativeLocationPrior.cpp

@@ -8,553 +8,554 @@ using namespace OBJREC;
 
 
 RelativeLocationPrior::RelativeLocationPrior()
 RelativeLocationPrior::RelativeLocationPrior()
 {
 {
-	conf = new Config();
-	mapsize = 200;
+  conf = new Config();
+  mapsize = 200;
 }
 }
 
 
-RelativeLocationPrior::RelativeLocationPrior(const Config *_conf):conf(_conf)
+RelativeLocationPrior::RelativeLocationPrior ( const Config *_conf ) : conf ( _conf )
 {
 {
 }
 }
 
 
-void RelativeLocationPrior::setClassNo(int _classno)
+void RelativeLocationPrior::setClassNo ( int _classno )
 {
 {
-	classno = _classno; 
-	Init();
+  classno = _classno;
+  Init();
 }
 }
 
 
 void RelativeLocationPrior::Init()
 void RelativeLocationPrior::Init()
 {
 {
-	std::string section = "PostProcessRLP";
-	mapsize = conf->gI(section, "mapsize", 200 );
-
-	featdim = classno*3;
-
-	//Priorsmaps erzeugen
-	for(int i = 0; i < classno; i++)
-	{
-		NICE::MultiChannelImageT<double> *tmp  = new NICE::MultiChannelImageT<double>(mapsize, mapsize, classno, true);
-		tmp->setAll(0.0);
-		priormaps.push_back(tmp);
-	}
+  std::string section = "PostProcessRLP";
+  mapsize = conf->gI ( section, "mapsize", 200 );
+
+  featdim = classno * 3;
+
+  //Priorsmaps erzeugen
+  for ( int i = 0; i < classno; i++ )
+  {
+    NICE::MultiChannelImageT<double> *tmp  = new NICE::MultiChannelImageT<double> ( mapsize, mapsize, classno);
+    tmp->setAll ( 0.0 );
+    priormaps.push_back ( tmp );
+  }
 }
 }
 
 
 RelativeLocationPrior::~RelativeLocationPrior()
 RelativeLocationPrior::~RelativeLocationPrior()
 {
 {
-	for(int i = 0; i < classno; i++)
-	{
-		delete priormaps[i];
-	}
+  for ( int i = 0; i < classno; i++ )
+  {
+    delete priormaps[i];
+  }
 }
 }
 
 
-void RelativeLocationPrior::trainPriorsMaps(Examples &regions, int xsize, int ysize)
-{	
-	for(int j = 0; j < (int)regions.size(); j++)
-	{
-		for(int i = 0; i < (int)regions.size(); i++)
-		{
-			if(i == j) 
-				continue;
-			
-			int x = regions[i].second.x - regions[j].second.x;
-			int y = regions[i].second.y - regions[j].second.y;
-			
-			convertCoords(x, xsize);
-			convertCoords(y, ysize);
-			
-			priormaps[regions[i].first]->set(x, y, priormaps[regions[i].first]->get(x, y, regions[j].first)+1.0/*regions[j].second.weight*/, regions[j].first);
-		}
-	}
+void RelativeLocationPrior::trainPriorsMaps ( Examples &regions, int xsize, int ysize )
+{
+  for ( int j = 0; j < ( int ) regions.size(); j++ )
+  {
+    for ( int i = 0; i < ( int ) regions.size(); i++ )
+    {
+      if ( i == j )
+        continue;
+
+      int x = regions[i].second.x - regions[j].second.x;
+      int y = regions[i].second.y - regions[j].second.y;
+
+      convertCoords ( x, xsize );
+      convertCoords ( y, ysize );
+
+      priormaps[regions[i].first]->set ( x, y, priormaps[regions[i].first]->get ( x, y, regions[j].first ) + 1.0/*regions[j].second.weight*/, regions[j].first );
+    }
+  }
 }
 }
 
 
-void RelativeLocationPrior::finishPriorsMaps(ClassNames &cn)
+void RelativeLocationPrior::finishPriorsMaps ( ClassNames &cn )
 {
 {
-	// Priormaps normalisieren
-	double alpha = 5;
-	for(int i = 0; i < classno; i++)
-	{
-		for(int j = 0; j < classno; j++)
-		{
-			double val = 0.0;
-
-			for(int x = 0; x < mapsize; x++)
-			{
-				for(int y = 0; y < mapsize; y++)
-				{
-					val = std::max(val,priormaps[i]->get(x, y, j));
-				}
-			}
-			if(val != 0.0)
-			{
-				for(int x = 0; x < mapsize; x++)
-				{
-					for(int y = 0; y < mapsize; y++)
-					{
-						double old = priormaps[i]->get(x, y, j);
-						
+  // Priormaps normalisieren
+  double alpha = 5;
+  for ( int i = 0; i < classno; i++ )
+  {
+    for ( int j = 0; j < classno; j++ )
+    {
+      double val = 0.0;
+
+      for ( int x = 0; x < mapsize; x++ )
+      {
+        for ( int y = 0; y < mapsize; y++ )
+        {
+          val = std::max ( val, priormaps[i]->get ( x, y, j ) );
+        }
+      }
+      if ( val != 0.0 )
+      {
+        for ( int x = 0; x < mapsize; x++ )
+        {
+          for ( int y = 0; y < mapsize; y++ )
+          {
+            double old = priormaps[i]->get ( x, y, j );
+
 #undef DIRICHLET
 #undef DIRICHLET
 #ifdef DIRICHLET
 #ifdef DIRICHLET
-						old = (old+alpha)/(val+classno*alpha);
+            old = ( old + alpha ) / ( val + classno * alpha );
 #else
 #else
-						old /= val;
+            old /= val;
 #endif
 #endif
-						priormaps[i]->set(x, y, old, j);
-					}
-				}
-			}
-		}
-	}
-		
-	double sigma = 0.1*(double)mapsize; // 10% der Breite/Höhe der Maps
-	
-	// alle Priormaps weichzeichnen
-	for(int j = 0; j < classno; j++)
-	{
-		for(int i = 0; i < classno; i++)
-		{
-			NICE::FloatImage tmp(mapsize, mapsize);
-			tmp.set(0.0);
-			for(int x = 0; x < mapsize; x++)
-			{
-				for(int y = 0; y < mapsize; y++)
-				{
-					tmp.setPixelQuick(x,y, priormaps[j]->get(x, y, i));
-				}
-			}
-
-			NICE::FloatImage out;
-			//FourierLibrary::gaussFilterD(tmp, out, sigma);
-			NICE::filterGaussSigmaApproximate<float,float,float>( tmp, sigma, &out);
-					
-			for(int x = 0; x < mapsize; x++)
-			{
-				for(int y = 0; y < mapsize; y++)
-				{
-					priormaps[j]->set(x, y, out.getPixel(x,y), i);
-				}
-			}
-		}
-	}
-	
-	// Summe aller Pixel an einer Position über jede Klasse = 1 
-	for(int i = 0; i < classno; i++)
-	{
-		for(int x = 0; x < mapsize; x++)
-		{
-			for(int y = 0; y < mapsize; y++)
-			{
-				double val = 0.0;
-				for(int j = 0; j < classno; j++)
-				{
-					val += priormaps[i]->get(x, y, j);
-				}
-				if(val != 0.0)
-				{
-					for(int j = 0; j < classno; j++)
-					{
-						double old = priormaps[i]->get(x, y, j);
-						old /= val;
-						priormaps[i]->set(x, y, old, j);
-					}
-				}
-			}
-		}
-	}
-	
+            priormaps[i]->set ( x, y, old, j );
+          }
+        }
+      }
+    }
+  }
+
+  double sigma = 0.1 * ( double ) mapsize; // 10% der Breite/Höhe der Maps
+
+  // alle Priormaps weichzeichnen
+  for ( int j = 0; j < classno; j++ )
+  {
+    for ( int i = 0; i < classno; i++ )
+    {
+      NICE::FloatImage tmp ( mapsize, mapsize );
+      tmp.set ( 0.0 );
+      for ( int x = 0; x < mapsize; x++ )
+      {
+        for ( int y = 0; y < mapsize; y++ )
+        {
+          tmp.setPixelQuick ( x, y, priormaps[j]->get ( x, y, i ) );
+        }
+      }
+
+      NICE::FloatImage out;
+      //FourierLibrary::gaussFilterD(tmp, out, sigma);
+      NICE::filterGaussSigmaApproximate<float, float, float> ( tmp, sigma, &out );
+
+      for ( int x = 0; x < mapsize; x++ )
+      {
+        for ( int y = 0; y < mapsize; y++ )
+        {
+          priormaps[j]->set ( x, y, out.getPixel ( x, y ), i );
+        }
+      }
+    }
+  }
+
+  // Summe aller Pixel an einer Position über jede Klasse = 1
+  for ( int i = 0; i < classno; i++ )
+  {
+    for ( int x = 0; x < mapsize; x++ )
+    {
+      for ( int y = 0; y < mapsize; y++ )
+      {
+        double val = 0.0;
+        for ( int j = 0; j < classno; j++ )
+        {
+          val += priormaps[i]->get ( x, y, j );
+        }
+        if ( val != 0.0 )
+        {
+          for ( int j = 0; j < classno; j++ )
+          {
+            double old = priormaps[i]->get ( x, y, j );
+            old /= val;
+            priormaps[i]->set ( x, y, old, j );
+          }
+        }
+      }
+    }
+  }
+
 #undef VISDEBUG
 #undef VISDEBUG
 #ifdef VISDEBUG
 #ifdef VISDEBUG
 #ifndef NOVISUAL
 #ifndef NOVISUAL
-	NICE::ColorImage rgbim((classno-1)*(mapsize+10), (classno-1)*(mapsize+10));
-	
-	double maxval = -numeric_limits<double>::max();
-	double minval = numeric_limits<double>::max();
-	
-	for(int j = 0; j < classno; j++)
-	{
-		if(j == 6) continue;
-		for(int i = 0; i < classno; i++)
-		{
-			if(i == 6) continue;
-			for(int x = 0; x < mapsize; x++)
-			{
-				for(int y = 0; y < mapsize; y++)
-				{
-					double val = priormaps[j]->get(x, y, i);
-					maxval = std::max(val, maxval);
-					minval = std::min(val, minval);
-				}
-			}
-		}
-	}
-	
-	int jcounter = 0;
-	for(int j = 0; j < classno; j++)
-	{
-		if(j == 6) continue;
-		int icounter = 0;
-		for(int i = 0; i < classno; i++)
-		{
-			if(i == 6) continue;
-			
-			NICE::FloatImage tmp(mapsize, mapsize);
-			tmp.set(0.0);
-			
-			for(int x = 0; x < mapsize; x++)
-			{
-				for(int y = 0; y < mapsize; y++)
-				{
-					tmp.setPixel(x, y, priormaps[j]->get(x, y, i));
-				}
-			}
-
-			tmp.setPixel(0,0,maxval);
-			tmp.setPixel(0,1,minval);
-			cout << "i: " << cn.text(i) << endl;
-			NICE::ColorImage imgrgb2 (mapsize, mapsize);
-			ICETools::convertToRGB(tmp, imgrgb2);
-			
-			imgrgb2.setPixel(0,0,2,imgrgb2.getPixel(1,0,2));
-			imgrgb2.setPixel(0,1,2,imgrgb2.getPixel(1,1,2));
-			imgrgb2.setPixel(0,0,0,imgrgb2.getPixel(1,0,0));
-			imgrgb2.setPixel(0,1,0,imgrgb2.getPixel(1,1,0));
-			imgrgb2.setPixel(0,0,1,imgrgb2.getPixel(1,0,1));
-			imgrgb2.setPixel(0,1,1,imgrgb2.getPixel(1,1,1));
-			
-			for(int y = 0; y < mapsize; y++)
-			{
-				for(int x = 0; x < mapsize; x++)
-				{
-					rgbim.setPixel(x+jcounter*(mapsize+10),y+icounter*(mapsize+10),2,imgrgb2.getPixel(x,y,2));
-					rgbim.setPixel(x+jcounter*(mapsize+10),y+icounter*(mapsize+10),0,imgrgb2.getPixel(x,y,0));
-					rgbim.setPixel(x+jcounter*(mapsize+10),y+icounter*(mapsize+10),1,imgrgb2.getPixel(x,y,1));
-				}
-			}
-			icounter++;
-		}
-		jcounter++;
-	}
-	rgbim.write("tmp.ppm");
+  NICE::ColorImage rgbim ( ( classno - 1 ) * ( mapsize + 10 ), ( classno - 1 ) * ( mapsize + 10 ) );
+
+  double maxval = -numeric_limits<double>::max();
+  double minval = numeric_limits<double>::max();
+
+  for ( int j = 0; j < classno; j++ )
+  {
+    if ( j == 6 ) continue;
+    for ( int i = 0; i < classno; i++ )
+    {
+      if ( i == 6 ) continue;
+      for ( int x = 0; x < mapsize; x++ )
+      {
+        for ( int y = 0; y < mapsize; y++ )
+        {
+          double val = priormaps[j]->get ( x, y, i );
+          maxval = std::max ( val, maxval );
+          minval = std::min ( val, minval );
+        }
+      }
+    }
+  }
+
+  int jcounter = 0;
+  for ( int j = 0; j < classno; j++ )
+  {
+    if ( j == 6 ) continue;
+    int icounter = 0;
+    for ( int i = 0; i < classno; i++ )
+    {
+      if ( i == 6 ) continue;
+
+      NICE::FloatImage tmp ( mapsize, mapsize );
+      tmp.set ( 0.0 );
+
+      for ( int x = 0; x < mapsize; x++ )
+      {
+        for ( int y = 0; y < mapsize; y++ )
+        {
+          tmp.setPixel ( x, y, priormaps[j]->get ( x, y, i ) );
+        }
+      }
+
+      tmp.setPixel ( 0, 0, maxval );
+      tmp.setPixel ( 0, 1, minval );
+      cout << "i: " << cn.text ( i ) << endl;
+      NICE::ColorImage imgrgb2 ( mapsize, mapsize );
+      ICETools::convertToRGB ( tmp, imgrgb2 );
+
+      imgrgb2.setPixel ( 0, 0, 2, imgrgb2.getPixel ( 1, 0, 2 ) );
+      imgrgb2.setPixel ( 0, 1, 2, imgrgb2.getPixel ( 1, 1, 2 ) );
+      imgrgb2.setPixel ( 0, 0, 0, imgrgb2.getPixel ( 1, 0, 0 ) );
+      imgrgb2.setPixel ( 0, 1, 0, imgrgb2.getPixel ( 1, 1, 0 ) );
+      imgrgb2.setPixel ( 0, 0, 1, imgrgb2.getPixel ( 1, 0, 1 ) );
+      imgrgb2.setPixel ( 0, 1, 1, imgrgb2.getPixel ( 1, 1, 1 ) );
+
+      for ( int y = 0; y < mapsize; y++ )
+      {
+        for ( int x = 0; x < mapsize; x++ )
+        {
+          rgbim.setPixel ( x + jcounter* ( mapsize + 10 ), y + icounter* ( mapsize + 10 ), 2, imgrgb2.getPixel ( x, y, 2 ) );
+          rgbim.setPixel ( x + jcounter* ( mapsize + 10 ), y + icounter* ( mapsize + 10 ), 0, imgrgb2.getPixel ( x, y, 0 ) );
+          rgbim.setPixel ( x + jcounter* ( mapsize + 10 ), y + icounter* ( mapsize + 10 ), 1, imgrgb2.getPixel ( x, y, 1 ) );
+        }
+      }
+      icounter++;
+    }
+    jcounter++;
+  }
+  rgbim.write ( "tmp.ppm" );
 #endif
 #endif
 #endif
 #endif
 }
 }
 
 
-void RelativeLocationPrior::trainClassifier(Examples &regions, NICE::MultiChannelImageT<double> & probabilities)
+void RelativeLocationPrior::trainClassifier ( Examples &regions, NICE::MultiChannelImageT<double> & probabilities )
 {
 {
-	// für alle Regionen einen Merkmalsvektor erzeugen und diesen der Trainingsmenge hinzufügen
-	getFeature(regions, probabilities);
-
-	for(int i = 0; i < (int)regions.size(); i++)
-	{
-		trainingsdata.push_back(pair<int, Example>(regions[i].first, regions[i].second));
-		regions[i].second.svec = NULL;
-	}
+  // für alle Regionen einen Merkmalsvektor erzeugen und diesen der Trainingsmenge hinzufügen
+  getFeature ( regions, probabilities );
+
+  for ( int i = 0; i < ( int ) regions.size(); i++ )
+  {
+    trainingsdata.push_back ( pair<int, Example> ( regions[i].first, regions[i].second ) );
+    regions[i].second.svec = NULL;
+  }
 }
 }
 
 
 void RelativeLocationPrior::finishClassifier()
 void RelativeLocationPrior::finishClassifier()
 {
 {
-	//////////////////////////////
-	// Klassifikatoren anlernen //
-	//////////////////////////////
-	FeaturePool fp;
-	Feature *f = new SparseVectorFeature ( featdim );
-	f->explode ( fp );
-	delete f;
-	
-	//feature size
-	int s = 3;
-
-	classifiers.resize(classno);
-	for(int i = 0; i < classno; i++)
-	{
-		classifiers[i] = SLR(conf, "ClassifierSMLR");
-		Examples ex2;
-		int countex = 0;
-		for(int j = 0; j < (int)trainingsdata.size(); j++)
-		{
-			Example e;
-			int z = 0;
-			e.svec = new SparseVector(s+1);
-			for(int k = i*s; k < i*s+s; k++, z++)
-			{
-				double val = trainingsdata[j].second.svec->get(k);
-				if(val != 0.0)
-					(*e.svec)[z] = val;
-			}
-			(*e.svec)[s] = 1.0;
-			
-			ex2.push_back ( pair<int, Example> ( trainingsdata[j].first, e ) );
-			
-			if(trainingsdata[j].first == i)
-				countex++;
-		}
-				
-		if(ex2.size() <= 2 || countex < 1)
-			continue;
-		
-		classifiers[i].train(fp, ex2, i);
-				
-		for(int j = 0; j < (int)ex2.size(); j++)
-		{
-			delete ex2[j].second.svec;
-			ex2[j].second.svec = NULL;
-		}
-	}
-	
-	trainingsdata.clear();
+  //////////////////////////////
+  // Klassifikatoren anlernen //
+  //////////////////////////////
+  FeaturePool fp;
+  Feature *f = new SparseVectorFeature ( featdim );
+  f->explode ( fp );
+  delete f;
+
+  //feature size
+  int s = 3;
+
+  classifiers.resize ( classno );
+  for ( int i = 0; i < classno; i++ )
+  {
+    classifiers[i] = SLR ( conf, "ClassifierSMLR" );
+    Examples ex2;
+    int countex = 0;
+    for ( int j = 0; j < ( int ) trainingsdata.size(); j++ )
+    {
+      Example e;
+      int z = 0;
+      e.svec = new SparseVector ( s + 1 );
+      for ( int k = i * s; k < i*s + s; k++, z++ )
+      {
+        double val = trainingsdata[j].second.svec->get ( k );
+        if ( val != 0.0 )
+          ( *e.svec ) [z] = val;
+      }
+      ( *e.svec ) [s] = 1.0;
+
+      ex2.push_back ( pair<int, Example> ( trainingsdata[j].first, e ) );
+
+      if ( trainingsdata[j].first == i )
+        countex++;
+    }
+
+    if ( ex2.size() <= 2 || countex < 1 )
+      continue;
+
+    classifiers[i].train ( fp, ex2, i );
+
+    for ( int j = 0; j < ( int ) ex2.size(); j++ )
+    {
+      delete ex2[j].second.svec;
+      ex2[j].second.svec = NULL;
+    }
+  }
+
+  trainingsdata.clear();
 }
 }
 
 
-void RelativeLocationPrior::postprocess ( Examples &regions, NICE::MultiChannelImageT<double> & probabilities)
+void RelativeLocationPrior::postprocess ( Examples &regions, NICE::MultiChannelImageT<double> & probabilities )
 {
 {
-	getFeature(regions, probabilities);
-	
-	int s = 3;
-	
-	for(int i = 0; i < (int) regions.size(); i++)
-	{
-		FullVector overall_distribution(classno+1);
-		overall_distribution[classno] = 0.0;
-		
-		double maxp = -numeric_limits<double>::max();
-		int bestclass = 0;
-	
-		double sum  = 0.0;
-
-		for(int c = 0; c < classno; c++)
-		{		
-			Example e;
-			int z = 0;
-			e.svec = new SparseVector(s+1);
-			for(int k = c*s; k < c*s+s; k++, z++)
-			{
-				double val = regions[i].second.svec->get(k);
-				if(val != 0.0)
-					(*e.svec)[z] = val;
-			}
-			(*e.svec)[s] = 1.0;
-			
-			overall_distribution[c] = classifiers[c].classify(e);
-		
-			sum += overall_distribution[c];
-		
-			if(maxp < overall_distribution[c])
-			{
-				bestclass = c;
-				maxp = overall_distribution[c];
-			}
-			delete e.svec;
-			e.svec = NULL;
-		}
-
-		for(int c = 0; c < classno; c++)
-		{
-			overall_distribution[c] /= sum;
-		}
-
-		ClassificationResult r = ClassificationResult( bestclass, overall_distribution );
-
-		if(bestclass < 0)
-		{
-			regions[i].second.svec->store(cout);cout << endl;
-			cout << "fehler: besclass=" << bestclass << endl;			
-			for(int j = 0; j < (int)probabilities.numChannels; j++)
-			{
-				cout << "j: " << j << " score: " << r.scores[j] << endl;
-			}
-		}
-		regions[i].first = bestclass;
-	}
+  getFeature ( regions, probabilities );
+
+  int s = 3;
+
+  for ( int i = 0; i < ( int ) regions.size(); i++ )
+  {
+    FullVector overall_distribution ( classno + 1 );
+    overall_distribution[classno] = 0.0;
+
+    double maxp = -numeric_limits<double>::max();
+    int bestclass = 0;
+
+    double sum  = 0.0;
+
+    for ( int c = 0; c < classno; c++ )
+    {
+      Example e;
+      int z = 0;
+      e.svec = new SparseVector ( s + 1 );
+      for ( int k = c * s; k < c*s + s; k++, z++ )
+      {
+        double val = regions[i].second.svec->get ( k );
+        if ( val != 0.0 )
+          ( *e.svec ) [z] = val;
+      }
+      ( *e.svec ) [s] = 1.0;
+
+      overall_distribution[c] = classifiers[c].classify ( e );
+
+      sum += overall_distribution[c];
+
+      if ( maxp < overall_distribution[c] )
+      {
+        bestclass = c;
+        maxp = overall_distribution[c];
+      }
+      delete e.svec;
+      e.svec = NULL;
+    }
+
+    for ( int c = 0; c < classno; c++ )
+    {
+      overall_distribution[c] /= sum;
+    }
+
+    ClassificationResult r = ClassificationResult ( bestclass, overall_distribution );
+
+    if ( bestclass < 0 )
+    {
+      regions[i].second.svec->store ( cout );
+      cout << endl;
+      cout << "fehler: besclass=" << bestclass << endl;
+      for ( int j = 0; j < ( int ) probabilities.channels(); j++ )
+      {
+        cout << "j: " << j << " score: " << r.scores[j] << endl;
+      }
+    }
+    regions[i].first = bestclass;
+  }
 }
 }
 
 
-void RelativeLocationPrior::convertCoords(int &x, int xsize)
+void RelativeLocationPrior::convertCoords ( int &x, int xsize )
 {
 {
-	x = (int)round((double(x)+(double)xsize)/(2.0*(double)xsize) * ((double)mapsize-1.0));
+  x = ( int ) round ( ( double ( x ) + ( double ) xsize ) / ( 2.0 * ( double ) xsize ) * ( ( double ) mapsize - 1.0 ) );
 
 
-	x = std::min(x, mapsize-1);
-	x = std::max(x,0);
+  x = std::min ( x, mapsize - 1 );
+  x = std::max ( x, 0 );
 }
 }
 
 
-void RelativeLocationPrior::getFeature(Examples &regions, NICE::MultiChannelImageT<double> & probabilities)
+void RelativeLocationPrior::getFeature ( Examples &regions, NICE::MultiChannelImageT<double> & probabilities )
 {
 {
 
 
-	int xsize, ysize;
-	xsize = probabilities.xsize;
-	ysize = probabilities.ysize;
-	
-	// get best classes
-	vector<int> bestclasses(regions.size(), -1);
-	for(int r = 0; r < (int)regions.size(); r++)
-	{
-		double maxval = -numeric_limits<double>::max();
-		for(int c = 0; c < (int)probabilities.numChannels; c++)	
-		{
-			double val = probabilities.get(regions[r].second.x, regions[r].second.y, c);
-			if(maxval < val)
-			{
-				bestclasses[r] = c;
-				maxval = val;
-			}
-		}
-	}
-	
-	vector<double> alpha;
-	for(int r = 0; r < (int)regions.size(); r++)
-	{
-		double tmpalpha = probabilities.get(regions[r].second.x,regions[r].second.y,bestclasses[r]) *regions[r].second.weight;
-		
-		alpha.push_back(tmpalpha);
-	}
-
-	//erzeuge f_relloc
-	vector<vector<double> > vother;
-	vector<vector<double> > vself;		
-	for(int i = 0; i < (int)regions.size(); i++)
-	{
-		vector<double> v,w;
-		vother.push_back(v);
-		vself.push_back(w);
-		for( int c = 0; c < classno; c++)
-		{
-			double tmp_vother = 0.0;
-			double tmp_self = 0.0;
-			
-			for(int j = 0; j < (int)regions.size(); j++)
-			{
-				if(j == i)
-					continue;
-				
-				int x = regions[i].second.x - regions[j].second.x;
-				int y = regions[i].second.y - regions[j].second.y;
-					
-				convertCoords(x, xsize);
-				convertCoords(y, ysize);
-
-				double val = priormaps[c]->get(x, y, bestclasses[j]) * alpha[j]; ;
-
-				if(bestclasses[j] == bestclasses[i])//Objektbestandteile
-				{
-					tmp_self += val;
-				}
-				else//Kontextinformationen
-				{
-					tmp_vother += val;
-				}
-			}
-			
-			if(fabs(tmp_self) < 10e-7)
-				tmp_self = 10e-7;
-			if(fabs(tmp_vother) < 10e-7)
-				tmp_vother = 10e-7;
-			
-			vother[i].push_back(tmp_vother);
-			vself[i].push_back(tmp_self);
-		}
-	}
-
-	for(int r = 0; r < (int)regions.size(); r++)
-	{
-		if(regions[r].second.svec !=NULL)
-		{
-			delete regions[r].second.svec;
-			regions[r].second.svec = NULL;
-		}		
-		if(regions[r].second.vec !=NULL)
-		{
-			delete regions[r].second.vec;
-			regions[r].second.vec = NULL;
-		}
-
-		regions[r].second.svec = new SparseVector(classno*3);
-		
-		int counter = 0; 
-		
-		for (int i = 0; i < classno; i++)
-		{
-			//appearence feature (old probability for each class
-			double fapp = log(probabilities.get(regions[r].second.x,regions[r].second.y,i));
-			
-			if(fabs(fapp) > 10e-7)
-				(*(regions[r].second.svec))[counter] = fapp;
-			counter++;
-			
-			double val = log(vother[r][i]);
-			
-			if(fabs(val) > 10e-7)
-				(*(regions[r].second.svec))[counter] = val;
-			counter++;
-			
-			val =log(vself[r][i]);
-			
-			if(fabs(val) > 10e-7)
-				(*(regions[r].second.svec))[counter] = val;
-			counter++;
-		}
-	}
+  int xsize, ysize;
+  xsize = probabilities.width();
+  ysize = probabilities.height();
+
+  // get best classes
+  vector<int> bestclasses ( regions.size(), -1 );
+  for ( int r = 0; r < ( int ) regions.size(); r++ )
+  {
+    double maxval = -numeric_limits<double>::max();
+    for ( int c = 0; c < ( int ) probabilities.channels(); c++ )
+    {
+      double val = probabilities.get ( regions[r].second.x, regions[r].second.y, c );
+      if ( maxval < val )
+      {
+        bestclasses[r] = c;
+        maxval = val;
+      }
+    }
+  }
+
+  vector<double> alpha;
+  for ( int r = 0; r < ( int ) regions.size(); r++ )
+  {
+    double tmpalpha = probabilities.get ( regions[r].second.x, regions[r].second.y, bestclasses[r] ) * regions[r].second.weight;
+
+    alpha.push_back ( tmpalpha );
+  }
+
+  //erzeuge f_relloc
+  vector<vector<double> > vother;
+  vector<vector<double> > vself;
+  for ( int i = 0; i < ( int ) regions.size(); i++ )
+  {
+    vector<double> v, w;
+    vother.push_back ( v );
+    vself.push_back ( w );
+    for ( int c = 0; c < classno; c++ )
+    {
+      double tmp_vother = 0.0;
+      double tmp_self = 0.0;
+
+      for ( int j = 0; j < ( int ) regions.size(); j++ )
+      {
+        if ( j == i )
+          continue;
+
+        int x = regions[i].second.x - regions[j].second.x;
+        int y = regions[i].second.y - regions[j].second.y;
+
+        convertCoords ( x, xsize );
+        convertCoords ( y, ysize );
+
+        double val = priormaps[c]->get ( x, y, bestclasses[j] ) * alpha[j]; ;
+
+        if ( bestclasses[j] == bestclasses[i] ) //Objektbestandteile
+        {
+          tmp_self += val;
+        }
+        else//Kontextinformationen
+        {
+          tmp_vother += val;
+        }
+      }
+
+      if ( fabs ( tmp_self ) < 10e-7 )
+        tmp_self = 10e-7;
+      if ( fabs ( tmp_vother ) < 10e-7 )
+        tmp_vother = 10e-7;
+
+      vother[i].push_back ( tmp_vother );
+      vself[i].push_back ( tmp_self );
+    }
+  }
+
+  for ( int r = 0; r < ( int ) regions.size(); r++ )
+  {
+    if ( regions[r].second.svec != NULL )
+    {
+      delete regions[r].second.svec;
+      regions[r].second.svec = NULL;
+    }
+    if ( regions[r].second.vec != NULL )
+    {
+      delete regions[r].second.vec;
+      regions[r].second.vec = NULL;
+    }
+
+    regions[r].second.svec = new SparseVector ( classno*3 );
+
+    int counter = 0;
+
+    for ( int i = 0; i < classno; i++ )
+    {
+      //appearence feature (old probability for each class
+      double fapp = log ( probabilities.get ( regions[r].second.x, regions[r].second.y, i ) );
+
+      if ( fabs ( fapp ) > 10e-7 )
+        ( * ( regions[r].second.svec ) ) [counter] = fapp;
+      counter++;
+
+      double val = log ( vother[r][i] );
+
+      if ( fabs ( val ) > 10e-7 )
+        ( * ( regions[r].second.svec ) ) [counter] = val;
+      counter++;
+
+      val = log ( vself[r][i] );
+
+      if ( fabs ( val ) > 10e-7 )
+        ( * ( regions[r].second.svec ) ) [counter] = val;
+      counter++;
+    }
+  }
 }
 }
 
 
-void RelativeLocationPrior::restore (istream & is, int format)
+void RelativeLocationPrior::restore ( istream & is, int format )
 {
 {
-	is >> classno;
-	is >> mapsize;
-	is >> featdim;
-	
-	//Priorsmaps erzeugen
-	for(int i = 0; i < classno; i++)
-	{
-		NICE::MultiChannelImageT<double> *tmp  = new NICE::MultiChannelImageT<double>(mapsize, mapsize, classno, true);
-		tmp->setAll(0.0);
-		priormaps.push_back(tmp);
-	}
-	
-	double val;
-	for(int i = 0; i < classno; i++)
-	{
-		for(int j = 0; j < classno; j++)
-		{
-			for(int x = 0; x < mapsize; x++)
-			{
-				for(int y = 0; y < mapsize; y++)
-				{
-					
-					is >> val;
-					priormaps[i]->set(x, y, val, j);
-				}
-			}
-		}
-	}
-	
-	classifiers.resize(classno);
-	for(int i = 0; i < classno; i++)
-	{
-		classifiers[i] = SLR();
-		classifiers[i].restore(is, format);
-	}
+  is >> classno;
+  is >> mapsize;
+  is >> featdim;
+
+  //Priorsmaps erzeugen
+  for ( int i = 0; i < classno; i++ )
+  {
+    NICE::MultiChannelImageT<double> *tmp  = new NICE::MultiChannelImageT<double> ( mapsize, mapsize, classno);
+    tmp->setAll ( 0.0 );
+    priormaps.push_back ( tmp );
+  }
+
+  double val;
+  for ( int i = 0; i < classno; i++ )
+  {
+    for ( int j = 0; j < classno; j++ )
+    {
+      for ( int x = 0; x < mapsize; x++ )
+      {
+        for ( int y = 0; y < mapsize; y++ )
+        {
+
+          is >> val;
+          priormaps[i]->set ( x, y, val, j );
+        }
+      }
+    }
+  }
+
+  classifiers.resize ( classno );
+  for ( int i = 0; i < classno; i++ )
+  {
+    classifiers[i] = SLR();
+    classifiers[i].restore ( is, format );
+  }
 }
 }
 
 
-void RelativeLocationPrior::store (ostream & os, int format) const
+void RelativeLocationPrior::store ( ostream & os, int format ) const
 {
 {
-	os << classno << " ";
-	os << mapsize << " ";
-	os << featdim << endl;
-	for(int i = 0; i < classno; i++)
-	{
-		for(int j = 0; j < classno; j++)
-		{
-			for(int x = 0; x < mapsize; x++)
-			{
-				for(int y = 0; y < mapsize; y++)
-				{
-					os << priormaps[i]->get(x, y, j) << " ";
-				}
-			}
-		}
-	}
-	
-	for(int i = 0; i < classno; i++)
-	{
-		classifiers[i].store(os, format);
-	}
+  os << classno << " ";
+  os << mapsize << " ";
+  os << featdim << endl;
+  for ( int i = 0; i < classno; i++ )
+  {
+    for ( int j = 0; j < classno; j++ )
+    {
+      for ( int x = 0; x < mapsize; x++ )
+      {
+        for ( int y = 0; y < mapsize; y++ )
+        {
+          os << priormaps[i]->get ( x, y, j ) << " ";
+        }
+      }
+    }
+  }
+
+  for ( int i = 0; i < classno; i++ )
+  {
+    classifiers[i].store ( os, format );
+  }
 }
 }
 
 
 void RelativeLocationPrior::clear ()
 void RelativeLocationPrior::clear ()
 {
 {
-	
+
 }
 }