Bjoern Froehlich 12 年之前
父節點
當前提交
454eb2e252

+ 0 - 92
classifier/FPCnone.cpp

@@ -1,92 +0,0 @@
-#include "semseg/classifier/FPCnone.h"
-
-#include <iostream>
-
-using namespace OBJREC;
-
-using namespace std;
-
-using namespace NICE;
-
-FPCnone::FPCnone()
-{
-}
-
-FPCnone::FPCnone( const Config *_conf, string section )
-{
-  conf = _conf;
-}
-
-FPCnone::~FPCnone()
-{
-  //clean up
-}
-
-ClassificationResult FPCnone::classify( Example & pce )
-{
-  FullVector overall_distribution( maxClassNo + 1 );
-  overall_distribution[maxClassNo] = 0.0;
-
-  double maxp = -numeric_limits<double>::max();
-  int classno = 0;
-
-  double sum  = 0.0;
-
-  for ( int i = 0; i < maxClassNo + 1; i++ )
-  {
-    overall_distribution[i] = ( *pce.vec )[i];
-
-    sum += overall_distribution[i];
-
-    if ( maxp < overall_distribution[i] )
-    {
-      classno = i;
-      maxp = overall_distribution[i];
-    }
-  }
-
-  /*for(int i = 0; i < maxClassNo; i++)
-  {
-   overall_distribution[i] /= sum;
-  }*/
-
-  //cout << "Klasse: " << classno << " prob: " << overall_distribution[classno] << endl;
-  if ( classno > 12 )
-  {
-    cout << "failure" << endl;
-  }
-
-  return ClassificationResult( classno, overall_distribution );
-}
-
-void FPCnone::train( FeaturePool & _fp, Examples & examples )
-{
-  fp = FeaturePool( _fp );
-}
-
-
-void FPCnone::restore( istream & is, int format )
-{
-}
-
-void FPCnone::store( ostream & os, int format ) const
-{
-}
-
-void FPCnone::clear()
-{
-}
-
-FeaturePoolClassifier *FPCnone::clone() const
-{
-  FPCnone *o = new FPCnone( conf, "non" );
-
-  o->maxClassNo = maxClassNo;
-
-  return o;
-}
-
-void FPCnone::setComplexity( int size )
-{
-  cerr << "FPCnone: no complexity to set" << endl;
-}

+ 0 - 81
classifier/FPCnone.h

@@ -1,81 +0,0 @@
-/**
- * @file FPCnone.h
- * @brief bad hack, not realy a classifier, returns the first values as classification result
- * @author Björn Fröhlich
- * @date 18/06/2010
-
- */
-#ifndef FPCnoneDEF
-#define FPCnoneDEF
-
-#include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
-#include "vislearning/classifier/fpclassifier/logisticregression/SLR.h"
-#include "vislearning/cbaselib/FeaturePool.h"
-
-namespace OBJREC {
-
-class FPCnone : public FeaturePoolClassifier
-{
-
-protected:
-
-  //! the featurepool
-  FeaturePool fp;
-
-  //! config file;
-  const NICE::Config *conf;
-
-public:
-  /**
-   * standard constructor
-   * @param conf configfile
-   * @param section section name in configfile for classifier
-   */
-  FPCnone( const NICE::Config *conf, std::string section = "SMLR" );
-
-
-  /**
-   * simple constructor -> does nothing
-   */
-  FPCnone();
-
-  /**
-   * simple destructor
-   */
-  ~FPCnone();
-
-  /**
-   * main classification function
-   * @param pce input feature
-   * @return a classification result
-   */
-  ClassificationResult classify( Example & pce );
-
-  /**
-   * start training
-   * @param fp a featurepool (how to handle which features...)
-   * @param examples input features
-   */
-  void train( FeaturePool & _fp, Examples & examples );
-
-  /**
-   * clone this object
-   * @return a copy of this object
-   */
-  FeaturePoolClassifier *clone() const;
-
-  /**
-   * set complexity for the next training process e.g. number of weak classifiers
-   * @param size new complexity
-   */
-  void setComplexity( int size );
-
-  /** IO functions */
-  void restore( std::istream & is, int format = 0 );
-  void store( std::ostream & os, int format = 0 ) const;
-  void clear();
-};
-
-} // namespace
-
-#endif

+ 0 - 103
classifier/Makefile.inc

@@ -1,103 +0,0 @@
-# LIBRARY-DIRECTORY-MAKEFILE
-# conventions:
-# - all subdirectories containing a "Makefile.inc" are considered sublibraries
-#   exception: "progs/" and "tests/" subdirectories!
-# - all ".C", ".cpp" and ".c" files in the current directory are linked to a
-#   library
-# - the library depends on all sublibraries 
-# - the library name is created with $(LIBNAME), i.e. it will be somehow
-#   related to the directory name and with the extension .a
-#   (e.g. lib1/sublib -> lib1_sublib.a)
-# - the library will be added to the default build list ALL_LIBRARIES
-
-# --------------------------------
-# - remember the last subdirectory
-#
-# set the variable $(SUBDIR) correctly to the current subdirectory. this
-# variable can be used throughout the current makefile.inc. The many 
-# SUBDIR_before, _add, and everything are only required so that we can recover
-# the previous content of SUBDIR before exitting the makefile.inc
-
-SUBDIR_add:=$(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
-SUBDIR_before:=$(SUBDIR)
-SUBDIR:=$(strip $(SUBDIR_add))
-SUBDIR_before_$(SUBDIR):=$(SUBDIR_before)
-ifeq "$(SUBDIR)" "./"
-SUBDIR:=
-endif
-
-# ------------------------
-# - include subdirectories
-#
-# note the variables $(SUBDIRS_OF_$(SUBDIR)) are required later on to recover
-# the dependencies automatically. if you handle dependencies on your own, you
-# can also dump the $(SUBDIRS_OF_$(SUBDIR)) variable, and include the
-# makefile.inc of the subdirectories on your own...
-
-SUBDIRS_OF_$(SUBDIR):=$(patsubst %/Makefile.inc,%,$(wildcard $(SUBDIR)*/Makefile.inc))
-include $(SUBDIRS_OF_$(SUBDIR):%=%/Makefile.inc)
-
-# ----------------------------
-# - include local dependencies
-#
-# you can specify libraries needed by the individual objects or by the whole
-# directory. the object specific additional libraries are only considered
-# when compiling the specific object files
-# TODO: update documentation...
-
--include $(SUBDIR)libdepend.inc
-
-$(foreach d,$(filter-out %progs %tests,$(SUBDIRS_OF_$(SUBDIR))),$(eval $(call PKG_DEPEND_INT,$(d))))
-
-# ---------------------------
-# - objects in this directory
-#
-# the use of the variable $(OBJS) is not mandatory. it is mandatory however
-# to update $(ALL_OBJS) in a way that it contains the path and name of
-# all objects. otherwise we can not include the appropriate .d files.
-
-OBJS:=$(patsubst %.cpp,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.cpp))) \
-      $(patsubst %.C,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.C))) \
-	  $(shell grep -ls Q_OBJECT $(SUBDIR)*.h | sed -e's@^@/@;s@.*/@$(OBJDIR)moc_@;s@\.h$$@.o@') \
-      $(patsubst %.c,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.c)))
-ALL_OBJS += $(OBJS)
-
-# ----------------------------
-# - binaries in this directory
-#
-# output of binaries in this directory. none of the variables has to be used.
-# but everything you add to $(ALL_LIBRARIES) and $(ALL_BINARIES) will be
-# compiled with `make all`. be sure again to add the files with full path.
-
-LIBRARY_BASENAME:=$(call LIBNAME,$(SUBDIR))
-ifneq "$(SUBDIR)" ""
-ALL_LIBRARIES+=$(LIBDIR)$(LIBRARY_BASENAME).$(LINK_FILE_EXTENSION)
-endif
-
-# ---------------------
-# - binary dependencies
-#
-# there is no way of determining the binary dependencies automatically, so we
-# follow conventions. the current library depends on all sublibraries.
-# all other dependencies have to be added manually by specifying, that the
-# current .pc file depends on some other .pc file. binaries depending on
-# libraries should exclusivelly use the .pc files as well.
-
-ifeq "$(SKIP_BUILD_$(OBJDIR))" "1"
-$(LIBDIR)$(LIBRARY_BASENAME).a:
-else
-$(LIBDIR)$(LIBRARY_BASENAME).a:$(OBJS) \
-	$(call PRINT_INTLIB_DEPS,$(PKGDIR)$(LIBRARY_BASENAME).a,.$(LINK_FILE_EXTENSION))
-endif
-
-$(PKGDIR)$(LIBRARY_BASENAME).pc: \
-	$(call PRINT_INTLIB_DEPS,$(PKGDIR)$(LIBRARY_BASENAME).pc,.pc)
-
-# -------------------
-# - subdir management
-#
-# as the last step, always add this line to correctly recover the subdirectory
-# of the makefile including this one!
-
-SUBDIR:=$(SUBDIR_before_$(SUBDIR))
-

+ 0 - 1
classifier/libdepend.inc

@@ -1 +0,0 @@
-$(call PKG_DEPEND_INT,objrec/classifier)

+ 0 - 1
libdepend.inc

@@ -1,2 +1 @@
-$(call PKG_DEPEND_INT,objrec/semanticsegmentation)
 $(call PKG_DEPEND_INT,core)
 $(call PKG_DEPEND_INT,core)

+ 2 - 4
progs/testClassifier.cpp

@@ -5,13 +5,11 @@
 * @date 2007-10-12
 * @date 2007-10-12
 */
 */
 
 
-#include <objrec/nice_nonvis.h>
-
 #include <fstream>
 #include <fstream>
 #include <iostream>
 #include <iostream>
 
 
 #include <vislearning/cbaselib/MultiDataset.h>
 #include <vislearning/cbaselib/MultiDataset.h>
-#include <objrec/iclassifier/icgeneric/CSGeneric.h>
+#include "vislearning/classifier/genericClassifierSelection.h"
 #include <vislearning/cbaselib/ClassificationResults.h>
 #include <vislearning/cbaselib/ClassificationResults.h>
 #include <vislearning/cbaselib/MutualInformation.h>
 #include <vislearning/cbaselib/MutualInformation.h>
 
 
@@ -175,7 +173,7 @@ int main( int argc, char **argv )
       FeaturePoolClassifier *fpc = new FPCRandomForestTransfer( &conf, classNames );
       FeaturePoolClassifier *fpc = new FPCRandomForestTransfer( &conf, classNames );
       vec_classifier = new VCFeaturePool( &conf, fpc );
       vec_classifier = new VCFeaturePool( &conf, fpc );
     } else {
     } else {
-      vec_classifier = CSGeneric::selectVecClassifier( &conf, "main" );
+      vec_classifier = GenericClassifierSelection::selectVecClassifier( &conf, "main" );
     }
     }
 
 
     NICE::Vector thresholds;
     NICE::Vector thresholds;

+ 2 - 2
progs/testClassifierGMM.cpp

@@ -9,7 +9,7 @@
 #include <iostream>
 #include <iostream>
 
 
 #include <vislearning/cbaselib/MultiDataset.h>
 #include <vislearning/cbaselib/MultiDataset.h>
-#include <objrec/iclassifier/icgeneric/CSGeneric.h>
+#include "vislearning/classifier/genericClassifierSelection.h"
 #include <vislearning/cbaselib/ClassificationResults.h>
 #include <vislearning/cbaselib/ClassificationResults.h>
 #include <vislearning/cbaselib/MutualInformation.h>
 #include <vislearning/cbaselib/MutualInformation.h>
 
 
@@ -199,7 +199,7 @@ int main( int argc, char **argv )
       FeaturePoolClassifier *fpc = new FPCRandomForestTransfer( &conf, classNames );
       FeaturePoolClassifier *fpc = new FPCRandomForestTransfer( &conf, classNames );
       vec_classifier = new VCFeaturePool( &conf, fpc );
       vec_classifier = new VCFeaturePool( &conf, fpc );
     } else {
     } else {
-      vec_classifier = CSGeneric::selectVecClassifier( &conf, "main" );
+      vec_classifier = GenericClassifierSelection::selectVecClassifier( &conf, "main" );
     }
     }
 
 
     NICE::Vector thresholds;
     NICE::Vector thresholds;

+ 0 - 1
progs/testSemanticSegmentation.cpp

@@ -19,7 +19,6 @@
 #include <semseg/semseg/SemSegLocal.h>
 #include <semseg/semseg/SemSegLocal.h>
 #include <semseg/semseg/SemSegCsurka.h>
 #include <semseg/semseg/SemSegCsurka.h>
 #include <semseg/semseg/SemSegNovelty.h>
 #include <semseg/semseg/SemSegNovelty.h>
-#include <semseg/semseg/SemSegRegionBased.h>
 #include <semseg/semseg/SemSegContextTree.h>
 #include <semseg/semseg/SemSegContextTree.h>
 
 
 #include <core/basics/ResourceStatistics.h>
 #include <core/basics/ResourceStatistics.h>

+ 2 - 2
semseg/SemSegContextTree.cpp

@@ -6,8 +6,8 @@
 #include "vislearning/cbaselib/CachedExample.h"
 #include "vislearning/cbaselib/CachedExample.h"
 #include "vislearning/cbaselib/PascalResults.h"
 #include "vislearning/cbaselib/PascalResults.h"
 #include "vislearning/baselib/ColorSpace.h"
 #include "vislearning/baselib/ColorSpace.h"
-#include "objrec/segmentation/RSMeanShift.h"
-#include "objrec/segmentation/RSGraphBased.h"
+#include "segmentation/RSMeanShift.h"
+#include "segmentation/RSGraphBased.h"
 #include "core/basics/numerictools.h"
 #include "core/basics/numerictools.h"
 #include "core/basics/StringTools.h"
 #include "core/basics/StringTools.h"
 #include "core/basics/FileName.h"
 #include "core/basics/FileName.h"

+ 1 - 1
semseg/SemSegContextTree.h

@@ -11,7 +11,7 @@
 #include "SemanticSegmentation.h"
 #include "SemanticSegmentation.h"
 #include <core/vector/VVector.h>
 #include <core/vector/VVector.h>
 #include "vislearning/features/localfeatures/LFColorWeijer.h"
 #include "vislearning/features/localfeatures/LFColorWeijer.h"
-#include "objrec/segmentation/RegionSegmentationMethod.h"
+#include "segmentation/RegionSegmentationMethod.h"
 
 
 #include "semseg/semseg/operations/Operations.h"
 #include "semseg/semseg/operations/Operations.h"
 
 

+ 1 - 1
semseg/SemSegCsurka.cpp

@@ -118,7 +118,7 @@ SemSegCsurka::SemSegCsurka ( const Config *conf,
   else if ( cname == "GPHIK" )
   else if ( cname == "GPHIK" )
     classifier = new GPHIKClassifierNICE ( conf, "ClassiferGPHIK" );
     classifier = new GPHIKClassifierNICE ( conf, "ClassiferGPHIK" );
   else
   else
-    vclassifier = CSGeneric::selectVecClassifier ( conf, "main" );
+    vclassifier = GenericClassifierSelection::selectVecClassifier ( conf, "main" );
   //classifier = new FPCSparseMultinomialLogisticRegression(conf, "ClassifierSMLR");
   //classifier = new FPCSparseMultinomialLogisticRegression(conf, "ClassifierSMLR");
 
 
   if ( classifier != NULL )
   if ( classifier != NULL )

+ 5 - 6
semseg/SemSegCsurka.h

@@ -24,10 +24,10 @@
 #include "vislearning/baselib/Preprocess.h"
 #include "vislearning/baselib/Preprocess.h"
 #include "vislearning/baselib/Globals.h"
 #include "vislearning/baselib/Globals.h"
 
 
-#include "objrec/segmentation/RegionSegmentationMethod.h"
-#include "objrec/segmentation/RSMeanShift.h"
-#include "objrec/segmentation/RSGraphBased.h"
-#include "objrec/segmentation/RSCache.h"
+#include "segmentation/RegionSegmentationMethod.h"
+#include "segmentation/RSMeanShift.h"
+#include "segmentation/RSGraphBased.h"
+#include "segmentation/RSCache.h"
 
 
 #include "SemSegTools.h"
 #include "SemSegTools.h"
 
 
@@ -42,8 +42,7 @@
 #include "semseg/semseg/postsegmentation/PPSuperregion.h"
 #include "semseg/semseg/postsegmentation/PPSuperregion.h"
 #include "semseg/semseg/postsegmentation/PPGraphCut.h"
 #include "semseg/semseg/postsegmentation/PPGraphCut.h"
 
 
-
-#include <objrec/iclassifier/icgeneric/CSGeneric.h>
+#include "vislearning/classifier/genericClassifierSelection.h"
 
 
 /** @brief pixelwise labeling systems */
 /** @brief pixelwise labeling systems */
 
 

+ 0 - 1440
semseg/SemSegRegionBased.cpp

@@ -1,1440 +0,0 @@
-#ifdef NICE_USELIB_OPENMP
-#include <omp.h>
-#endif
-
-#include "SemSegRegionBased.h"
-
-#include <iostream>
-
-#include "vislearning/cbaselib/CachedExample.h"
-#include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
-#include "vislearning/classifier/fpclassifier/logisticregression/FPCSMLR.h"
-
-#include <objrec/iclassifier/icgeneric/CSGeneric.h>
-#include "vislearning/features/fpfeatures/PixelPairFeature.h"
-#include "vislearning/classifier/genericClassifierSelection.h"
-
-#include "SemSegTools.h"
-
-#include "objrec/segmentation/RSMeanShift.h"
-#include "objrec/segmentation/RSCache.h"
-#include "objrec/segmentation/RSGraphBased.h"
-
-#include "vislearning/baselib/Globals.h"
-
-#include <vislearning/cbaselib/VectorFeature.h>
-
-#include "vislearning/features/fpfeatures/SparseVectorFeature.h"
-#include "vislearning/features/localfeatures/LFColorWeijer.h"
-#include "vislearning/features/localfeatures/LFColorSande.h"
-#include "vislearning/features/localfeatures/LocalFeatureSift.h"
-#include "vislearning/features/localfeatures/LocalFeatureOpponnentSift.h"
-#include "vislearning/features/localfeatures/LocalFeatureLFInterface.h"
-#include "vislearning/features/localfeatures/LocalFeatureRGBSift.h"
-#include "vislearning/features/localfeatures/LFCache.h"
-
-#include "objrec/features/regionfeatures/RFColor.h"
-#include "objrec/features/regionfeatures/RFHoG.h"
-#include "objrec/features/regionfeatures/RFBoV.h"
-#include "objrec/features/regionfeatures/RFBoVCodebook.h"
-#include "objrec/features/regionfeatures/RFCsurka.h"
-
-#include "objrec/iclassifier/codebook/CodebookRandomForest.h"
-
-#include "vislearning/math/cluster/GMM.h"
-
-#undef DEMO
-#undef WRITEFEATS
-
-using namespace OBJREC;
-using namespace std;
-using namespace NICE;
-
-#define DEBUG_PRINTS
-
-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
-}
-
-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
-}
-
-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 DEMO
-    rsm->visualizeGraphRepresentation ( cimg, mask );
-#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 );
-
-//#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 ) );
-    }
-//#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
-}
-
-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 )
-{
-#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 )
-{
-#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 )
-{
-#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
-  // 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
-
-  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;
-
-//#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
-      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 )
-{
-#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 )
-{
-#ifdef DEBUG_PRINTS
-  cout << "SemSegRegionBased::semanticseg starts" << endl;
-#endif
-  int xsize, ysize;
-
-  ce->getImageSize ( xsize, ysize );
-
-  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 );
-#ifdef DEMO
-  rsm->visualizeGraphRepresentation ( cimg, mask );
-#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;
-  }
-#endif
-
-  segresult = NICE::Image ( xsize, ysize );
-  segresult.set ( 0 );
-
-  Examples examples;
-
-  vector<vector<double> > probs;
-
-  classify ( feats, examples, probs );
-
-  labelRegions ( rg, probs );
-
-  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 )
-{
-#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 )
-{
-#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] ) );
-    }
-#ifdef DEMO
-    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
-}
-
-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 ) )
-  {
-//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
-}
-
-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
-}
-
-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
-}
-
-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
-}

+ 0 - 190
semseg/SemSegRegionBased.h

@@ -1,190 +0,0 @@
-/**
-* @file SemSegRegionBased.h
-* @brief new semantic segmentation method using regions
-* @author Björn Fröhlich
-* @date 01/29/2010
-*/
-#ifndef SemSegRegionBasedINCLUDE
-#define SemSegRegionBasedINCLUDE
-
-#include "SemanticSegmentation.h"
-
-#include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
-#include "vislearning/classifier/classifierbase/VecClassifier.h"
-
-#include "objrec/segmentation/RegionSegmentationMethod.h"
-
-#include "vislearning/math/mathbase/Featuretype.h"
-#include "objrec/features/regionfeatures/RegionFeatures.h"
-#include "vislearning/features/localfeatures/LocalFeature.h"
-
-#include "vislearning/math/ftransform/PCA.h"
-
-#include "semseg/semseg/postsegmentation/PPGraphCut.h"
-
-namespace OBJREC
-{
-class SemSegRegionBased : public SemanticSegmentation
-{
-  protected:
-
-    //! destination for saving intermediate steps
-    bool save_cache, read_cache;
-    std::string cache;
-    std::string classifiercache;
-
-    //! used ClassNames
-    ClassNames cn;
-
-    //! Classifier
-    VecClassifier *vclassifier;
-    FeaturePoolClassifier *fpc;
-
-    //! Configuration File
-    const NICE::Config *conf;
-
-    //! Segmentation Method
-    RegionSegmentationMethod *rsm;
-
-    //! using color Weijer features or not
-    RegionFeatures *rfc;
-
-    //! using HoGFeatures or not
-    RegionFeatures *rfhog;
-
-    //! using BoV or not
-    RegionFeatures *rfbov;
-
-    //! Moosmann Codebook (alternative BoV approach)
-    RegionFeatures *rfbovcrdf;
-
-    //! old method like used in Csurka
-    RegionFeatures *rfCsurka;
-
-    //! features for BoV
-    LocalFeature *siftFeats;
-
-    //! using structure feature
-    RegionFeatures *rfstruct;
-
-    //! MRF optimization
-    PPGraphCut *gcopt;
-
-  public:
-    /** constructor
-     *  @param conf needs a configfile
-     *  @param md and a MultiDataset (contains images and other things)
-     */
-    SemSegRegionBased ( const NICE::Config *c, const MultiDataset *md );
-
-    /** simple destructor */
-    virtual ~SemSegRegionBased();
-
-    /** The trainingstep
-     *  @param md and a MultiDataset (contains images and other things)
-     */
-    void train ( const MultiDataset *md );
-
-    /** The main procedure. Input: Image, Output: Segmented Image with pixelwise labeles and the probabilities
-     * @param ce image data
-     * @param segresult result of the semantic segmentation with a label for each pixel
-     * @param probabilities multi-channel image with one channel for each class and corresponding probabilities for each pixel
-     */
-    void semanticseg ( CachedExample *ce, NICE::Image & segresult,  NICE::MultiChannelImageT<double> & probabilities );
-    /**
-     * get all features for an Image and save them in Examples
-     * @param cimg input image
-     * @param mask region mask
-     * @param rg region graph
-     * @param feats output features
-     */
-    void getFeats ( const NICE::ColorImage &cimg, const NICE::Matrix &mask, const RegionGraph &rg, std::vector<std::vector< FeatureType> > &feats ) const;
-
-    /**
-     * computes or reads features and corresponding labels for learnHighLevel()
-     * @param perm input permutation
-     * @param feats output features
-     * @param label output label
-     * @param examples output examples (including label)
-     * @param mode mode 1 for examples, mode 0 for VVector
-     */
-    void computeLF ( LabeledSet::Permutation perm, NICE::VVector &feats, std::vector<int> &label, Examples &examples, int mode );
-
-    /**
-     * Computes HighLevel Codebooks (i.e. GMM or PCA) if necessary
-     * @param perm training examples
-     */
-    void learnHighLevel ( LabeledSet::Permutation perm );
-
-    /**
-     * trains the classifier
-     * @param feats features
-     */
-    void trainClassifier ( std::vector<std::vector<FeatureType> > &feats, Examples &examples );
-
-    /**
-     * Convert features into examples
-     * @param feats input features
-     * @param examples features as examples
-     */
-    void getExample ( const std::vector<std::vector<FeatureType> > &feats, Examples &examples );
-
-    /**
-     * create featurepool depending on used features
-     * @param feats input features
-     * @param fp feature pool
-     */
-    void getFeaturePool ( const std::vector<std::vector<FeatureType> > &feats, FeaturePool &fp );
-
-    /**
-     * classify the given features
-     * @param feats input features
-     * @param examples examples
-     * @param probs probability for each region
-     */
-    void classify ( const std::vector<std::vector<FeatureType> > &feats, Examples &examples, std::vector<std::vector<double> > &probs );
-
-    /**
-     * set the label of each region the to most probable class
-     * @param rg
-     * @param probs
-     */
-    void labelRegions ( RegionGraph &rg, std::vector<std::vector<double> > &probs );
-
-    /**
-     * set label of each pixel to label of corresponding region
-     * @param segresult result image
-     * @param mask region mask
-     * @param rg region graph
-     */
-    void labelImage ( NICE::Image &segresult, NICE::Matrix &mask,RegionGraph &rg );
-
-    /**
-     * get the label for each region from the groundtruth for learning step and save them in rg
-     * @param mask region mask
-     * @param rg region graph
-     * @param pixelLabels Groundtruth images
-     */
-    void getRegionLabel ( NICE::Matrix &mask, RegionGraph &rg, NICE::Image &pixelLabels );
-
-    /**
-     * train pca
-     * @param feats input features
-     * @param pca pca
-     * @param dim new dimension
-     * @param fn destination filename
-     */
-    void initializePCA ( const NICE::VVector &feats, PCA &pca, int dim, std::string &fn );
-
-    /**
-     * transform features using a given pca
-     * @param feats input and output features
-     * @param pca
-     */
-    void transformFeats ( NICE::VVector &feats, PCA &pca );
-
-};
-
-} // namespace
-
-#endif

+ 2 - 7
semseg/libdepend.inc

@@ -1,8 +1,3 @@
 $(call PKG_DEPEND_EXT,OPENMP)
 $(call PKG_DEPEND_EXT,OPENMP)
-$(call PKG_DEPEND_INT,objrec/iclassifier)
-$(call PKG_DEPEND_INT,objrec/segmentation)
-$(call PKG_DEPEND_INT,objrec/fourier)
-$(call PKG_DEPEND_INT,objrec/features)
-$(call PKG_DEPEND_INT,objrec/semanticsegmentation)
-$(call PKG_DEPEND_INT,gp-hik-exp)
-#$(call PKG_DEPEND_INT,semseg/classifier)
+$(call PKG_DEPEND_INT,segmentation)
+$(call PKG_DEPEND_INT,gp-hik-exp)

+ 142 - 142
semseg/postsegmentation/PPGraphCut.cpp

@@ -1,6 +1,6 @@
 #include "PPGraphCut.h"
 #include "PPGraphCut.h"
 
 
-#include "objrec/segmentation/RegionGraph.h"
+#include "segmentation/RegionGraph.h"
 
 
 using namespace std;
 using namespace std;
 using namespace NICE;
 using namespace NICE;
@@ -8,192 +8,192 @@ using namespace OBJREC;
 
 
 void PPGraphCut::setClassNo(int _classno)
 void PPGraphCut::setClassNo(int _classno)
 {
 {
-	classno = _classno;
+  classno = _classno;
 
 
-	coocurence = new double[classno*classno];
-	
-	for(int i = 0; i < classno*classno; i++)
-	{
-		coocurence[i] = 0.0;
-	}
+  coocurence = new double[classno*classno];
+
+  for (int i = 0; i < classno*classno; i++)
+  {
+    coocurence[i] = 0.0;
+  }
 
 
 }
 }
 
 
 PPGraphCut::PPGraphCut()
 PPGraphCut::PPGraphCut()
 {
 {
-	conf = new Config();
-	Init();
+  conf = new Config();
+  Init();
 }
 }
 
 
-PPGraphCut::PPGraphCut(const Config *_conf):conf(_conf)
+PPGraphCut::PPGraphCut(const Config *_conf): conf(_conf)
 {
 {
-	Init();
+  Init();
 }
 }
 
 
 void PPGraphCut::Init()
 void PPGraphCut::Init()
 {
 {
-	std::string section = "PostProcess";
+  std::string section = "PostProcess";
 }
 }
 
 
 PPGraphCut::~PPGraphCut()
 PPGraphCut::~PPGraphCut()
 {
 {
-	
+
 }
 }
 
 
 void PPGraphCut::optimizeImage(RegionGraph &regions, vector<vector<double> > & probabilities)
 void PPGraphCut::optimizeImage(RegionGraph &regions, vector<vector<double> > & probabilities)
 {
 {
-	vector<Node*> nodes;
-	regions.get(nodes);
-
-	GCoptimizationGeneralGraph graphcut(nodes.size(), classno);
-
-	graphcut.setSmoothCost(coocurence);
-	
-	map<pair<int,int>, int> pairs;
-	
-	for(int i = 0; i < (int) nodes.size(); i++)
-	{
-		vector<Node*> nbs;
-		nodes[i]->getNeighbors(nbs);
-		int pos1 = nodes[i]->getNumber();
-		for(int j = 0; j < (int)nbs.size(); j++)
-		{
-			int pos2 = nbs[j]->getNumber();
-			pair<int,int> p(std::min(pos1,pos2),std::max(pos1,pos2));
-			map<pair<int,int>, int>::iterator iter = pairs.find(p);
-			if(iter == pairs.end())
-			{
-				pairs.insert(make_pair(p,1));
-				graphcut.setNeighbors(pos1, pos2,1.0);
-			}
-		}
-		for(int l = 0; l < classno; l++)
-		{
-			double val = probabilities[i][l];
-			if(val <= 0.0)
-				val = 1e-10;
-			val = -log(val);
-			graphcut.setDataCost(pos1, l, val);
-		}
-		graphcut.setLabel(pos1, nodes[i]->getLabel());
-	}
-
-	graphcut.swap(20);
-
-	//MRF::EnergyVal E_smooth = graphcut->smoothnessEnergy();
-
-	//MRF::EnergyVal E_data   = graphcut->dataEnergy();
-
-	for (int i = 0; i < (int)nodes.size(); i++ )
-	{
-		regions[i]->setLabel(graphcut.whatLabel(i));
-	}
+  vector<Node*> nodes;
+  regions.get(nodes);
+
+  GCoptimizationGeneralGraph graphcut(nodes.size(), classno);
+
+  graphcut.setSmoothCost(coocurence);
+
+  map<pair<int, int>, int> pairs;
+
+  for (int i = 0; i < (int) nodes.size(); i++)
+  {
+    vector<Node*> nbs;
+    nodes[i]->getNeighbors(nbs);
+    int pos1 = nodes[i]->getNumber();
+    for (int j = 0; j < (int)nbs.size(); j++)
+    {
+      int pos2 = nbs[j]->getNumber();
+      pair<int, int> p(std::min(pos1, pos2), std::max(pos1, pos2));
+      map<pair<int, int>, int>::iterator iter = pairs.find(p);
+      if (iter == pairs.end())
+      {
+        pairs.insert(make_pair(p, 1));
+        graphcut.setNeighbors(pos1, pos2, 1.0);
+      }
+    }
+    for (int l = 0; l < classno; l++)
+    {
+      double val = probabilities[i][l];
+      if (val <= 0.0)
+        val = 1e-10;
+      val = -log(val);
+      graphcut.setDataCost(pos1, l, val);
+    }
+    graphcut.setLabel(pos1, nodes[i]->getLabel());
+  }
+
+  graphcut.swap(20);
+
+  //double E_smooth = graphcut->smoothnessEnergy();
+
+  //double E_data   = graphcut->dataEnergy();
+
+  for (int i = 0; i < (int)nodes.size(); i++ )
+  {
+    regions[i]->setLabel(graphcut.whatLabel(i));
+  }
 }
 }
 
 
 void PPGraphCut::optimizeImage(Examples &regions, NICE::Matrix &mask, NICE::MultiChannelImageT<double> & probabilities)
 void PPGraphCut::optimizeImage(Examples &regions, NICE::Matrix &mask, NICE::MultiChannelImageT<double> & probabilities)
 {
 {
-	RegionGraph g;
-	g.computeGraph(regions, mask);
-
-	vector<vector<double> > probs;
-	
-	for(int p = 0; p < (int)regions.size(); p++)
-	{
-		vector<double> pr;
-		for(int l = 0; l < classno; l++)
-		{
-			pr.push_back(probabilities.get(regions[p].second.x, regions[p].second.y, l));
-		}
-		probs.push_back(pr);
-	}
-
-	optimizeImage(g, probs);
+  RegionGraph g;
+  g.computeGraph(regions, mask);
+
+  vector<vector<double> > probs;
+
+  for (int p = 0; p < (int)regions.size(); p++)
+  {
+    vector<double> pr;
+    for (int l = 0; l < classno; l++)
+    {
+      pr.push_back(probabilities.get(regions[p].second.x, regions[p].second.y, l));
+    }
+    probs.push_back(pr);
+  }
+
+  optimizeImage(g, probs);
 }
 }
 
 
 void PPGraphCut::trainImage(RegionGraph &g)
 void PPGraphCut::trainImage(RegionGraph &g)
 {
 {
-	vector<Node*> nodes;
-	g.get(nodes);
-
-	for(int i = 0; i < (int) nodes.size(); i++)
-	{
-		vector<Node*> nbs;
-		nodes[i]->getNeighbors(nbs);
-		for(int j = 0; j < (int)nbs.size(); j++)
-		{
-			//if(nodes[i]->getLabel() != nbs[j]->getLabel())
-			coocurence[nodes[i]->getLabel()*classno+nbs[j]->getLabel()]+=1.0;
-		}
-	}
+  vector<Node*> nodes;
+  g.get(nodes);
+
+  for (int i = 0; i < (int) nodes.size(); i++)
+  {
+    vector<Node*> nbs;
+    nodes[i]->getNeighbors(nbs);
+    for (int j = 0; j < (int)nbs.size(); j++)
+    {
+      //if(nodes[i]->getLabel() != nbs[j]->getLabel())
+      coocurence[nodes[i]->getLabel()*classno + nbs[j]->getLabel()] += 1.0;
+    }
+  }
 }
 }
 
 
 void PPGraphCut::trainImage(Examples &regions, NICE::Matrix &mask)
 void PPGraphCut::trainImage(Examples &regions, NICE::Matrix &mask)
 {
 {
-	// coocurence Matrix bestimmen
-	RegionGraph g;
-	g.computeGraph(regions, mask);
-	trainImage(g);
+  // coocurence Matrix bestimmen
+  RegionGraph g;
+  g.computeGraph(regions, mask);
+  trainImage(g);
 }
 }
-		
+
 void PPGraphCut::finishPP(ClassNames &cn)
 void PPGraphCut::finishPP(ClassNames &cn)
 {
 {
-	for(int i = 0; i < classno; i++)
-	{
-		for(int j = 0; j < classno; j++)
-		{
-			cout << coocurence[classno*i+j] << " ";
-		}
-		cout << endl;
-	}
-	cout << endl;
-	
-	double weight = conf->gD( "PPGC", "weight", 0.01 );
-	double maxv =  -numeric_limits<double>::max();
-	for(int i = 0; i < classno; i++)
-	{
-		for(int j = 0; j < classno; j++)
-		{
-			if(j == i)
-				coocurence[classno*i+j] = 0.0;
-			else
-				maxv = std::max(maxv, coocurence[classno*i+j]);
-		}
-	}
-	
-	maxv+=1+1e-10;
-	
-	for(int i = 0; i < classno; i++)
-	{
-		for(int j = 0; j < classno; j++)
-		{
-			if(j == i)
-				coocurence[classno*i+j] = 0.0;
-			else
-				coocurence[classno*i+j] = -weight*(log(( coocurence[classno*i+j]+1.0)/maxv));
-		}
-	}
-	for(int i = 0; i < classno; i++)
-	{
-		for(int j = 0; j < classno; j++)
-		{
-			cout << coocurence[classno*i+j] << " ";
-		}
-		cout << endl;
-	}
-	//GetChar();
+  for (int i = 0; i < classno; i++)
+  {
+    for (int j = 0; j < classno; j++)
+    {
+      cout << coocurence[classno*i+j] << " ";
+    }
+    cout << endl;
+  }
+  cout << endl;
+
+  double weight = conf->gD( "PPGC", "weight", 0.01 );
+  double maxv =  -numeric_limits<double>::max();
+  for (int i = 0; i < classno; i++)
+  {
+    for (int j = 0; j < classno; j++)
+    {
+      if (j == i)
+        coocurence[classno*i+j] = 0.0;
+      else
+        maxv = std::max(maxv, coocurence[classno*i+j]);
+    }
+  }
+
+  maxv += 1 + 1e-10;
+
+  for (int i = 0; i < classno; i++)
+  {
+    for (int j = 0; j < classno; j++)
+    {
+      if (j == i)
+        coocurence[classno*i+j] = 0.0;
+      else
+        coocurence[classno*i+j] = -weight * (log(( coocurence[classno*i+j] + 1.0) / maxv));
+    }
+  }
+  for (int i = 0; i < classno; i++)
+  {
+    for (int j = 0; j < classno; j++)
+    {
+      cout << coocurence[classno*i+j] << " ";
+    }
+    cout << endl;
+  }
+  //GetChar();
 }
 }
 
 
 void PPGraphCut::restore (istream & is, int format)
 void PPGraphCut::restore (istream & is, int format)
 {
 {
-	
+
 }
 }
-		
+
 void PPGraphCut::store (ostream & os, int format) const
 void PPGraphCut::store (ostream & os, int format) const
 {
 {
-	
+
 }
 }
 
 
 void PPGraphCut::clear()
 void PPGraphCut::clear()
 {
 {
-	
+
 }
 }

+ 2 - 2
semseg/postsegmentation/PPGraphCut.h

@@ -20,9 +20,9 @@
 
 
 #include "vislearning/cbaselib/ClassNames.h"
 #include "vislearning/cbaselib/ClassNames.h"
 
 
-#include "objrec/segmentation/RSMeanShift.h"
+#include "segmentation/RSMeanShift.h"
 
 
-#include "objrec/mrf/mrfmin/GCoptimization.h"
+#include "vislearning/mrf/mrfmin/GCoptimization.h"
 
 
 
 
 namespace OBJREC
 namespace OBJREC

+ 227 - 227
semseg/postsegmentation/PPSuperregion.cpp

@@ -4,7 +4,7 @@
 #include <core/iceconversion/convertice.h>
 #include <core/iceconversion/convertice.h>
 #endif
 #endif
 
 
-#include "objrec/segmentation/RegionGraph.h"
+#include "segmentation/RegionGraph.h"
 
 
 using namespace std;
 using namespace std;
 using namespace NICE;
 using namespace NICE;
@@ -12,19 +12,19 @@ using namespace OBJREC;
 
 
 PPSuperregion::PPSuperregion()
 PPSuperregion::PPSuperregion()
 {
 {
-	conf = new Config();
-	Init();
+  conf = new Config();
+  Init();
 }
 }
 
 
-PPSuperregion::PPSuperregion(const Config *_conf):conf(_conf)
+PPSuperregion::PPSuperregion(const Config *_conf): conf(_conf)
 {
 {
-	Init();
+  Init();
 }
 }
 
 
 void PPSuperregion::Init()
 void PPSuperregion::Init()
 {
 {
-	std::string section = "PostProcessSG";
-	rf = new FPCRandomForests( conf, "ShapeRF" );
+  std::string section = "PostProcessSG";
+  rf = new FPCRandomForests( conf, "ShapeRF" );
 }
 }
 
 
 PPSuperregion::~PPSuperregion()
 PPSuperregion::~PPSuperregion()
@@ -35,252 +35,252 @@ PPSuperregion::~PPSuperregion()
 void PPSuperregion::optimizeShape(Examples &regions, NICE::Matrix &mask, NICE::MultiChannelImageT<double> & probabilities)
 void PPSuperregion::optimizeShape(Examples &regions, NICE::Matrix &mask, NICE::MultiChannelImageT<double> & probabilities)
 {
 {
 #ifdef NICE_USELIB_ICE
 #ifdef NICE_USELIB_ICE
-	vector<ice::Region> superregions;
-	vector<double> probs;
-	vector<int> classes;
-	NICE::Matrix smask;
-	getSuperregions(regions, mask, superregions, classes, smask);
-	
-	for(int i = 0; i < (int)superregions.size(); i++)
-	{
-		ice::Moments m;
-		superregions[i].CalcMoments(m);
-
-		NICE::Vector tmp = makeEVector(m.AffineHuInvariants());
-		NICE::Vector *tmp2 = new NICE::Vector(tmp);
-		Example tex(tmp2);		
-		
-		ClassificationResult r = rf->classify ( tex );
-
-		probs.push_back(r.scores[classes[i]]);
-	}
-
-	vector<ice::Region> orgregions;
-	for(int i = 0; i < (int)regions.size(); i++)
-	{
-		orgregions.push_back(ice::Region());
-	}
-	
-	for(int y = 0; y < (int)mask.cols(); y++)
-	{
-		for(int x = 0; x < (int)mask.rows(); x++)
-		{
-			int pos = mask(x,y);
-			orgregions[pos].Add(x,y);
-		}
-	}
-
-	// maps the regions to their superregions
-	vector<int> regmapsreg(regions.size(), 0);
-	for(int y = 0; y < (int)smask.cols(); y++)
-	{
-		for(int x = 0; x < (int)smask.rows(); x++)
-		{
-			int r = mask(x,y);
-			int sr = smask(x,y);
-			regmapsreg[r] = sr;
-		}
-	}
-	
-	RegionGraph g;
-	g.computeGraph(regions, mask);
-	
-	vector<Node*> nodes;
-	g.get(nodes);
-
-	bool change = true;
-	int k = 0;
-	while(change && k < 100)
-	{
-		k++;
-		change = false;
-		int anders = 0;
-		for(int i = 0; i < (int) nodes.size(); i++)
-		{
-
-			set<int> sr;
-			int regnb = nodes[i]->getRegion();
-			int orgreg = regmapsreg[regnb];
-
-			if(nodes[i]->isAtBorder())
-			{
-				vector<Node*> nbs;
-				nodes[i]->getNeighbors(nbs);
-				for(int j = 0; j < (int)nbs.size(); j++)
-					sr.insert(regmapsreg[nbs[j]->getRegion()]);
-			}
-	
-			vector<double> otherprobs;
-
-			ice::Region re = superregions[orgreg];
-			re.Del(orgregions[regnb]);
-
-			ice::Moments m;
-
-			if(re.Area() > 0)
-			{
-				re.CalcMoments(m);
-
-				NICE::Vector tmp = makeEVector( m.AffineHuInvariants());
-				NICE::Vector *tmp2 = new NICE::Vector(tmp);
-				Example tex(tmp2);
-				ClassificationResult r = rf->classify ( tex );
-				tex.vec = NULL;
-				delete tmp2;
-				
-				double val = probabilities.get(regions[regnb].second.x, regions[regnb].second.y, classes[orgreg]) * r.scores[classes[orgreg]];
-				
-				otherprobs.push_back(val);
-				if(otherprobs[0] < probs[orgreg])
-					continue;
-			}
-			
-			for( set<int>::const_iterator iter = sr.begin();iter != sr.end();++iter )
-			{
-				ice::Moments m2;
-				ice::Region re2 = superregions[regmapsreg[*iter]];
-				re2.Add(orgregions[regnb]);
-				re2.CalcMoments(m2);
-				NICE::Vector tmp = makeEVector(m2.AffineHuInvariants());
-				NICE::Vector *tmp2 = new NICE::Vector(tmp);
-				Example tex(tmp2);
-				ClassificationResult r2 = rf->classify ( tex );
-				tex.vec = NULL;
-				delete tmp2;
-				
-				double val = probabilities.get(regions[regnb].second.x, regions[regnb].second.y, classes[*iter]) * r2.scores[classes[*iter]];
-				
-				otherprobs.push_back(val);
-			}
-
-			int k = 1;
-			int best = -1;
-			double bestval = -1.0;
-			for( set<int>::const_iterator iter = sr.begin();iter != sr.end();++iter, k++ ) 
-			{
-				if(otherprobs[k] > probs[*iter])
-				{
-					if(bestval < otherprobs[k])
-					{
-						bestval = otherprobs[k];
-						best = *iter;
-					}
-				}
-			}
-			
-			if(best < 0 || bestval <= 0.0)
-				continue;
-			
-			change = true;
-
-			probs[best] = bestval;
-
-			superregions[best].Add(orgregions[regnb]);
-
-			probs[orgreg] = otherprobs[0];
-
-			superregions[orgreg].Del(orgregions[regnb]);
-
-			regmapsreg[regnb] = best;
-
-			nodes[i]->setLabel(classes[best]);
-			anders++;
-		}
-	}
-	
-	for(int i = 0; i < (int)regions.size(); i++)
-	{
-		regions[i].first = classes[regmapsreg[i]];
-	}
+  vector<ice::Region> superregions;
+  vector<double> probs;
+  vector<int> classes;
+  NICE::Matrix smask;
+  getSuperregions(regions, mask, superregions, classes, smask);
+
+  for (int i = 0; i < (int)superregions.size(); i++)
+  {
+    ice::Moments m;
+    superregions[i].CalcMoments(m);
+
+    NICE::Vector tmp = makeEVector(m.AffineHuInvariants());
+    NICE::Vector *tmp2 = new NICE::Vector(tmp);
+    Example tex(tmp2);
+
+    ClassificationResult r = rf->classify ( tex );
+
+    probs.push_back(r.scores[classes[i]]);
+  }
+
+  vector<ice::Region> orgregions;
+  for (int i = 0; i < (int)regions.size(); i++)
+  {
+    orgregions.push_back(ice::Region());
+  }
+
+  for (int y = 0; y < (int)mask.cols(); y++)
+  {
+    for (int x = 0; x < (int)mask.rows(); x++)
+    {
+      int pos = mask(x, y);
+      orgregions[pos].Add(x, y);
+    }
+  }
+
+  // maps the regions to their superregions
+  vector<int> regmapsreg(regions.size(), 0);
+  for (int y = 0; y < (int)smask.cols(); y++)
+  {
+    for (int x = 0; x < (int)smask.rows(); x++)
+    {
+      int r = mask(x, y);
+      int sr = smask(x, y);
+      regmapsreg[r] = sr;
+    }
+  }
+
+  RegionGraph g;
+  g.computeGraph(regions, mask);
+
+  vector<Node*> nodes;
+  g.get(nodes);
+
+  bool change = true;
+  int k = 0;
+  while (change && k < 100)
+  {
+    k++;
+    change = false;
+    int anders = 0;
+    for (int i = 0; i < (int) nodes.size(); i++)
+    {
+
+      set<int> sr;
+      int regnb = nodes[i]->getRegion();
+      int orgreg = regmapsreg[regnb];
+
+      if (nodes[i]->isAtBorder())
+      {
+        vector<Node*> nbs;
+        nodes[i]->getNeighbors(nbs);
+        for (int j = 0; j < (int)nbs.size(); j++)
+          sr.insert(regmapsreg[nbs[j]->getRegion()]);
+      }
+
+      vector<double> otherprobs;
+
+      ice::Region re = superregions[orgreg];
+      re.Del(orgregions[regnb]);
+
+      ice::Moments m;
+
+      if (re.Area() > 0)
+      {
+        re.CalcMoments(m);
+
+        NICE::Vector tmp = makeEVector( m.AffineHuInvariants());
+        NICE::Vector *tmp2 = new NICE::Vector(tmp);
+        Example tex(tmp2);
+        ClassificationResult r = rf->classify ( tex );
+        tex.vec = NULL;
+        delete tmp2;
+
+        double val = probabilities.get(regions[regnb].second.x, regions[regnb].second.y, classes[orgreg]) * r.scores[classes[orgreg]];
+
+        otherprobs.push_back(val);
+        if (otherprobs[0] < probs[orgreg])
+          continue;
+      }
+
+      for ( set<int>::const_iterator iter = sr.begin();iter != sr.end();++iter )
+      {
+        ice::Moments m2;
+        ice::Region re2 = superregions[regmapsreg[*iter]];
+        re2.Add(orgregions[regnb]);
+        re2.CalcMoments(m2);
+        NICE::Vector tmp = makeEVector(m2.AffineHuInvariants());
+        NICE::Vector *tmp2 = new NICE::Vector(tmp);
+        Example tex(tmp2);
+        ClassificationResult r2 = rf->classify ( tex );
+        tex.vec = NULL;
+        delete tmp2;
+
+        double val = probabilities.get(regions[regnb].second.x, regions[regnb].second.y, classes[*iter]) * r2.scores[classes[*iter]];
+
+        otherprobs.push_back(val);
+      }
+
+      int k = 1;
+      int best = -1;
+      double bestval = -1.0;
+      for ( set<int>::const_iterator iter = sr.begin();iter != sr.end();++iter, k++ )
+      {
+        if (otherprobs[k] > probs[*iter])
+        {
+          if (bestval < otherprobs[k])
+          {
+            bestval = otherprobs[k];
+            best = *iter;
+          }
+        }
+      }
+
+      if (best < 0 || bestval <= 0.0)
+        continue;
+
+      change = true;
+
+      probs[best] = bestval;
+
+      superregions[best].Add(orgregions[regnb]);
+
+      probs[orgreg] = otherprobs[0];
+
+      superregions[orgreg].Del(orgregions[regnb]);
+
+      regmapsreg[regnb] = best;
+
+      nodes[i]->setLabel(classes[best]);
+      anders++;
+    }
+  }
+
+  for (int i = 0; i < (int)regions.size(); i++)
+  {
+    regions[i].first = classes[regmapsreg[i]];
+  }
 #else
 #else
-	throw("PPSuperRegion.cpp: please use ice library for this function");
+  throw("PPSuperRegion.cpp: please use ice library for this function");
 #endif
 #endif
 }
 }
 #ifdef NICE_USELIB_ICE
 #ifdef NICE_USELIB_ICE
 void PPSuperregion::getSuperregions(const Examples &regions, const NICE::Matrix &mask, vector<ice::Region> &superregions, vector<int> &classes, NICE::Matrix &smask)
 void PPSuperregion::getSuperregions(const Examples &regions, const NICE::Matrix &mask, vector<ice::Region> &superregions, vector<int> &classes, NICE::Matrix &smask)
 {
 {
-	NICE::Image tmp (mask.rows(), mask.cols());
-	tmp.set(0);
-	NICE::ColorImage m2 (tmp, tmp, tmp);
-	for(int y = 0; y < (int)mask.cols(); y++)
-	{
-		for(int x = 0; x < (int)mask.rows(); x++)
-		{
-			int pos = mask(x,y);
-
-			m2.setPixel(x,y,0,regions[pos].first);
-			m2.setPixel(x,y,1,regions[pos].first);
-			m2.setPixel(x,y,2,regions[pos].first);
-		}
-	}
-
-	RSMeanShift rs(conf);
-	int count = rs.transformSegmentedImg( m2, smask);
-	
-	classes.resize(count);
-	for(int i = 0; i < count; i++)
-	{
-		superregions.push_back(ice::Region());
-	}
-	
-	for(int y = 0; y < (int)smask.cols(); y++)
-	{
-		for(int x = 0; x < (int)smask.rows(); x++)
-		{
-			int pos = smask(x,y);
-			superregions[pos].Add(x,y);
-			classes[pos] = regions[mask(x,y)].first;
-		}
-	}
+  NICE::Image tmp (mask.rows(), mask.cols());
+  tmp.set(0);
+  NICE::ColorImage m2 (tmp, tmp, tmp);
+  for (int y = 0; y < (int)mask.cols(); y++)
+  {
+    for (int x = 0; x < (int)mask.rows(); x++)
+    {
+      int pos = mask(x, y);
+
+      m2.setPixel(x, y, 0, regions[pos].first);
+      m2.setPixel(x, y, 1, regions[pos].first);
+      m2.setPixel(x, y, 2, regions[pos].first);
+    }
+  }
+
+  RSMeanShift rs(conf);
+  int count = rs.transformSegmentedImg( m2, smask);
+
+  classes.resize(count);
+  for (int i = 0; i < count; i++)
+  {
+    superregions.push_back(ice::Region());
+  }
+
+  for (int y = 0; y < (int)smask.cols(); y++)
+  {
+    for (int x = 0; x < (int)smask.rows(); x++)
+    {
+      int pos = smask(x, y);
+      superregions[pos].Add(x, y);
+      classes[pos] = regions[mask(x,y)].first;
+    }
+  }
 }
 }
 #endif
 #endif
 
 
 void PPSuperregion::trainShape(Examples &regions, NICE::Matrix &mask)
 void PPSuperregion::trainShape(Examples &regions, NICE::Matrix &mask)
 {
 {
 #ifdef NICE_USELIB_ICE
 #ifdef NICE_USELIB_ICE
-	// bestimme Superregionen
-	vector<ice::Region> superregions;
-	vector<int> classes;
-	// refactor-nice.pl: check this substitution
-	// old: Image smask;
-	NICE::Matrix smask;
-	getSuperregions(regions, mask, superregions, classes, smask);
-	
-	// berechne die Momente der Superregionen und speichere diese als Merkmale ab
-	for(int i = 0; i < (int)superregions.size(); i++)
-	{
-		ice::Moments m;
-		superregions[i].CalcMoments(m);
-		NICE::Vector tmp = makeEVector(m.AffineHuInvariants());
-		NICE::Vector *tmp2 = new NICE::Vector(tmp);
-		shapefeats.push_back(pair<int, Example>(classes[i], Example(tmp2)));
-	}
+  // bestimme Superregionen
+  vector<ice::Region> superregions;
+  vector<int> classes;
+  // refactor-nice.pl: check this substitution
+  // old: Image smask;
+  NICE::Matrix smask;
+  getSuperregions(regions, mask, superregions, classes, smask);
+
+  // berechne die Momente der Superregionen und speichere diese als Merkmale ab
+  for (int i = 0; i < (int)superregions.size(); i++)
+  {
+    ice::Moments m;
+    superregions[i].CalcMoments(m);
+    NICE::Vector tmp = makeEVector(m.AffineHuInvariants());
+    NICE::Vector *tmp2 = new NICE::Vector(tmp);
+    shapefeats.push_back(pair<int, Example>(classes[i], Example(tmp2)));
+  }
 #else
 #else
-	throw("PPSuperRegion.cpp: please use ice library for this function");
+  throw("PPSuperRegion.cpp: please use ice library for this function");
 #endif
 #endif
 }
 }
-		
+
 void PPSuperregion::finishShape(ClassNames &cn)
 void PPSuperregion::finishShape(ClassNames &cn)
 {
 {
-	//Lerne Klassifikator mit dem den Formmerkmalen an
-	FeaturePool fp;
-	Feature *f = new VectorFeature ( 7 );
-	f->explode ( fp );
-	delete f;
-	rf->train ( fp, shapefeats);
+  //Lerne Klassifikator mit dem den Formmerkmalen an
+  FeaturePool fp;
+  Feature *f = new VectorFeature ( 7 );
+  f->explode ( fp );
+  delete f;
+  rf->train ( fp, shapefeats);
 }
 }
 
 
 void PPSuperregion::restore (istream & is, int format)
 void PPSuperregion::restore (istream & is, int format)
 {
 {
-	
+
 }
 }
-		
+
 void PPSuperregion::store (ostream & os, int format) const
 void PPSuperregion::store (ostream & os, int format) const
 {
 {
-	
+
 }
 }
 
 
 void PPSuperregion::clear()
 void PPSuperregion::clear()
 {
 {
-	
+
 }
 }

+ 1 - 1
semseg/postsegmentation/PPSuperregion.h

@@ -21,7 +21,7 @@
 
 
 #include "vislearning/cbaselib/ClassNames.h"
 #include "vislearning/cbaselib/ClassNames.h"
 
 
-#include "objrec/segmentation/RSMeanShift.h"
+#include "segmentation/RSMeanShift.h"
 
 
 #ifdef NICE_USELIB_ICE
 #ifdef NICE_USELIB_ICE
 #include <image_nonvis.h>
 #include <image_nonvis.h>

+ 2 - 3
semseg/postsegmentation/libdepend.inc

@@ -1,4 +1,3 @@
 $(call PKG_DEPEND_EXT,ICE)
 $(call PKG_DEPEND_EXT,ICE)
-$(call PKG_DEPEND_INT,objrec/cbaselib)
-$(call PKG_DEPEND_INT,objrec/mrf)
-$(call PKG_DEPEND_INT,core)
+$(call PKG_DEPEND_INT,core)
+$(call PKG_DEPEND_INT,vislearning/mrf)