Browse Source

class MCI3DT + SemSegContextTree for 3D data + new Operations

Sven Sickert 12 years ago
parent
commit
66c5350cb1
44 changed files with 2179 additions and 8136 deletions
  1. 0 92
      classifier/FPCnone.cpp
  2. 0 81
      classifier/FPCnone.h
  3. 0 103
      classifier/Makefile.inc
  4. 0 1
      classifier/libdepend.inc
  5. 34 0
      image/MultiChannelImage3DT.cpp
  6. 158 0
      image/MultiChannelImage3DT.h
  7. 706 0
      image/MultiChannelImage3DT.tcc
  8. 35 0
      image/MultiChannelImageAccess3D.h
  9. 2 2
      libdepend.inc
  10. 0 98
      progs/classtest.cpp
  11. 0 123
      progs/getRelevantClasses.cpp
  12. 0 333
      progs/testClassifier.cpp
  13. 0 346
      progs/testClassifierGMM.cpp
  14. 0 29
      progs/testNICE.cpp
  15. 0 51
      progs/testRF.cpp
  16. 154 126
      progs/testSemanticSegmentation.cpp
  17. 537 340
      semseg/SemSegContextTree.cpp
  18. 17 12
      semseg/SemSegContextTree.h
  19. 0 2016
      semseg/SemSegCsurka.cpp
  20. 0 250
      semseg/SemSegCsurka.h
  21. 0 108
      semseg/SemSegLocal.cpp
  22. 0 48
      semseg/SemSegLocal.h
  23. 0 355
      semseg/SemSegNovelty.cpp
  24. 0 89
      semseg/SemSegNovelty.h
  25. 0 1440
      semseg/SemSegRegionBased.cpp
  26. 0 190
      semseg/SemSegRegionBased.h
  27. 70 18
      semseg/SemanticSegmentation.cpp
  28. 20 9
      semseg/SemanticSegmentation.h
  29. 1 2
      semseg/libdepend.inc
  30. 133 56
      semseg/operations/Operations.cpp
  31. 312 44
      semseg/operations/Operations.h
  32. 0 8
      semseg/postsegmentation/Makefile
  33. 0 103
      semseg/postsegmentation/Makefile.inc
  34. 0 199
      semseg/postsegmentation/PPGraphCut.cpp
  35. 0 126
      semseg/postsegmentation/PPGraphCut.h
  36. 0 286
      semseg/postsegmentation/PPSuperregion.cpp
  37. 0 121
      semseg/postsegmentation/PPSuperregion.h
  38. 0 115
      semseg/postsegmentation/PSSImageLevelPrior.cpp
  39. 0 51
      semseg/postsegmentation/PSSImageLevelPrior.h
  40. 0 27
      semseg/postsegmentation/PostSemSeg.cpp
  41. 0 38
      semseg/postsegmentation/PostSemSeg.h
  42. 0 561
      semseg/postsegmentation/RelativeLocationPrior.cpp
  43. 0 135
      semseg/postsegmentation/RelativeLocationPrior.h
  44. 0 4
      semseg/postsegmentation/libdepend.inc

+ 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)

+ 34 - 0
image/MultiChannelImage3DT.cpp

@@ -0,0 +1,34 @@
+#include "core/image/MultiChannelImage3DT.h"
+
+using namespace NICE;
+
+#define SET_FUNCS_MACRO(MYTYPE) \
+  template <> \
+  int MultiChannelImage3DT<MYTYPE>::getPixelInt(int x, int y, int channel) const \
+  { \
+    return (int)get(x,y,channel); \
+  } \
+  \
+  template<>\
+  double MultiChannelImage3DT<MYTYPE>::getPixelFloat(int x, int y, int channel) const\
+  {\
+    return (double)get(x,y,channel);\
+  }\
+  template<>\
+  void MultiChannelImage3DT<MYTYPE>::setPixelInt(int x, int y, int channel, int pixel)\
+  {\
+    set(x,y,(MYTYPE)pixel,channel);\
+  }\
+  \
+  template<>\
+  void MultiChannelImage3DT<MYTYPE>::setPixelFloat(int x, int y, int channel, double pixel)\
+  {\
+    set(x,y,(MYTYPE)pixel,channel);\
+  }
+
+SET_FUNCS_MACRO ( int )
+SET_FUNCS_MACRO ( long int )
+SET_FUNCS_MACRO ( double )
+SET_FUNCS_MACRO ( float )
+SET_FUNCS_MACRO ( unsigned int )
+

+ 158 - 0
image/MultiChannelImage3DT.h

@@ -0,0 +1,158 @@
+#ifndef _NICE_CORE_MULTICHANNELIMAGE3DT_H
+#define _NICE_CORE_MULTICHANNELIMAGE3DT_H
+
+#include <semseg3d/image/MultiChannelImageAccess3D.h>
+#include <core/image/ImageT.h>
+#include <core/image/MultiChannelImageT.h>
+
+#include <fstream>
+
+namespace NICE {
+
+/**
+ * @class MultiChannelImage3DT
+ * A 3d image (arbitrary number of cross section images) consisting of an arbitrary number of channels.
+ *
+ * formaly known as Generic Image
+ *
+ * @author Erik Rodner and Björn Fröhlich and Sven Sickert
+ * @example notyet
+ */
+
+template <class P>
+class MultiChannelImage3DT : public MultiChannelImageAccess3D {
+protected:
+  typedef P Value;
+  typedef unsigned int uint;
+
+  /** image data, use carefully !!! data[channel][pixel_offset] */
+  P **data;
+  
+  /** image width */
+  int xsize;
+  
+  /** image height */
+  int ysize;
+
+  /** image depth */
+  int zsize;
+  
+  /** number of image channels */
+  uint numChannels;
+  
+public:
+
+  virtual inline int width() const;
+  virtual inline int height() const;
+  virtual inline int depth() const;
+
+  virtual inline int channels() const;
+
+  virtual int getPixelInt( int x, int y, int z, int channel ) const;
+
+  virtual double getPixelFloat( int x, int y, int z, int channel ) const;
+
+  virtual void setPixelInt( int x, int y, int z, int channel, int pixel );
+
+  virtual void setPixelFloat( int x, int y, int z, int channel, double pixel );
+
+  /** simple constructor */
+  MultiChannelImage3DT( int xsize, int ysize, int zsize, uint numChannels = 1);
+
+  /** very simple constructor */
+  MultiChannelImage3DT();
+
+  /** copy constructor */
+  MultiChannelImage3DT( const MultiChannelImage3DT<P>& p );
+
+  /** simple destructor */
+  virtual ~MultiChannelImage3DT();
+
+  /** free all memory */
+  void freeData();
+
+  /** reinit */
+  void reInit( int xsize, int ysize, int zsize, int numChannels = 1);
+
+  /** reinit data structure using the same dimensions and
+   number of channels as another image */
+  template<class SrcP>
+  void reInitFrom( const MultiChannelImage3DT<SrcP> & src);
+
+  void addChannel( int newChans = 1 );
+
+  /** add a channel to Multichannel Image */
+  template<class SrcP>
+  void addChannel( NICE::MultiChannelImageT<SrcP> &newImg );
+  
+  template<class SrcP>
+  void addChannel(const NICE::MultiChannelImage3DT<SrcP> &newImg);
+  
+  /** get value */
+  P get( int x, int y, int z, uint channel = 0 ) const;
+  
+  /** get data pointer */
+  P** getDataPointer();
+
+  /** set value */
+  void set( int x, int y, int z, P val, uint channel = 0 );
+
+  /** set value */
+  void set( P val, uint channel = 0 );
+
+  /** set value */
+  void setAll( P val );
+
+  /** calc integral image */
+  void calcIntegral( uint channel = 0 );
+  
+  /**
+   * @brief calculate the integral value in the volume given by upper left front corner and lower right back corner, including out of boundary check
+   * @warning make sure that the given channel is an integral 3d image
+   * @param ulfx upper left front x coordinate
+   * @param ulfy upper left front y coordinate
+   * @param ulfz upper left front z coordinate
+   * @param lrbx lower right back x coordinate
+   * @param lrby lower right back y coordinate
+   * @param lrbz lower right back z coordinate
+   * @param channel channel
+   * @return P mean value of given volume
+   **/
+  P getIntegralValue(int ulfx, int ulfy, int ulfz, int lrbx, int lrby, int lrbz, int channel);
+
+  /** convert to ice image */
+  void convertToGrey( NICE::Image & img, int z, uint channel = 0, bool normalize = true ) const;
+
+  /** convert to ice colorimage */
+  void convertToColor( NICE::ColorImage & img, int z, const int chan1 = 0, const int chan2 = 1, const int chan3 = 2 ) const;
+
+  /** return image for visualization */
+  Image getChannel( int z, uint channel = 0 ) const;
+
+  /** return rgb image for visualization */
+  ColorImage getColor(int z) const;
+
+  /** calculate image statistics */
+  void statistics( P & min, P & max, uint channel = 0 ) const;
+
+  /** dump all data to RAW format: xsize, ysize, numChannels, <data> */
+  void store( std::string filename ) const;
+
+  /** read all data from RAW format: xsize, ysize, numChannels, <data> */
+  void restore( std::string filename );
+
+  /** copy alls data to new object */
+  MultiChannelImage3DT<P>& operator=( const MultiChannelImage3DT<P>& orig );
+  
+  /** element operator */
+  P & operator() (int x, int y, int z, uint channel = 0);
+  
+  /** element operator */
+  MultiChannelImageT<P> operator[] (uint c);
+};
+
+} // namespace
+
+#include <semseg3d/image/MultiChannelImage3DT.tcc>
+
+#endif

+ 706 - 0
image/MultiChannelImage3DT.tcc

@@ -0,0 +1,706 @@
+#include <iostream>
+#include <assert.h>
+#include <stdio.h>
+
+namespace NICE {
+template<class P>
+MultiChannelImage3DT<P>::MultiChannelImage3DT( int _xsize, int _ysize, int _zsize, uint _numChannels)
+{
+  data = NULL;
+  numChannels = 0;
+  xsize = 0;
+  ysize = 0;
+  zsize = 0;
+  reInit( _xsize, _ysize, _zsize, _numChannels);
+}
+
+template<class P>
+MultiChannelImage3DT<P>::MultiChannelImage3DT()
+{
+  xsize = 0;
+  ysize = 0;
+  zsize = 0;
+  numChannels = 0;
+  data = NULL;
+}
+
+template<class P>
+P & MultiChannelImage3DT<P>::operator() (int x, int y, int z, uint channel)
+{
+  assert( channel < numChannels );
+  assert(( x < xsize ) && ( x >= 0 ) );
+  assert(( y < ysize ) && ( y >= 0 ) );
+  assert(( z < zsize ) && ( z >= 0 ) );
+  assert( data[channel] != NULL );
+  return data[channel][x + y*xsize + z*xsize*ysize];
+}
+
+template<class P>
+MultiChannelImageT<P> MultiChannelImage3DT<P>::operator[] (uint c)
+{
+  // This was our first idea ... but it creates a real copy
+  // ImageT<P> tmp ( data[c], xsize, ysize, xsize*sizeof(P), GrayColorImageCommonImplementation::noAlignment );
+  // This is the correct version. The funny thing about this is that shallowCopy
+  // is not an enum parameter, but an instance of ShallowCopyMode, which is a class.
+  // This fancy trick was done in older to prevent automatic conversion between enum types
+  // as done implicitly by C++.
+  
+  MultiChannelImageT<P> img;
+  for( int z = 0; z < zsize; z++ )
+  {
+    P * datatmp = data[c];
+    ImageT<P> tmp ( &datatmp[z*(xsize*ysize)], xsize, ysize, xsize*sizeof(P), GrayColorImageCommonImplementation::shallowCopy );
+    img.addChannel(tmp);
+  }
+  return img;
+}
+
+template<class P>
+MultiChannelImage3DT<P>& MultiChannelImage3DT<P>::operator=(const MultiChannelImage3DT<P>& orig) 
+{
+  if(!(xsize == orig.xsize && ysize == orig.ysize && zsize == orig.zsize && numChannels == orig.numChannels))
+  {
+    freeData();
+    xsize = orig.xsize;
+    ysize = orig.ysize;
+    zsize = orig.zsize;
+    numChannels = orig.numChannels;
+    if(orig.data != NULL)
+    {
+      data = new P *[numChannels];
+      for ( int c = 0; c < ( int )numChannels; c++ )
+      {
+        if ( orig.data[c] == NULL )
+        {
+          data[c] = NULL;
+        }
+        else
+        {
+          data[c] = new P [xsize*ysize*zsize];
+        }
+      }
+    }
+    else
+      data = NULL;
+  }
+
+  for ( int c = 0; c < ( int )numChannels; c++ )
+  {
+    if ( orig.data[c] != NULL )
+    {
+      for ( int x = 0; x < xsize*ysize*zsize; x++ )
+      {
+        data[c][x] = orig.data[c][x];
+      }
+    }
+  }
+  
+  return *this;
+}
+
+template<class P>
+MultiChannelImage3DT<P>::MultiChannelImage3DT( const MultiChannelImage3DT<P>& p )
+{
+  data = NULL;
+  xsize = p.xsize;
+  ysize = p.ysize;
+  zsize = p.zsize;
+  numChannels = p.numChannels;
+   
+  if(p.data != NULL)
+    data = new P *[numChannels];
+  else
+    data = NULL;
+
+  for ( int c = 0; c < ( int )numChannels; c++ )
+  {
+    if ( p.data[c] == NULL )
+    {
+      data[c] = NULL;
+    }
+    else
+    {
+      data[c] = new P [xsize*ysize*zsize];
+      for ( int x = 0; x < xsize*ysize*zsize; x++ )
+      {
+        data[c][x] = p.data[c][x];
+      }
+    }
+  }
+}
+
+
+template<class P>
+void MultiChannelImage3DT<P>::addChannel( int newChans )
+{
+  P **tmpData = new P *[numChannels+newChans];
+
+  bool allocMem = false;
+  int i = 0;
+
+  for ( ; i < (int)numChannels; i++ )
+  {
+    tmpData[i] = data[i];
+
+    if ( data[i] != NULL )
+      allocMem = true;
+  }
+
+  if ( allocMem )
+  {
+    for ( ; i < newChans + (int)numChannels; i++ )
+    {
+      tmpData[i] = new P [xsize*ysize*zsize];
+    }
+  }
+
+  numChannels += newChans;
+
+  delete [] data;
+
+  data = new P *[numChannels];
+
+  for ( i = 0; i < (int)numChannels; i++ )
+  {
+    data[i] = tmpData[i];
+  }
+
+  delete [] tmpData;
+}
+
+template<class P>
+template<class SrcP>
+void MultiChannelImage3DT<P>::addChannel(NICE::MultiChannelImageT<SrcP> &newMCImg)
+{
+  int oldchan = numChannels;
+  if(this->xsize > 0)
+  {
+    assert(newMCImg.width() == this->width() && newMCImg.height() == this->height());
+    assert(newMCImg.channels() == this->zsize);
+    addChannel(1);
+  }
+  else
+  {
+    reInit( newMCImg.width(), newMCImg.height(), newMCImg.channels(), 1 );
+  }
+  
+  for(int z = 0; z < this->zsize; z++)
+  {
+    NICE::ImageT<SrcP> newImg = newMCImg[z];
+    for(int y = 0; y < this->ysize; y++)
+    {
+      for(int x = 0; x < this->xsize; x++)
+      {
+        data[oldchan][x + y*xsize + z*xsize*ysize] = (P)newImg(x,y);
+      }
+    }
+  }
+}
+
+template<class P>
+template<class SrcP>
+void MultiChannelImage3DT<P>::addChannel(const NICE::MultiChannelImage3DT<SrcP> &newImg)
+{
+  int oldchan = numChannels;
+  if(numChannels > 0)
+  {
+    assert(newImg.width() == this->width() && newImg.height() == this->height() && newImg.depth() == this->depth());
+    addChannel(newImg.channels());
+  }
+  else
+  {
+      reInit( newImg.width(), newImg.height(), newImg.depth(), newImg.channels() );
+  }
+  
+  int chanNI = 0;
+  
+  for(int c = oldchan; c < (int)numChannels; c++, chanNI++)
+  {
+    int val = 0;
+    for(int z = 0; z < this->zsize; z++)
+    {
+      for(int y = 0; y < this->ysize; y++)
+      {
+        for(int x = 0; x < this->xsize; x++, val++)
+        {
+          data[c][val] = newImg.get(x,y,z,chanNI);
+        }
+      }
+    }
+  }
+}
+
+template<class P>
+MultiChannelImage3DT<P>::~MultiChannelImage3DT()
+{
+  freeData();
+}
+
+template<class P>
+void MultiChannelImage3DT<P>::freeData()
+{
+  if ( data != NULL )
+  {
+    for ( uint i = 0 ; i < numChannels ; i++ )
+      if ( data[i] != NULL )
+        delete [] data[i];
+
+    delete [] data;
+
+    data = NULL;
+  }
+}
+
+template<class P>
+void MultiChannelImage3DT<P>::reInit( int _xsize, int _ysize, int _zsize, int _numChannels )
+{
+  freeData();
+  xsize = _xsize;
+  ysize = _ysize;
+  zsize = _zsize;
+  numChannels = _numChannels;
+  data = new P *[numChannels];
+
+  for ( uint i = 0 ; i < numChannels; i++ )
+    data[i] = new P [xsize*ysize*zsize];
+}
+
+template<class P>
+template<class SrcP>
+void MultiChannelImage3DT<P>::reInitFrom( const MultiChannelImage3DT<SrcP> & src )
+{
+  freeData();
+
+  xsize = src.width();
+  ysize = src.height();
+  zsize = src.depth();
+  numChannels = src.channels();
+
+  data = new P *[numChannels];
+
+  for ( uint i = 0 ; i < numChannels; i++ )
+    data[i] = new P [xsize*ysize*zsize];
+}
+
+template<class P>
+P MultiChannelImage3DT<P>::get( int x, int y, int z, uint channel ) const
+{
+  assert( channel < numChannels );
+  assert(( x < xsize ) && ( x >= 0 ) );
+  assert(( y < ysize ) && ( y >= 0 ) );
+  assert(( z < zsize ) && ( z >= 0 ) );
+  assert( data[channel] != NULL );
+
+  return data[channel][x + y*xsize + z*xsize*ysize];
+}
+
+template<class P>
+P ** MultiChannelImage3DT<P>::getDataPointer()
+{
+  return data;
+}
+
+template<class P>
+void MultiChannelImage3DT<P>::set( int x, int y, int z, P val, uint channel )
+{
+  assert( channel < numChannels );
+  assert(( x < xsize ) && ( x >= 0 ) );
+  assert(( y < ysize ) && ( y >= 0 ) );
+  assert(( z < zsize ) && ( z >= 0 ) );
+  assert( data[channel] != NULL );
+
+  data[channel][x + y*xsize + z*xsize*ysize] = val;
+}
+
+template<class P>
+void MultiChannelImage3DT<P>::set( P val, uint channel )
+{
+  assert( channel < numChannels );
+  assert( data[channel] != NULL );
+
+  for ( int k = 0 ; k < xsize*ysize*zsize ; k++ )
+    data[channel][k] = val;
+}
+
+template<class P>
+void MultiChannelImage3DT<P>::setAll( P val )
+{
+  for ( uint channel = 0 ; channel < numChannels ; channel++ )
+    if ( data[channel] != NULL )
+      set( val, channel );
+}
+
+template<class P>
+void MultiChannelImage3DT<P>::statistics( P & min, P & max, uint channel ) const
+{
+  assert( channel < numChannels );
+
+  for ( long k = 0 ; k < xsize*ysize*zsize ; k++ )
+  {
+    P val = data [channel][k];
+    if (( k == 0 ) || ( val > max ) ) max = val;
+    if (( k == 0 ) || ( val < min ) ) min = val;
+  }
+  
+  assert(finite(max));
+  assert(finite(min));
+}
+
+template<class P>
+Image MultiChannelImage3DT<P>::getChannel( int z, uint channel ) const
+{
+  assert( channel < numChannels );
+
+  NICE::Image img;
+  convertToGrey( img, z, channel, true );
+  /*
+      P min, max;
+      statistics ( min, max, channel );
+      fprintf (stderr, "MultiChannelImage3DT<>::showChannel: max %f min %f\n", (double)max, (double)min );*/
+
+  return img;
+}
+
+/** convert to ice image */
+template<class P>
+void MultiChannelImage3DT<P>::convertToGrey( NICE::Image & img, int z, uint channel,  bool normalize ) const
+{
+  assert( channel < numChannels );
+
+  P min, max;
+
+  if ( normalize ) {
+    statistics( min, max, channel );
+    fprintf( stderr, "MultiChannelImage3DT<>::showChannel: max %f min %f\n", ( double )max, ( double )min );
+  }
+
+  bool skip_assignment = false;
+
+  img.resize( xsize, ysize );
+
+  if ( normalize )
+    if ( max - min < std::numeric_limits<double>::min() )
+    {
+      img.set( max );
+      skip_assignment = true;
+      fprintf( stderr, "MultiChannelImage3DT::showChannel: image is uniform! (%f)\n", ( double )max );
+    }
+
+
+  if ( ! skip_assignment )
+  {
+    long k = 0;
+
+    for ( int y = 0 ; y < ysize; y++ )
+    {
+      for ( int x = 0 ; x < xsize ; x++, k++ )
+      {
+        if ( normalize )
+        {
+          img.setPixel( x, y, ( int )(( data[channel][z*xsize*ysize + k] - min ) * 255 / ( max - min ) ) );
+        }
+        else
+        {
+          img.setPixel( x, y, ( int )( data[channel][z*xsize*ysize + k] ) );
+        }
+      }
+    }
+  }
+}
+
+template<class P>
+void MultiChannelImage3DT<P>::convertToColor( NICE::ColorImage & img, int z, const int chan1, const int chan2, const int chan3) const
+{
+  assert( chan1 < numChannels && chan2 < numChannels && chan3 < numChannels);
+
+  img.resize( xsize, ysize );
+
+  long k = 0;
+
+  for ( int y = 0 ; y < ysize; y++ )
+  {
+    for ( int x = 0 ; x < xsize ; x++, k++ )
+    {
+      img.setPixel( x, y, 0, ( int )( data[chan1][z*xsize*ysize + k] ) );
+      img.setPixel( x, y, 1, ( int )( data[chan2][z*xsize*ysize + k] ) );
+      img.setPixel( x, y, 2, ( int )( data[chan3][z*xsize*ysize + k] ) );
+    }
+  }
+}
+
+template<class P>
+ColorImage MultiChannelImage3DT<P>::getColor(int z) const
+{
+  assert( z < zsize );
+	assert( numChannels >= 3 );
+
+  NICE::ColorImage img( xsize, ysize );
+
+  long k = 0;
+
+  for ( int y = 0 ; y < ysize; y++ )
+  {
+    for ( int x = 0 ; x < xsize ; x++, k++ )
+    {
+      img.setPixel( x, y, 0, ( int )( data[0][z*xsize*ysize + k] ) );
+      img.setPixel( x, y, 1, ( int )( data[1][z*xsize*ysize + k] ) );
+      img.setPixel( x, y, 2, ( int )( data[2][z*xsize*ysize + k] ) );
+    }
+  }
+  //showImage(img);
+  //getchar();
+  return img;
+}
+
+template<class P>
+void MultiChannelImage3DT<P>::calcIntegral( uint channel )
+{
+  assert( channel < numChannels );
+  assert( data[channel] != NULL );
+
+  P *integralImage = data[channel];
+
+  /** first column **/
+  int k = xsize;
+  for ( int y = 1 ; y < ysize; y++, k += xsize )
+    integralImage[k] += integralImage[k-xsize];
+
+  /** first row **/
+  k = 1;
+  for ( int x = 1 ; x < xsize; x++, k++ )
+    integralImage[k] += integralImage[k-1];
+
+  /** first stack (depth) **/
+  k = xsize * ysize;
+  for ( int z = 1 ; z < zsize; z++, k += (xsize*ysize) )
+  integralImage[k] += integralImage[k-(xsize*ysize)];
+
+  /** x-y plane **/
+  k = xsize + 1;
+  for ( int y = 1 ; y < ysize ; y++, k++ )
+    for ( int x = 1 ; x < xsize ; x++, k++ )
+    {
+      integralImage[k] += integralImage[k-1];
+      integralImage[k] += integralImage[k - xsize];
+      integralImage[k] -= integralImage[k - xsize - 1];
+    }
+
+  /** y-z plane **/
+  k = xsize*ysize + xsize;
+  for ( int z = 1 ; z < zsize ; z++, k+=xsize )
+    for ( int y = 1 ; y < zsize ; y++, k+=xsize )
+    {
+      integralImage[k] += integralImage[k-(xsize*ysize)];
+      integralImage[k] += integralImage[k - xsize];
+      integralImage[k] -= integralImage[k - xsize - (xsize*ysize)];
+    }
+  
+  /** x-z plane **/
+  k = xsize*ysize + 1;
+  for ( int z = 1 ; z < zsize ; z++, k+=((xsize*ysize)-(xsize-1)) )
+    for ( int x = 1 ; x < xsize ; x++, k++ )
+    {
+      integralImage[k] += integralImage[k-1];
+      integralImage[k] += integralImage[k - (xsize*ysize)];
+      integralImage[k] -= integralImage[k - (xsize*ysize) - 1];
+    }
+    
+  /** all other pixels **/
+  k = xsize*ysize + xsize + 1;
+  for ( int z = 1 ; z < zsize ; z++, k+= xsize )
+  {
+    for ( int y = 1 ; y < ysize ; y++, k++ )
+    {
+      for ( int x = 1 ; x < xsize ; x++, k++ )
+      {
+        integralImage[k] += integralImage[k - (xsize*ysize)];
+        integralImage[k] += integralImage[k - xsize];
+        integralImage[k] += integralImage[k - 1];
+        integralImage[k] += integralImage[k - (xsize*ysize) - xsize - 1];
+        integralImage[k] -= integralImage[k - (xsize*ysize) - xsize];
+        integralImage[k] -= integralImage[k - (xsize*ysize) - 1];
+        integralImage[k] -= integralImage[k - xsize - 1];
+      }
+    }
+  }
+}
+
+template<class P>
+P MultiChannelImage3DT<P>::getIntegralValue(int ulfx, int ulfy, int ulfz, int lrbx, int lrby, int lrbz, int channel)
+{
+  ulfx = std::max(ulfx-1, -1);
+  ulfx = std::min(ulfx, xsize-1);
+  ulfy = std::max(ulfy-1, -1);
+  ulfy = std::min(ulfy, ysize-1);
+  ulfz = std::max(ulfz-1, -1);
+  ulfz = std::min(ulfz, zsize-1);
+
+  lrbx = std::max(lrbx, 0);
+  lrbx = std::min(lrbx, xsize-1);
+  lrby = std::max(lrby, 0);
+  lrby = std::min(lrby, ysize-1);
+  lrbz = std::max(lrbz, 0);
+  lrbz = std::min(lrbz, zsize-1);
+  
+  P val1, val2, val3, val4, val5, val6, val7, val8;
+  val1 = get(lrbx, lrby, lrbz, channel);
+  if( ulfz > -1 )
+    val2 = get(lrbx, lrby, ulfz, channel);
+  else
+    val2 = 0;
+  if( ulfx > -1 )
+    val3 = get(ulfx, lrby, lrbz, channel);
+  else
+    val3 = 0;
+  if( ulfx > -1 && ulfz > -1 )
+    val4 = get(ulfx, lrby, ulfz, channel);
+  else
+    val4 = 0;
+  if( ulfy > -1 )
+    val5 = get(lrbx, ulfy, lrbz, channel);
+  else
+    val5 = 0;
+  if( ulfy > -1 && ulfz > -1 )
+    val6 = get(lrbx, ulfy, ulfz, channel);
+  else
+    val6 = 0;
+  if( ulfx > -1 && ulfy > -1 )
+    val7 = get(ulfx, ulfy, lrbz, channel);
+  else
+    val7 = 0;
+  if(ulfx > -1 && ulfy > -1 && ulfz > -1)
+    val8 = get(ulfx, ulfy, ulfz, channel);
+  else
+    val8 = 0;
+  
+  P volume = abs((P)(lrbx-ulfx)*(lrby-ulfy)*(lrbz-ulfz));
+  P val = val1 - val2 - val3 + val4 - ( val5 - val6 - val7 + val8 );
+  return val/volume;
+}
+
+template<class P>
+void MultiChannelImage3DT<P>::store( std::string filename ) const
+{
+  // simple raw format
+  FILE *f = fopen( filename.c_str(), "w" );
+
+  if ( f == NULL ) {
+    fprintf( stderr, "MultiChannelImage3DT::store: error writing to %s\n", filename.c_str() );
+    exit( -1 );
+  }
+
+  fwrite( &xsize, sizeof( int ), 1, f );
+  fwrite( &ysize, sizeof( int ), 1, f );
+  fwrite( &zsize, sizeof( int ), 1, f );
+  fwrite( &numChannels, sizeof( uint ), 1, f );
+
+  for ( uint channel = 0 ; channel < numChannels ; channel++ )
+  {
+    assert( data[channel] != NULL );
+    fwrite( data[channel], sizeof( P ), xsize*ysize*zsize, f );
+  }
+
+  fclose( f );
+}
+
+template<class P>
+void MultiChannelImage3DT<P>::restore( std::string filename )
+{
+  // simple raw format
+  FILE *f = fopen( filename.c_str(), "r" );
+
+  if ( f == NULL ) {
+    fprintf( stderr, "MultiChannelImage3DT::store: error reading from %s\n", filename.c_str() );
+    exit( -1 );
+  }
+
+  fread( &xsize, sizeof( int ), 1, f );
+  fread( &ysize, sizeof( int ), 1, f );
+  fread( &zsize, sizeof( int ), 1, f );
+  fread( &numChannels, sizeof( uint ), 1, f );
+
+  if ( numChannels > 0 ) {
+    reInit( xsize, ysize, zsize, numChannels );
+
+    for ( uint channel = 0 ; channel < numChannels ; channel++ )
+    {
+      assert( data[channel] != NULL );
+      fread( data[channel], sizeof( P ), xsize*ysize*zsize, f );
+    }
+  } else {
+    freeData();
+    data = NULL;
+  }
+
+  fclose( f );
+}
+
+template<class P>
+int MultiChannelImage3DT<P>::width() const
+{
+  return xsize;
+}
+
+template<class P>
+int MultiChannelImage3DT<P>::height() const
+{
+  return ysize;
+}
+
+template<class P>
+int MultiChannelImage3DT<P>::depth() const
+{
+  return zsize;
+}
+
+template<class P>
+int MultiChannelImage3DT<P>::channels() const
+{
+  return ( int )numChannels;
+}
+
+template<class P>
+int MultiChannelImage3DT<P>::getPixelInt( int x, int y, int z, int channel ) const
+{
+  throw( "this type is not implemented\n" );
+  return -1;
+}
+
+template<class P>
+double MultiChannelImage3DT<P>::getPixelFloat( int x, int y, int z, int channel ) const
+{
+  throw( "this type is not implemented\n" );
+  return -1.0;
+}
+
+template<class P>
+void MultiChannelImage3DT<P>::setPixelInt( int x, int y, int z, int channel, int pixel )
+{
+  throw( "this type is not implemented\n" );
+}
+
+template<class P>
+void MultiChannelImage3DT<P>::setPixelFloat( int x, int y, int z, int channel, double pixel )
+{
+  throw( "this type is not implemented\n" );
+}
+/*
+#define SET_FUNCS_PROTO_MACRO(MYTYPE) \
+template<>\
+int MultiChannelImage3DT<MYTYPE>::getPixelInt(int x, int y, int channel) const;\
+template<>\
+double MultiChannelImage3DT<MYTYPE>::getPixelFloat(int x, int y, int channel) const;\
+template<>\
+void MultiChannelImage3DT<MYTYPE>::setPixelInt(int x, int y, int channel, int pixel);\
+template<>\
+void MultiChannelImage3DT<MYTYPE>::setPixelFloat(int x, int y, int channel, double pixel);
+
+SET_FUNCS_PROTO_MACRO( double )
+SET_FUNCS_PROTO_MACRO( int )
+SET_FUNCS_PROTO_MACRO( long int )
+SET_FUNCS_PROTO_MACRO( float )
+SET_FUNCS_PROTO_MACRO( unsigned int )
+*/
+} // namespace
+
+

+ 35 - 0
image/MultiChannelImageAccess3D.h

@@ -0,0 +1,35 @@
+/*
+ * NICE-Core - efficient algebra and computer vision methods
+ *  - libimage - An image library
+ * See file License for license information.
+ */
+
+#ifndef _LIMUN_BASEMULTICHANNELIMAGE3D_H
+#define _LIMUN_BASEMULTICHANNELIMAGE3D_H
+
+namespace NICE {
+
+/**
+ * A generic, but not very efficient multi channel image access interface.
+ *
+ * @author Ferid Bajramovic
+ */
+class MultiChannelImageAccess3D {
+public:
+  virtual int width() const = 0;
+  virtual int height() const = 0;
+	virtual int depth() const = 0;
+  virtual int channels() const = 0;
+
+  virtual int getPixelInt(int x, int y, int z, int channel) const = 0;
+  virtual double getPixelFloat(int x, int y, int z, int channel) const = 0;
+
+  virtual void setPixelInt(int x, int y, int z, int channel, int pixel) = 0;
+  virtual void setPixelFloat(int x, int y, int z, int channel, double pixel) = 0;
+
+  virtual ~MultiChannelImageAccess3D () {};
+};
+
+} // namespace
+
+#endif

+ 2 - 2
libdepend.inc

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

+ 0 - 98
progs/classtest.cpp

@@ -1,98 +0,0 @@
-#include <iostream>
-#include <fstream>
-#include <core/vector/VectorT.h>
-#include <limits>
-
-using namespace std;
-
-using namespace NICE;
-
-template<class ElementType>
-
-class SparseVectorT : public VectorT<ElementType> {
-  size_t dsize;
-
-public:
-  SparseVectorT( const size_t size, const ElementType& element ): VectorT<ElementType>( size, element ) {
-    dsize = 5;
-  }
-
-  virtual inline size_t size() const {
-    return dsize;
-  }
-};
-
-
-void printit( VectorT<double> &e )
-{
-  //cout << e.size() << endl;
-  size_t a = 0;
-
-  for ( int i = 0; i < numeric_limits<int>::max(); i++ )
-  {
-    a = e.size();
-  }
-}
-
-int main( int argc, char **argv )
-{
-  VectorT<double> k( 2, 2.0 );
-  /*cout << "print1 vector:" << endl;
-  cout << e.size()<< endl;*/
-
-  //SparseVectorT<double> k(2,2.0);
-  /* cout << "print2 sparse:" << endl;
-   cout << k.size()<< endl;*/
-  /*
-   cout << "print3 vectormethode:" << endl;
-   printit(e);
-
-   cout << "print4 sparsemethode:" << endl;*/
-  printit( k );
-  return 0;
-}
-
-/*
-
-class Elter
-{
-protected:
- int t1;
- int t2;
-
-public:
- Elter():t1(1),t2(2){}
- virtual void print(){cout << "t1: " << t1 << endl;}
-};
-
-class Kind:public Elter
-{
-public:
- Kind(){t1 = 3; t2 = 4;}
- virtual void print(){cout << "t2: " << t2 << endl;}
-};
-
-void printit(Elter &e)
-{
- e.print();
-}
-
-int main(int argc, char **argv)
-{
- Elter e;
- cout << "print1 elter:" << endl;
- e.print();
-
- Kind k;
- cout << "print2 kind:" << endl;
- k.print();
-
- cout << "print3 eltermethode:" << endl;
- printit(e);
-
-
- cout << "print3 kindmethode:" << endl;
- printit(k);
- return 0;
-}
-*/

+ 0 - 123
progs/getRelevantClasses.cpp

@@ -1,123 +0,0 @@
-// Beispielhafter Aufruf: BUILD_x86_64/progs/testSemanticSegmentation -config <CONFIGFILE>
-
-/**
-* @file testSemanticSegmentation.cpp
-* @brief test semantic segmentation routines
-* @author Erik Rodner
-* @date 03/20/2008
-*/
-
-#ifdef NICE_USELIB_OPENMP
-#include <omp.h>
-#endif
-
-#include "core/basics/Config.h"
-#include <core/basics/StringTools.h>
-#include <vislearning/baselib/ICETools.h>
-
-#include "vislearning/cbaselib/MultiDataset.h"
-#include "core/image/MultiChannelImageT.h"
-
-#include <fstream>
-
-using namespace OBJREC;
-
-using namespace NICE;
-
-using namespace std;
-
-/**
- test semantic segmentation routines
-*/
-int main( int argc, char **argv )
-{
-  Config conf( argc, argv );
-
-  MultiDataset md( &conf );
-
-  const ClassNames & classNames = md.getClassNames( "train" );
-
-  const LabeledSet *testFiles = md["test"];
-
-  set<int> forbidden_classes;
-
-  std::string forbidden_classes_s = conf.gS( "analysis", "forbidden_classes", "" );
-
-  classNames.getSelection( forbidden_classes_s, forbidden_classes );
-
-  LOOP_ALL_S( *testFiles )
-  {
-    EACH_INFO( classno, info );
-
-    std::string file = info.img();
-
-    NICE::Image lm;
-    NICE::MultiChannelImageT<double> probabilities;
-
-    if ( info.hasLocalizationInfo() )
-    {
-      const LocalizationResult *l_gt = info.localization();
-
-      lm.resize( l_gt->xsize, l_gt->ysize );
-      lm.set( 0 );
-      l_gt->calcLabeledImage( lm, classNames.getBackgroundClass() );
-    }
-
-    NICE::Image lm_gt;
-
-    if ( info.hasLocalizationInfo() )
-    {
-      const LocalizationResult *l_gt = info.localization();
-
-      lm_gt.resize( l_gt->xsize, l_gt->ysize );
-      lm_gt.set( 0 );
-
-      fprintf( stderr, "testSemanticSegmentation: Generating Labeled NICE::Image (Ground-Truth)\n" );
-      l_gt->calcLabeledImage( lm_gt, classNames.getBackgroundClass() );
-    }
-
-    set<int> classes;
-
-    for ( int x = 0; x < lm_gt.width(); x++ )
-    {
-      for ( int y = 0; y < lm_gt.height(); y++ )
-      {
-        classes.insert( lm_gt.getPixel( x, y ) );
-      }
-    }
-
-
-
-    // write allowed classes
-    string cndir = conf.gS( "SemSegCsurka", "cndir", "" );
-
-    std::vector< std::string > list;
-
-    StringTools::split( file, '/', list );
-
-    cout << cndir << "/" << list.back() << ".dat" << endl;
-
-    string cname = list.back();
-
-    if ( cndir != "" )
-    {
-      string fname = cndir + "/" + cname + ".dat";
-      cout << fname << endl;
-      ofstream outfile( fname.c_str() );
-
-      set<int>::iterator theIterator;
-
-      for ( theIterator = classes.begin(); theIterator != classes.end(); theIterator++ ) {
-        outfile << *theIterator << endl;
-      }
-
-    }
-    else
-    {
-      cerr << "please define directory for writing filenames in config: SemSegCsurka::cndir" << endl;
-      exit( -1 );
-    }
-  }
-
-  return 0;
-}

+ 0 - 333
progs/testClassifier.cpp

@@ -1,333 +0,0 @@
-/**
-* @file testClassifier.cpp
-* @brief main program for classifier evaluation
-* @author Erik Rodner
-* @date 2007-10-12
-*/
-
-#include <objrec/nice_nonvis.h>
-
-#include <fstream>
-#include <iostream>
-
-#include <vislearning/cbaselib/MultiDataset.h>
-#include <objrec/iclassifier/icgeneric/CSGeneric.h>
-#include <vislearning/cbaselib/ClassificationResults.h>
-#include <vislearning/cbaselib/MutualInformation.h>
-
-#include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
-#include <vislearning/classifier/fpclassifier/randomforest/FPCRandomForestTransfer.h>
-#include <vislearning/classifier/classifierinterfaces/VCFeaturePool.h>
-
-#include "core/basics/Config.h"
-#include <vislearning/baselib/Preprocess.h>
-#include <core/basics/StringTools.h>
-
-#undef DEBUG
-
-using namespace OBJREC;
-
-using namespace NICE;
-
-using namespace std;
-
-void binarizeVector( NICE::Vector & xout, const NICE::Vector & x, const NICE::Vector & thresholds )
-{
-  xout.resize( x.size() );
-
-  for ( size_t i = 0 ; i < x.size() ; i++ )
-    if ( fabs( x[i] ) > thresholds[i] )
-      xout[i] = 1.0;
-    else
-      xout[i] = 0.0;
-}
-
-void binarizeSet( LabeledSetVector & dst, const LabeledSetVector & src, const NICE::Vector & thresholds )
-{
-  LOOP_ALL( src )
-  {
-    EACH( classno, x );
-    NICE::Vector dstv;
-    binarizeVector( dstv, x, thresholds );
-    dst.add( classno, dstv );
-  }
-}
-
-int main( int argc, char **argv )
-{
-  fprintf( stderr, "testClassifier: init\n" );
-
-  std::set_terminate( __gnu_cxx::__verbose_terminate_handler );
-
-  Config conf( argc, argv );
-
-  string wekafile = conf.gS( "main", "weka", "" );
-  string trainfn = conf.gS( "main", "train", "train.vec" );
-  string testfn = conf.gS( "main", "test", "test.vec" );
-  int format = conf.gI( "main", "format", 0 );
-  bool binarize = conf.gB( "main", "binarize", false );
-  int wekaclass = conf.gI( "main", "wekaclass", 1 );
-  string classifier_cache = conf.gS( "main", "classifiercache", "" );
-  string classifier_cache_in = conf.gS( "main", "classifierin", "" );
-  int numRuns = conf.gI( "main", "runs", 1 );
-  string writeImgNet = conf.gS( "main", "imgnet", "" );
-
-  // classno:text,classno:text,...
-  string classes = conf.gS( "main", "classes", "" );
-  int classesnb = conf.gI( "main", "classes", 0 );
-  string classesconf = conf.gS( "main", "classesconf", "" );
-
-  fprintf( stderr, "testClassifier: reading config\n" );
-  Preprocess::Init( &conf );
-
-  fprintf( stderr, "testClassifier: reading multi dataset\n" );
-  int testMaxClassNo;
-  int trainMaxClassNo;
-
-  ClassNames *classNames;
-
-  if ( classes.size() == 0 && classesnb != 0 )
-  {
-    classNames = new ClassNames();
-
-    for ( int classno = 0 ; classno < classesnb ; classno++ )
-    {
-      classNames->addClass( classno, StringTools::convertToString<int> ( classno ), StringTools::convertToString<int> ( classno ) );
-    }
-
-    trainMaxClassNo = classNames->getMaxClassno();
-
-    testMaxClassNo = trainMaxClassNo;
-  }
-  else
-    if ( classes.size() > 0 )
-    {
-      classNames = new ClassNames();
-
-      vector<string> classes_sub;
-      StringTools::split( string( classes ), ',', classes_sub );
-
-      for ( vector<string>::const_iterator i = classes_sub.begin();
-            i != classes_sub.end(); i++ )
-      {
-        vector<string> desc;
-        StringTools::split( *i, ':', desc );
-
-        if ( desc.size() != 2 )
-          break;
-
-        int classno = StringTools::convert<int> ( desc[0] );
-
-        classNames->addClass( classno, desc[1], desc[1] );
-      }
-
-      trainMaxClassNo = classNames->getMaxClassno();
-
-      testMaxClassNo = trainMaxClassNo;
-
-      classNames->store( cout );
-    }
-    else if ( classesconf.size() > 0 ) {
-      classNames = new ClassNames();
-      Config cConf( classesconf );
-      classNames->readFromConfig( cConf, "*" );
-      trainMaxClassNo = classNames->getMaxClassno();
-      testMaxClassNo = trainMaxClassNo;
-    }
-    else
-    {
-      MultiDataset md( &conf );
-      classNames = new ClassNames( md.getClassNames( "train" ), "*" );
-      testMaxClassNo = md.getClassNames( "test" ).getMaxClassno();
-      trainMaxClassNo = md.getClassNames( "train" ).getMaxClassno();
-    }
-
-  LabeledSetVector train;
-
-  if ( classifier_cache_in.size() <= 0 )
-  {
-    fprintf( stderr, "testClassifier: Reading training dataset from %s\n", trainfn.c_str() );
-    train.read( trainfn, format );
-    train.printInformation();
-  } else {
-    fprintf( stderr, "testClassifier: skipping training set %s\n", trainfn.c_str() );
-  }
-
-  LabeledSetVector test;
-
-  fprintf( stderr, "testClassifier: Reading test dataset from %s\n", testfn.c_str() );
-  test.read( testfn, format );
-
-  ClassificationResults cresults;
-
-  ofstream outinet;
-
-  if ( writeImgNet.length() > 0 )
-  {
-    outinet.open( writeImgNet.c_str() );
-  }
-
-  for ( int runs = 0 ; runs < numRuns ; runs++ ) {
-    VecClassifier *vec_classifier = NULL;
-
-    if ( conf.gS( "main", "classifier" ) == "random_forest_transfer" )
-    {
-      FeaturePoolClassifier *fpc = new FPCRandomForestTransfer( &conf, classNames );
-      vec_classifier = new VCFeaturePool( &conf, fpc );
-    } else {
-      vec_classifier = CSGeneric::selectVecClassifier( &conf, "main" );
-    }
-
-    NICE::Vector thresholds;
-
-    if ( classifier_cache_in.size() <= 0 )
-    {
-      if ( binarize ) {
-        LabeledSetVector trainbin;
-        NICE::Vector mis;
-        MutualInformation mi;
-        fprintf( stderr, "testClassifier: computing mutual information\n" );
-        mi.computeThresholdsOverall( train, thresholds, mis );
-        fprintf( stderr, "testClassifier: done!\n" );
-        binarizeSet( trainbin, train, thresholds );
-        vec_classifier->teach( trainbin );
-      } else {
-
-        vec_classifier->teach( train );
-
-      }
-
-      vec_classifier->finishTeaching();
-
-      if ( classifier_cache.size() > 0 )
-        vec_classifier->save( classifier_cache );
-    } else {
-      vec_classifier->setMaxClassNo( classNames->getMaxClassno() );
-      vec_classifier->read( classifier_cache_in );
-    }
-
-    ProgressBar pb( "Classification" );
-
-    pb.show();
-
-    std::vector<int> count( testMaxClassNo + 1, 0 );
-
-    std::vector<int> correct( testMaxClassNo + 1, 0 );
-
-    MatrixT<int> confusionMatrix( testMaxClassNo + 1, trainMaxClassNo + 1, 0 );
-
-    int n = test.count();
-    LOOP_ALL( test )
-    {
-      EACH( classno, v );
-      pb.update( n );
-#ifdef DEBUG
-      fprintf( stderr, "\tclassification\n" );
-#endif
-      ClassificationResult r;
-
-      if ( binarize )
-      {
-        NICE::Vector vout;
-        binarizeVector( vout, v, thresholds );
-        r = vec_classifier->classify( vout );
-      } else {
-        r = vec_classifier->classify( v );
-      }
-
-      r.classno_groundtruth = classno;
-
-      r.classname = classNames->text( r.classno );
-
-#ifdef DEBUG
-
-      if ( r.classno == classno )
-        fprintf( stderr, "+ classification %d (\"%s\") <-> %d (\"%s\") score=%f\n", classno,
-                 classNames->text( classno ).c_str(), r.classno, r.classname.c_str(), r.scores[r.classno] );
-      else
-        fprintf( stderr, "- classification %d (\"%s\") <-> %d (\"%s\") score=%f\n", classno,
-                 classNames->text( classno ).c_str(), r.classno, r.classname.c_str(), r.scores[r.classno] );
-
-      r.scores.store( cerr );
-
-#endif
-
-      if ( writeImgNet.length() > 0 )
-      {
-        for ( int z = 1; z < r.scores.size() - 1; z++ )
-        {
-          outinet << r.scores[z] << " ";
-        }
-
-        outinet << r.scores[r.scores.size()-1] << endl;
-      }
-
-      if ( r.classno >= 0 )
-      {
-        if ( classno == r.classno ) correct[classno]++;
-
-        count[classno]++;
-
-        if ( r.ok() ) {
-          confusionMatrix( classno, r.classno )++;
-        }
-
-        cresults.push_back( r );
-      }
-    }
-
-    pb.hide();
-
-    if ( wekafile.size() > 0 )
-    {
-      string wekafile_s = wekafile;
-
-      if ( numRuns > 1 )
-        wekafile_s = wekafile_s + "." + StringTools::convertToString<int>( runs ) + ".txt";
-
-      cresults.writeWEKA( wekafile_s, wekaclass );
-    }
-
-    int count_total = 0;
-
-    int correct_total = 0;
-    int classes_tested = 0;
-    double avg_recognition = 0.0;
-
-    for ( size_t classno = 0; classno < correct.size(); classno++ )
-    {
-      if ( count[classno] == 0 ) {
-        fprintf( stdout, "class %d not tested !!\n", ( int )classno );
-      } else {
-        fprintf( stdout, "classification result class %d (\"%s\") : %5.2f %%\n",
-                 ( int )classno, classNames->text( classno ).c_str(), correct[classno]*100.0 / count[classno] );
-        avg_recognition += correct[classno] / ( double )count[classno];
-        classes_tested++;
-      }
-
-      count_total += count[classno];
-
-      correct_total += correct[classno];
-    }
-
-    avg_recognition /= classes_tested;
-
-
-    fprintf( stdout, "overall recognition rate : %-5.3f %%\n", correct_total*100.0 / count_total );
-    fprintf( stdout, "average recognition rate : %-5.3f %%\n", avg_recognition*100 );
-    fprintf( stdout, "total:%d misclassified:%d\n", count_total, count_total - correct_total );
-
-    int max_count = *( max_element( count.begin(), count.end() ) );
-    fprintf( stdout, "no of classes : %d\n", classNames->numClasses() );
-    fprintf( stdout, "lower bound 1 : %f\n", 100.0 / ( classNames->numClasses() ) );
-    fprintf( stdout, "lower bound 2 : %f\n", max_count * 100.0 / ( double ) count_total );
-
-    cout << confusionMatrix << endl;
-
-    delete vec_classifier;
-  }
-
-  delete classNames;
-
-  return 0;
-}

+ 0 - 346
progs/testClassifierGMM.cpp

@@ -1,346 +0,0 @@
-/**
-* @file testClassifier.cpp
-* @brief main program for classifier evaluation
-* @author Erik Rodner
-* @date 2007-10-12
-*/
-
-#include <fstream>
-#include <iostream>
-
-#include <vislearning/cbaselib/MultiDataset.h>
-#include <objrec/iclassifier/icgeneric/CSGeneric.h>
-#include <vislearning/cbaselib/ClassificationResults.h>
-#include <vislearning/cbaselib/MutualInformation.h>
-
-#include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
-#include <vislearning/classifier/fpclassifier/randomforest/FPCRandomForestTransfer.h>
-#include <vislearning/classifier/classifierinterfaces/VCFeaturePool.h>
-
-#include "core/basics/Config.h"
-#include <vislearning/baselib/Preprocess.h>
-#include <core/basics/StringTools.h>
-
-#include "vislearning/math/cluster/GMM.h"
-
-#undef DEBUG
-
-using namespace OBJREC;
-
-using namespace NICE;
-
-using namespace std;
-
-void binarizeVector( NICE::Vector & xout, const NICE::Vector & x, const NICE::Vector & thresholds )
-{
-  xout.resize( x.size() );
-
-  for ( size_t i = 0 ; i < x.size() ; i++ )
-    if ( fabs( x[i] ) > thresholds[i] )
-      xout[i] = 1.0;
-    else
-      xout[i] = 0.0;
-}
-
-void binarizeSet( LabeledSetVector & dst, const LabeledSetVector & src, const NICE::Vector & thresholds )
-{
-  LOOP_ALL( src )
-  {
-    EACH( classno, x );
-    NICE::Vector dstv;
-    binarizeVector( dstv, x, thresholds );
-    dst.add( classno, dstv );
-  }
-}
-
-int main( int argc, char **argv )
-{
-  fprintf( stderr, "testClassifier: init\n" );
-
-  std::set_terminate( __gnu_cxx::__verbose_terminate_handler );
-
-  Config conf( argc, argv );
-
-  string wekafile = conf.gS( "main", "weka", "" );
-  string trainfn = conf.gS( "main", "train", "train.vec" );
-  string testfn = conf.gS( "main", "test", "test.vec" );
-  int format = conf.gI( "main", "format", 0 );
-  bool binarize = conf.gB( "main", "binarize", false );
-  int wekaclass = conf.gI( "main", "wekaclass", 1 );
-  string classifier_cache = conf.gS( "main", "classifiercache", "" );
-  string classifier_cache_in = conf.gS( "main", "classifierin", "" );
-  int numRuns = conf.gI( "main", "runs", 1 );
-
-  // classno:text,classno:text,...
-  string classes = conf.gS( "main", "classes", "" );
-  int classesnb = conf.gI( "main", "classes", 0 );
-  string classesconf = conf.gS( "main", "classesconf", "" );
-
-  fprintf( stderr, "testClassifier: reading config\n" );
-  Preprocess::Init( &conf );
-
-  fprintf( stderr, "testClassifier: reading multi dataset\n" );
-  int testMaxClassNo;
-  int trainMaxClassNo;
-
-
-  ClassNames *classNames;
-
-  if ( classes.size() == 0 && classesnb != 0 )
-  {
-    classNames = new ClassNames();
-
-    for ( int classno = 0 ; classno < classesnb ; classno++ )
-    {
-      classNames->addClass( classno, StringTools::convertToString<int> ( classno ), StringTools::convertToString<int> ( classno ) );
-    }
-
-    trainMaxClassNo = classNames->getMaxClassno();
-
-    testMaxClassNo = trainMaxClassNo;
-  }
-  else
-    if ( classes.size() > 0 )
-    {
-      classNames = new ClassNames();
-
-      vector<string> classes_sub;
-      StringTools::split( string( classes ), ',', classes_sub );
-
-      for ( vector<string>::const_iterator i = classes_sub.begin();
-            i != classes_sub.end(); i++ )
-      {
-        vector<string> desc;
-        StringTools::split( *i, ':', desc );
-
-        if ( desc.size() != 2 )
-          break;
-
-        int classno = StringTools::convert<int> ( desc[0] );
-
-        classNames->addClass( classno, desc[1], desc[1] );
-      }
-
-      trainMaxClassNo = classNames->getMaxClassno();
-
-      testMaxClassNo = trainMaxClassNo;
-
-      classNames->store( cout );
-    }
-    else if ( classesconf.size() > 0 ) {
-      classNames = new ClassNames();
-      Config cConf( classesconf );
-      classNames->readFromConfig( cConf, "*" );
-      trainMaxClassNo = classNames->getMaxClassno();
-      testMaxClassNo = trainMaxClassNo;
-    }
-    else
-    {
-      MultiDataset md( &conf );
-      classNames = new ClassNames( md.getClassNames( "train" ), "*" );
-      testMaxClassNo = md.getClassNames( "test" ).getMaxClassno();
-      trainMaxClassNo = md.getClassNames( "train" ).getMaxClassno();
-    }
-
-  LabeledSetVector train;
-
-  if ( classifier_cache_in.size() <= 0 )
-  {
-    fprintf( stderr, "testClassifier: Reading training dataset from %s\n", trainfn.c_str() );
-    train.read( trainfn, format );
-    train.printInformation();
-  } else {
-    fprintf( stderr, "testClassifier: skipping training set %s\n", trainfn.c_str() );
-  }
-
-  LabeledSetVector test;
-
-  fprintf( stderr, "testClassifier: Reading test dataset from %s\n", testfn.c_str() );
-  test.read( testfn, format );
-
-  GMM *gmm = NULL;
-  int nbgmm = conf.gI( "main", "gmm", 0 );
-
-  if ( nbgmm > 0 )
-  {
-    gmm = new GMM( &conf, nbgmm );
-    VVector vset;
-    Vector l;
-    train.getFlatRepresentation( vset, l );
-    gmm->computeMixture( vset );
-
-    map<int, vector<NICE::Vector *> >::iterator iter;
-
-    for ( iter = train.begin(); iter != train.end(); ++iter )
-    {
-      for ( uint i = 0; i < iter->second.size(); ++i )
-      {
-        gmm->getProbs( *( iter->second[i] ), *( iter->second[i] ) );
-      }
-    }
-
-    for ( iter = test.begin(); iter != test.end(); ++iter )
-    {
-      for ( uint i = 0; i < iter->second.size(); ++i )
-      {
-        gmm->getProbs( *( iter->second[i] ), *( iter->second[i] ) );
-      }
-    }
-  }
-
-  ClassificationResults cresults;
-
-
-  for ( int runs = 0 ; runs < numRuns ; runs++ ) {
-    VecClassifier *vec_classifier = NULL;
-
-    if ( conf.gS( "main", "classifier" ) == "random_forest_transfer" )
-    {
-      FeaturePoolClassifier *fpc = new FPCRandomForestTransfer( &conf, classNames );
-      vec_classifier = new VCFeaturePool( &conf, fpc );
-    } else {
-      vec_classifier = CSGeneric::selectVecClassifier( &conf, "main" );
-    }
-
-    NICE::Vector thresholds;
-
-    if ( classifier_cache_in.size() <= 0 )
-    {
-      if ( binarize ) {
-        LabeledSetVector trainbin;
-        NICE::Vector mis;
-        MutualInformation mi;
-        fprintf( stderr, "testClassifier: computing mutual information\n" );
-        mi.computeThresholdsOverall( train, thresholds, mis );
-        fprintf( stderr, "testClassifier: done!\n" );
-        binarizeSet( trainbin, train, thresholds );
-        vec_classifier->teach( trainbin );
-      } else {
-
-        vec_classifier->teach( train );
-
-      }
-
-      vec_classifier->finishTeaching();
-
-      if ( classifier_cache.size() > 0 )
-        vec_classifier->save( classifier_cache );
-    } else {
-      vec_classifier->setMaxClassNo( classNames->getMaxClassno() );
-      vec_classifier->read( classifier_cache_in );
-    }
-
-    ProgressBar pb( "Classification" );
-
-    pb.show();
-
-    std::vector<int> count( testMaxClassNo + 1, 0 );
-
-    std::vector<int> correct( testMaxClassNo + 1, 0 );
-
-    MatrixT<int> confusionMatrix( testMaxClassNo + 1, trainMaxClassNo + 1, 0 );
-
-    int n = test.count();
-    LOOP_ALL( test )
-    {
-      EACH( classno, v );
-      pb.update( n );
-
-      fprintf( stderr, "\tclassification\n" );
-      ClassificationResult r;
-
-      if ( binarize )
-      {
-        NICE::Vector vout;
-        binarizeVector( vout, v, thresholds );
-        r = vec_classifier->classify( vout );
-      } else {
-        r = vec_classifier->classify( v );
-      }
-
-      r.classno_groundtruth = classno;
-
-      r.classname = classNames->text( r.classno );
-
-#ifdef DEBUG
-
-      if ( r.classno == classno )
-        fprintf( stderr, "+ classification %d (\"%s\") <-> %d (\"%s\") score=%f\n", classno,
-                 classNames->text( classno ).c_str(), r.classno, r.classname.c_str(), r.scores[r.classno] );
-      else
-        fprintf( stderr, "- classification %d (\"%s\") <-> %d (\"%s\") score=%f\n", classno,
-                 classNames->text( classno ).c_str(), r.classno, r.classname.c_str(), r.scores[r.classno] );
-
-#endif
-
-      r.scores.store( cerr );
-
-      if ( r.classno >= 0 )
-      {
-        if ( classno == r.classno ) correct[classno]++;
-
-        count[classno]++;
-
-        if ( r.ok() ) {
-          confusionMatrix( classno, r.classno )++;
-        }
-
-        cresults.push_back( r );
-      }
-    }
-
-    pb.hide();
-
-    if ( wekafile.size() > 0 )
-    {
-      string wekafile_s = wekafile;
-
-      if ( numRuns > 1 )
-        wekafile_s = wekafile_s + "." + StringTools::convertToString<int>( runs ) + ".txt";
-
-      cresults.writeWEKA( wekafile_s, wekaclass );
-    }
-
-    int count_total = 0;
-
-    int correct_total = 0;
-    int classes_tested = 0;
-    double avg_recognition = 0.0;
-
-    for ( size_t classno = 0; classno < correct.size(); classno++ )
-    {
-      if ( count[classno] == 0 ) {
-        fprintf( stdout, "class %d not tested !!\n", ( int )classno );
-      } else {
-        fprintf( stdout, "classification result class %d (\"%s\") : %5.2f %%\n",
-                 ( int )classno, classNames->text( classno ).c_str(), correct[classno]*100.0 / count[classno] );
-        avg_recognition += correct[classno] / ( double )count[classno];
-        classes_tested++;
-      }
-
-      count_total += count[classno];
-
-      correct_total += correct[classno];
-    }
-
-    avg_recognition /= classes_tested;
-
-
-    fprintf( stdout, "overall recognition rate : %-5.3f %%\n", correct_total*100.0 / count_total );
-    fprintf( stdout, "average recognition rate : %-5.3f %%\n", avg_recognition*100 );
-    fprintf( stdout, "total:%d misclassified:%d\n", count_total, count_total - correct_total );
-
-    int max_count = *( max_element( count.begin(), count.end() ) );
-    fprintf( stdout, "no of classes : %d\n", classNames->numClasses() );
-    fprintf( stdout, "lower bound 1 : %f\n", 100.0 / ( classNames->numClasses() ) );
-    fprintf( stdout, "lower bound 2 : %f\n", max_count * 100.0 / ( double ) count_total );
-
-    cout << confusionMatrix << endl;
-
-    delete vec_classifier;
-  }
-
-  delete classNames;
-
-  return 0;
-}

+ 0 - 29
progs/testNICE.cpp

@@ -1,29 +0,0 @@
-#include <core/image/ImageT.h>
-#include <core/imagedisplay/ImageDisplay.h>
-
-#undef DEBUG
-
-using namespace NICE;
-using namespace std;
-
-int main ( int argc, char **argv )
-{
-  std::set_terminate ( __gnu_cxx::__verbose_terminate_handler );
-  Image tmp ( 500, 1000 );
-  tmp.set ( 0 );
-
-  //showImage(tmp);
-  displayImage ( tmp );
-
-  for ( int i = 0; i < 256; i++ )
-  {
-    tmp.set ( i );
-    sleep ( 10 );
-  }
-
-  cout << "fin" << endl;
-  getchar();
-
-
-  return 0;
-}

+ 0 - 51
progs/testRF.cpp

@@ -1,51 +0,0 @@
-/**
-* @file testRF.cpp
-* @brief test random forest implementation
-* @author Björn Fröhlich
-* @date 06/08/2010
-*/
-#include "core/basics/Config.h"
-
-#include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
-#include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
-
-#include "vislearning/baselib/Globals.h"
-
-using namespace OBJREC;
-
-using namespace NICE;
-
-using namespace std;
-
-int main( int argc, char **argv )
-{
-  if ( argc < 1 )
-  {
-    cerr << "Bitte Datei angeben" << endl;
-    return -1;
-  }
-
-  string filename;
-
-  filename += argv[1];
-  cout << "file: " << filename << endl;
-
-  Config *conf = new Config();
-
-  FeaturePoolClassifier *fpcrfCs = new FPCRandomForests( conf, "CsurkaForest" );
-
-  //Vector *vec = new Vector(384);
-  //Example ex(vec);
-
-  fpcrfCs->setMaxClassNo( 8 );
-  fpcrfCs->read( filename );
-  /*
-  ClassificationResult r;
-
-  if(fpcrfCs != NULL)
-  {
-   r = fpcrfCs->classify ( ex );
-  }
-  */
-  return 0;
-}

+ 154 - 126
progs/testSemanticSegmentation.cpp

@@ -15,16 +15,14 @@
 #include "core/basics/StringTools.h"
 #include <vislearning/baselib/ICETools.h>
 
-#include <semseg/semseg/SemanticSegmentation.h>
-#include <semseg/semseg/SemSegLocal.h>
-#include <semseg/semseg/SemSegCsurka.h>
-#include <semseg/semseg/SemSegNovelty.h>
-#include <semseg/semseg/SemSegRegionBased.h>
-#include <semseg/semseg/SemSegContextTree.h>
+#include <semseg3d/image/MultiChannelImage3DT.h>
+#include <semseg3d/semseg/SemanticSegmentation.h>
+#include <semseg3d/semseg/SemSegContextTree.h>
 
 #include <core/basics/ResourceStatistics.h>
 
 #include <fstream>
+#include <vector>
 
 using namespace OBJREC;
 
@@ -91,33 +89,10 @@ int main( int argc, char **argv )
 
   const ClassNames & classNames = md.getClassNames( "train" );
 
-  string method = conf.gS( "main", "method", "SSCsurka" );
-
   SemanticSegmentation *semseg = NULL;
-
-  if ( method == "SSCsurka" )
-  {
-    semseg = new SemSegCsurka( &conf, &md );
-  }
-  else if ( method == "SSContext" )
-  {
-    semseg = new SemSegContextTree( &conf, &md );
-  }
-  else if( method == "SSNovelty" )
-  {
-    semseg = new SemSegNovelty( &conf, &md );
-  }
-
-  //SemanticSegmentation *semseg = new SemSegLocal ( &conf, &md );
-  //SemanticSegmentation *semseg = new SemSegSTF ( &conf, &md );
-  //SemanticSegmentation *semseg = new SemSegRegionBased(&conf, &md);
-
+  semseg = new SemSegContextTree( &conf, &md );
   const LabeledSet *testFiles = md["test"];
 
-  NICE::Matrix M( classNames.getMaxClassno() + 1, classNames.getMaxClassno() + 1 );
-
-  M.set( 0 );
-
   set<int> forbidden_classes;
 
   std::string forbidden_classes_s = conf.gS( "analysis", "forbidden_classes", "" );
@@ -128,130 +103,183 @@ int main( int argc, char **argv )
 
   pb.show();
 
-  int fileno = 0;
+  int fileno = 0, imageno = 0;
+
+	vector< int > zsizeVec;
+	semseg->getDepthVector( testFiles, zsizeVec );
+
+	int depthCount = 0, idx = 0;
+	vector< string > filelist;
+	NICE::MultiChannelImageT<double> segresult;
+	NICE::MultiChannelImageT<double> gt;
+	std::vector< NICE::Matrix > M_vec;
 
-  LOOP_ALL_S( *testFiles )
+	LOOP_ALL_S( *testFiles )
   {
     EACH_INFO( classno, info );
     std::string file = info.img();
+    filelist.push_back( file );
+		depthCount++;
 
-    NICE::Image lm;
-    NICE::MultiChannelImageT<double> probabilities;
-
-    if ( info.hasLocalizationInfo() )
+		NICE::Image lm;
+		NICE::Image lm_gt;
+		if ( info.hasLocalizationInfo() )
     {
       const LocalizationResult *l_gt = info.localization();
 
       lm.resize( l_gt->xsize, l_gt->ysize );
       lm.set( 0 );
-      l_gt->calcLabeledImage( lm, classNames.getBackgroundClass() );
-    }
-
-    semseg->semanticseg( file, lm, probabilities );
-
-    fprintf( stderr, "testSemanticSegmentation: Segmentation finished !\n" );
-
-    NICE::Image lm_gt;
-
-    if ( info.hasLocalizationInfo() )
-    {
-      const LocalizationResult *l_gt = info.localization();
-
-      lm_gt.resize( l_gt->xsize, l_gt->ysize );
+			
+			lm_gt.resize( l_gt->xsize, l_gt->ysize );
       lm_gt.set( 0 );
-
-      fprintf( stderr, "testSemanticSegmentation: Generating Labeled NICE::Image (Ground-Truth)\n" );
+      
+			l_gt->calcLabeledImage( lm, classNames.getBackgroundClass() );
+			fprintf( stderr, "testSemanticSegmentation: Generating Labeled NICE::Image (Ground-Truth)\n" );
       l_gt->calcLabeledImage( lm_gt, classNames.getBackgroundClass() );
     }
+    segresult.addChannel( lm );
+    gt.addChannel( lm_gt );
 
-    std::string fname = StringTools::baseName( file, false );
-
-    if ( write_results_pascal )
-    {
-
-      NICE::Image pascal_lm( lm.width(), lm.height() );
-      int backgroundClass = classNames.getBackgroundClass();
+		if ( depthCount < zsizeVec[idx] ) continue;
 
-      for ( int y = 0 ; y < lm.height(); y++ )
-        for ( int x = 0 ; x < lm.width(); x++ )
-        {
-          int v = lm.getPixel( x, y );
+    NICE::MultiChannelImage3DT<double> probabilities;
+		NICE::MultiChannelImage3DT<double> imgData;
+		semseg->make3DImage( filelist, imgData );
+		semseg->semanticseg( imgData, segresult, probabilities, filelist );
 
-          if ( v == backgroundClass )
-            pascal_lm.setPixel( x, y, 255 );
-          else
-            pascal_lm.setPixel( x, y, 255 - v - 1 );
-        }
-
-      char filename[1024];
-
-      char *format = ( char * )"pgm";
-      sprintf( filename, "%s/%s.%s", resultdir.c_str(), fname.c_str(), format );
-
-      pascal_lm.write( filename );
-    }
-
-    if ( show_result || write_results )
-    {
-      NICE::ColorImage orig( file );
-      NICE::ColorImage rgb;
-      NICE::ColorImage rgb_gt;
-
-      classNames.labelToRGB( lm, rgb );
-
-      classNames.labelToRGB( lm_gt, rgb_gt );
+    fprintf( stderr, "testSemanticSegmentation: Segmentation finished !\n" );
 
-      if ( write_results )
-      {
-        char filename[1024];
-        char *format = ( char * )"ppm";
-        sprintf( filename, "%06d.%s", fileno, format );
-        std::string origfilename = resultdir + "/orig_" + string( filename );
-        cerr << "Writing to file " << origfilename << endl;
-        orig.write( origfilename );
-        rgb.write( resultdir + "/result_" + string( filename ) );
-        rgb_gt.write( resultdir + "/groundtruth_" + string( filename ) );
-      }
-
-      if ( show_result )
-      {
-#ifndef NOVISUAL
-        showImage( rgb, "Result" );
-        showImage( rgb_gt, "Groundtruth" );
-        showImage( orig, "Input" );
-#endif
-      }
-    }
+    // save to file
+		for (int z = 0; z < zsizeVec[idx]; z++)
+		{
+			std::string fname = StringTools::baseName( filelist[z], false );
+
+			if ( write_results_pascal )
+			{
+				NICE::Image pascal_lm( segresult.width(), segresult.height() );
+				int backgroundClass = classNames.getBackgroundClass();
+
+				for ( int y = 0 ; y < segresult.height(); y++ )
+				{
+					for ( int x = 0 ; x < segresult.width(); x++ )
+					{
+						int v = segresult.get( x, y, (uint)z );
+
+						if ( v == backgroundClass )
+							pascal_lm.setPixel( x, y, 255 );
+						else
+							pascal_lm.setPixel( x, y, 255 - v - 1 );
+					}
+				}
+				
+				char filename[1024];
+
+				char *format = ( char * )"pgm";
+				sprintf( filename, "%s/%s.%s", resultdir.c_str(), fname.c_str(), format );
+				pascal_lm.write( filename );
+			}
+
+			if ( show_result || write_results )
+			{
+				NICE::ColorImage orig( filelist[z] );
+				NICE::ColorImage rgb;
+				NICE::ColorImage rgb_gt;
+
+				NICE::Image lm( segresult.width(), segresult.height() );
+				NICE::Image lm_gt( segresult.width(), segresult.height() );
+				for ( int y = 0 ; y < segresult.height(); y++ )
+				{
+					for ( int x = 0 ; x < segresult.width(); x++ )
+					{
+						lm.setPixel( x, y, segresult.get( x, y, (uint)z ) );
+						lm_gt.setPixel( x, y, gt.get( x, y, (uint)z ) );
+					}
+				}
+				classNames.labelToRGB( lm, rgb );
+				classNames.labelToRGB( lm_gt, rgb_gt );
+
+				if ( write_results )
+				{
+					char filename[1024];
+					char *format = ( char * )"ppm";
+					sprintf( filename, "%03d_%03d.%s", imageno, fileno, format );
+					std::string origfilename = resultdir + "/orig_" + string( filename );
+					cerr << "Writing to file " << origfilename << endl;
+					orig.write( origfilename );
+					rgb.write( resultdir + "/result_" + string( filename ) );
+					rgb_gt.write( resultdir + "/groundtruth_" + string( filename ) );
+					fileno++;
+				}
+
+				if ( show_result )
+				{
+	#ifndef NOVISUAL
+					showImage( rgb, "Result" );
+					showImage( rgb_gt, "Groundtruth" );
+					showImage( orig, "Input" );
+	#endif
+				}
+			}
+		}
 
 //#pragma omp critical
-    updateMatrix( lm, lm_gt, M, forbidden_classes );
-
-    cerr << M << endl;
-
-    fileno++;
-
-    pb.update( testFiles->count() );
+		for (int z = 0; z < zsizeVec[idx]; z++)
+		{
+			NICE::Image lm( segresult.width(), segresult.height() );
+			NICE::Image lm_gt( segresult.width(), segresult.height() );
+			for ( int y = 0 ; y < segresult.height(); y++ )
+			{
+				for ( int x = 0 ; x < segresult.width(); x++ )
+				{
+					lm.setPixel( x, y, segresult.get( x, y, (uint)z ) );
+					lm_gt.setPixel( x, y, gt.get( x, y, (uint)z ) );
+				}
+			}
+			NICE::Matrix M( classNames.getMaxClassno() + 1, classNames.getMaxClassno() + 1 );
+			M.set( 0 );
+			updateMatrix( lm, lm_gt, M, forbidden_classes );
+			M_vec.push_back( M );
+			
+			cerr << M << endl;
+		}
+
+		// prepare for new 3d image
+		filelist.clear();
+		NICE::MultiChannelImageT<double> segresult;
+		NICE::MultiChannelImageT<double> gt;
+		depthCount = 0;
+		idx++;
+		imageno++;
+
+		pb.update( testFiles->count() );
   }
-
+	segresult.freeData();
   pb.hide();
 
   long maxMemory;
   rs.getMaximumMemory(maxMemory);
   cerr << "Maximum memory used: " << maxMemory << " KB" << endl;
-  
+
   double overall = 0.0;
   double sumall = 0.0;
 
-  for ( int r = 0; r < ( int )M.rows(); r++ )
-  {
-    for ( int c = 0; c < ( int )M.cols(); c++ )
-    {
-      if ( r == c )
-        overall += M( r, c );
-
-      sumall += M( r, c );
-    }
-  }
+	NICE::Matrix M( classNames.getMaxClassno() + 1, classNames.getMaxClassno() + 1 );
+	M.set( 0 );
+	for (int s = 0; s < ( int )M_vec.size(); s++ )
+	{
+		NICE::Matrix M_tmp = M_vec[s];
+		for ( int r = 0; r < ( int )M_tmp.rows(); r++ )
+		{
+			for ( int c = 0; c < ( int )M_tmp.cols(); c++ )
+			{
+				if ( r == c )
+					overall += M_tmp( r, c );
+
+				sumall += M_tmp( r, c );
+				M( r, c ) += M_tmp( r, c );
+			}
+		}
+	}
 
   overall /= sumall;
 

File diff suppressed because it is too large
+ 537 - 340
semseg/SemSegContextTree.cpp


+ 17 - 12
semseg/SemSegContextTree.h

@@ -11,9 +11,10 @@
 #include "SemanticSegmentation.h"
 #include <core/vector/VVector.h>
 #include "vislearning/features/localfeatures/LFColorWeijer.h"
-#include "objrec/segmentation/RegionSegmentationMethod.h"
+#include "segmentation/RegionSegmentationMethod.h"
 
-#include "semseg/semseg/operations/Operations.h"
+#include "semseg3d/semseg/operations/Operations.h"
+#include "semseg3d/image/MultiChannelImage3DT.h"
 
 #include "gp-hik-exp/GPHIKClassifierNICE.h"
 
@@ -102,6 +103,9 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
     
     /** use Color features from van de Weijer or not */
     bool useWeijer;
+
+		/** use Edge features from Difference of Gaussian preprocessing or not */
+    bool useGaussian;
     
     /** use Regions as extra feature channel or not */
     bool useRegionFeature;
@@ -152,21 +156,20 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
     /** simple destructor */
     virtual ~SemSegContextTree();
 
-    /**
-     * test a single image
-     * @param ce input data
+		/**
+     * test a single 3d image
+     * @param imgData input data
      * @param segresult segmentation results
      * @param probabilities probabilities for each pixel
      */
-    void semanticseg ( CachedExample *ce,   NICE::Image & segresult,  NICE::MultiChannelImageT<double> & probabilities );
+		void semanticseg ( NICE::MultiChannelImage3DT<double> & imgData, NICE::MultiChannelImageT<double> & segresult, NICE::MultiChannelImage3DT<double> & probabilities, const std::vector<std::string> & filelist );
 
-    /**
+		/**
      * the main training method
      * @param md training data
      */
     void train ( const MultiDataset *md );
 
-
     /**
      * @brief computes integral image of given feats
      *
@@ -174,7 +177,7 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
      * @param integralImage output image (must be initilized)
      * @return void
      **/
-    void computeIntegralImage ( const NICE::MultiChannelImageT<unsigned short int> &currentfeats, NICE::MultiChannelImageT<double> &lfeats,int firstChannel );
+    void computeIntegralImage ( const NICE::MultiChannelImage3DT<unsigned short int> &currentfeats, NICE::MultiChannelImage3DT<double> &lfeats, int firstChannel );
 
     /**
      * @brief reads image and does some simple convertions
@@ -183,7 +186,7 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
      * @param currentFile image filename
      * @return void
      **/
-    void extractBasicFeatures ( NICE::MultiChannelImageT<double> &feats, const NICE::ColorImage &img, const std::string &currentFile, int &amountRegions);
+    void extractBasicFeatures ( NICE::MultiChannelImage3DT<double> &feats, const NICE::MultiChannelImage3DT<double> &imgData, const std::vector<std::string> &filelist, int &amountRegions);
 
     /**
      * compute best split for current settings
@@ -195,17 +198,18 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
      * @param splitval
      * @return best information gain
      */
-    double getBestSplit ( std::vector<NICE::MultiChannelImageT<double> > &feats, std::vector<NICE::MultiChannelImageT<unsigned short int> > &currentfeats, const std::vector<NICE::MatrixT<int> > &labels, int node, Operation *&splitop, double &splitval, const int &tree, std::vector<std::vector<std::vector<double> > > &regionProbs );
+    double getBestSplit ( std::vector<NICE::MultiChannelImage3DT<double> > &feats, std::vector<NICE::MultiChannelImage3DT<unsigned short int> > &currentfeats, const std::vector<NICE::MultiChannelImageT<int> > &labels, int node, Operation *&splitop, double &splitval, const int &tree, std::vector<std::vector<std::vector<double> > > &regionProbs );
 
     /**
      * @brief computes the mean probability for a given class over all trees
      * @param x x position
      * @param y y position
+		 * @param z z position
      * @param channel current class
      * @param currentfeats information about the nodes
      * @return double mean value
      **/
-    inline double getMeanProb ( const int &x, const int &y, const int &channel, const NICE::MultiChannelImageT<unsigned short int> &currentfeats );
+    inline double getMeanProb ( const int &x, const int &y, const int &z, const int &channel, const NICE::MultiChannelImage3DT<unsigned short int> &currentfeats );
 
     /**
      * @brief load all data to is stream
@@ -231,6 +235,7 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
      * @return void
      **/
     virtual void clear () {}
+
 };
 
 } // namespace

+ 0 - 2016
semseg/SemSegCsurka.cpp

@@ -1,2016 +0,0 @@
-#include <sstream>
-#include <iostream>
-
-#include "SemSegCsurka.h"
-#include "vislearning/baselib/ICETools.h"
-#include "core/image/Filter.h"
-#include "semseg/semseg/postsegmentation/PSSImageLevelPrior.h"
-
-using namespace std;
-using namespace NICE;
-using namespace OBJREC;
-
-#undef DEBUG_CSURK
-#undef UNCERTAINTY
-
-SemSegCsurka::SemSegCsurka ( const Config *conf,
-                             const MultiDataset *md )
-    : SemanticSegmentation ( conf, & ( md->getClassNames ( "train" ) ) )
-{
-  this->conf = conf;
-
-  opSiftImpl = conf->gS ( "Descriptor", "implementation", "VANDESANDE" );
-  readfeat = conf->gB ( "Descriptor", "read", true );
-  writefeat = conf->gB ( "Descriptor", "write", true );
-#ifdef DEBUG_CSURK
-  clog << "[log] SemSegCsurka::SemSegCsurka: OppenentSift implemenation: " << opSiftImpl << endl;
-#endif
-
-  save_cache = conf->gB ( "FPCPixel", "save_cache", true );
-  read_cache = conf->gB ( "FPCPixel", "read_cache", false );
-  cache = conf->gS ( "cache", "root", "" );
-  sigmaweight = conf->gD ( "SemSegCsurka", "sigmaweight", 0.6 );
-
-  dim = conf->gI ( "SemSegCsurka", "pcadim", 50 );
-
-  usepca = conf->gB ( "SemSegCsurka", "usepca", true );
-  calcpca = conf->gB ( "SemSegCsurka", "calcpca", false );
-
-  usegmm = conf->gB ( "SemSegCsurka", "usegmm", false );
-  norm = conf->gB ( "SemSegCsurka", "normalize", false );
-  usefisher = conf->gB ( "SemSegCsurka", "usefisher", false );
-  dogmm = conf->gB ( "SemSegCsurka", "dogmm", false );
-  gaussians = conf->gI ( "SemSegCsurka", "gaussians", 50 );
-
-  usekmeans = conf->gB ( "SemSegCsurka", "usekmeans", false );
-  kmeansfeat = conf->gI ( "SemSegCsurka", "kmeansfeat", 50 );
-  kmeanshard = conf->gB ( "SemSegCsurka", "kmeanshard", false );
-
-  cname = conf->gS ( "SemSegCsurka", "classifier", "RandomForests" );
-  anteil = conf->gD ( "SemSegCsurka", "anteil", 1.0 );
-  userellocprior = conf->gB ( "SemSegCsurka", "rellocfeat", false );
-  bool usesrg = conf->gB ( "SemSegCsurka", "usesrg", false );
-
-  useregions = conf->gB ( "SemSegCsurka", "useregions", true );
-  savesteps = conf->gB ( "SemSegCsurka", "savesteps", true );
-  bool usegcopt = conf->gB ( "SemSegCsurka", "usegcopt", false );
-
-  bestclasses = conf->gI ( "SemSegCsurka", "bestclasses", 0 );
-
-  smoothhl = conf->gB ( "SemSegCsurka", "smoothhl", false );
-  smoothfactor = conf->gD ( "SemSegCsurka", "smoothfactor", 1.0 );
-
-  usecolorfeats = conf->gB ( "SemSegCsurka", "usecolorfeats", false );
-
-  string rsMethod = conf->gS ( "SemSegCsurka", "segmentation", "meanshift" );
-
-  g = NULL;
-  k = NULL;
-  relloc = NULL;
-  srg = NULL;
-  gcopt = NULL;
-
-  if ( !useregions && ( userellocprior || usesrg ) )
-  {
-    cerr << "relative location priors and super region growing are just supported in combination with useregions" << endl;
-    exit ( 1 );
-  }
-
-  if ( usepca )
-    pca = PCA ( dim );
-
-  RegionSegmentationMethod * tmpseg;
-  if ( rsMethod == "meanshift" )
-    tmpseg = new RSMeanShift ( conf );
-  else
-    tmpseg = new RSGraphBased ( conf );
-
-  if ( save_cache )
-    seg = new RSCache ( conf, tmpseg );
-  else
-    seg = tmpseg;
-
-  if ( userellocprior )
-    relloc = new RelativeLocationPrior ( conf );
-  else
-    relloc = NULL;
-
-#ifdef NICE_USELIB_ICE
-  if ( usesrg )
-    srg = new PPSuperregion ( conf );
-  else
-    srg = NULL;
-#else
-  srg = NULL;
-#endif
-
-  if ( usegcopt )
-    gcopt = new PPGraphCut ( conf );
-  else
-    gcopt = NULL;
-
-  classifier = NULL;
-  vclassifier = NULL;
-  if ( cname == "RandomForests" )
-    classifier = new FPCRandomForests ( conf, "ClassifierForest" );
-  else if ( cname == "SMLR" )
-    classifier = new FPCSMLR ( conf, "ClassifierSMLR" );
-  else if ( cname == "GPHIK" )
-    classifier = new GPHIKClassifierNICE ( conf, "ClassiferGPHIK" );
-  else
-    vclassifier = CSGeneric::selectVecClassifier ( conf, "main" );
-  //classifier = new FPCSparseMultinomialLogisticRegression(conf, "ClassifierSMLR");
-
-  if ( classifier != NULL )
-    classifier->setMaxClassNo ( classNames->getMaxClassno() );
-  else
-    vclassifier->setMaxClassNo ( classNames->getMaxClassno() );
-
-  cn = md->getClassNames ( "train" );
-
-  if ( read_cache )
-  {
-    fprintf ( stderr, "SemSegCsurka:: Reading classifier data from %s\n", ( cache + "/fpcrf.data" ).c_str() );
-
-    if ( classifier != NULL )
-      classifier->read ( cache + "/fpcrf.data" );
-    else
-      vclassifier->read ( cache + "/veccl.data" );
-
-    if ( usepca )
-    {
-      std::string filename = cache + "/pca";
-      pca.read ( filename );
-    }
-
-    if ( usegmm )
-    {
-      g = new GMM ( conf, gaussians );
-
-      if ( !g->loadData ( cache + "/gmm" ) )
-      {
-        cerr << "SemSegCsurka:: no gmm file found" << endl;
-        exit ( -1 );
-      }
-    }
-    else {
-      g = NULL;
-    }
-
-    if ( usekmeans )
-    {
-      k = new KMeansOnline ( gaussians );
-    }
-
-    fprintf ( stderr, "SemSegCsurka:: successfully read\n" );
-
-    std::string filename = cache + "/rlp";
-
-    FILE *value;
-    value = fopen ( filename.c_str(), "r" );
-
-    if ( value == NULL )
-    {
-      trainpostprocess ( md );
-    }
-    else
-    {
-      if ( userellocprior )
-      {
-        relloc->read ( filename );
-      }
-    }
-
-    filename = cache + "/srg";
-
-    value = fopen ( filename.c_str(), "r" );
-
-    if ( value == NULL )
-    {
-      trainpostprocess ( md );
-    }
-    else
-    {
-      if ( srg != NULL )
-      {
-        srg->read ( filename );
-      }
-    }
-  }
-  else
-  {
-    train ( md );
-  }
-}
-
-SemSegCsurka::~SemSegCsurka()
-{
-  // clean-up
-  if ( classifier != NULL )
-    delete classifier;
-  if ( vclassifier != NULL )
-    delete vclassifier;
-  if ( seg != NULL )
-    delete seg;
-
-  g = NULL;
-  if ( g != NULL )
-    delete g;
-}
-
-void SemSegCsurka::normalize ( Examples &ex )
-{
-  assert ( ex.size() > 0 );
-  if ( vecmin.size() == 0 )
-  {
-    for ( int j = 0; j < ( int ) ex[0].second.vec->size(); j++ )
-    {
-      double maxv = -numeric_limits<int>::max();
-      double minv = numeric_limits<int>::max();
-      for ( int i = 0; i < ( int ) ex.size(); i++ )
-      {
-        maxv = std::max ( maxv, ( *ex[i].second.vec ) [j] );
-        minv = std::min ( minv, ( *ex[i].second.vec ) [j] );
-      }
-      vecmin.push_back ( minv );
-      vecmax.push_back ( maxv );
-    }
-  }
-  for ( int i = 0; i < ( int ) ex.size(); i++ )
-  {
-    for ( int j = 0; j < ( int ) ex[i].second.vec->size(); j++ )
-    {
-      ( *ex[i].second.vec ) [j] = ( ( *ex[i].second.vec ) [j] - vecmin[j] ) / ( vecmax[j] - vecmin[j] );
-    }
-  }
-  return;
-}
-
-void SemSegCsurka::convertLowToHigh ( Examples &ex, double reduce )
-{
-  cout << "converting low-level features to high-level features" << endl;
-
-  if ( reduce >= 1.0 )
-  {
-    for ( int i = 0; i < ( int ) ex.size(); i++ )
-    {
-      SparseVector *f = new SparseVector();
-
-      if ( usekmeans )
-      {
-        k->getDist ( *ex[i].second.vec, *f, kmeansfeat, kmeanshard );
-      }
-      else
-      {
-        if ( usefisher )
-          g->getFisher ( *ex[i].second.vec, *f );
-        else
-          g->getProbs ( *ex[i].second.vec, *f );
-      }
-      delete ex[i].second.vec;
-
-      ex[i].second.vec = NULL;
-      ex[i].second.svec = f;
-    }
-  }
-  else
-  {
-    srand ( time ( NULL ) );
-
-    vector<bool> del ( ex.size(), false );
-    cout << "Example size old " << ex.size() << endl;
-
-//#pragma omp parallel for
-    for ( int i = 0; i < ( int ) ex.size(); i++ )
-    {
-      double rval = ( double ) rand() / ( double ) RAND_MAX;
-      if ( rval < reduce )
-      {
-        SparseVector *f = new SparseVector();
-
-        if ( usekmeans )
-          k->getDist ( *ex[i].second.vec, *f, kmeansfeat, kmeanshard );
-        else
-        {
-          if ( usefisher )
-            g->getFisher ( *ex[i].second.vec, *f );
-          else
-            g->getProbs ( *ex[i].second.vec, *f );
-        }
-
-        delete ex[i].second.vec;
-        ex[i].second.vec = NULL;
-        ex[i].second.svec = f;
-      }
-      else
-      {
-        del[i] = true;
-      }
-    }
-    for ( int i = ( int ) del.size() - 1; i >= 0; i-- )
-    {
-      if ( del[i] )
-      {
-        ex.erase ( ex.begin() + i );
-      }
-    }
-    cerr << "Example size new " << ex.size() << endl;
-  }
-  cerr << "converting low-level features to high-level features finished" << endl;
-}
-
-void SemSegCsurka::smoothHL ( Examples ex )
-{
-
-  if ( !smoothhl )
-    return;
-  assert ( ex.size() > 1 );
-
-  long long int minx = numeric_limits<long long int>::max();
-  long long int miny = numeric_limits<long long int>::max();
-  long long int maxx = -numeric_limits<long long int>::max();
-  long long int maxy = -numeric_limits<long long int>::max();
-  long long int distx = numeric_limits<long long int>::max();
-  long long int disty = numeric_limits<long long int>::max();
-
-  set<double> scales;
-  for ( int i = 0; i < ( int ) ex.size(); i++ )
-  {
-    scales.insert ( ex[i].second.scale );
-  }
-
-  map<double, int> scalepos;
-  int it = 0;
-
-  for ( set<double>::const_iterator iter = scales.begin(); iter != scales.end();    ++iter, ++it )
-  {
-    scalepos.insert ( make_pair ( *iter, it ) );
-  }
-
-  for ( int i = 0; i < ( int ) ex.size(); i++ )
-  {
-    if ( minx < numeric_limits<int>::max() && ex[i].second.x - minx > 0 )
-      distx = std::min ( distx, ex[i].second.x - minx );
-    if ( miny < numeric_limits<int>::max() && ex[i].second.y - miny > 0 )
-      disty = std::min ( disty, ex[i].second.y - miny );
-    minx = std::min ( ( long long int ) ex[i].second.x, minx );
-    maxx = std::max ( ( long long int ) ex[i].second.x, maxx );
-    miny = std::min ( ( long long int ) ex[i].second.y, miny );
-    maxy = std::max ( ( long long int ) ex[i].second.y, maxy );
-  }
-
-  distx = abs ( distx );
-
-  int xsize = ( maxx - minx ) / distx + 1;
-  int ysize = ( maxy - miny ) / disty + 1;
-  double valx = ( ( double ) xsize - 1 ) / ( double ) ( maxx - minx );
-  double valy = ( ( double ) ysize - 1 ) / ( double ) ( maxy - miny );
-
-  //double sigma = smoothfactor;
-  double sigma = std::max ( xsize, ysize ) * smoothfactor;
-  //double sigma = 0.2;
-  cout << "sigma1: " << sigma << endl;
-
-  vector<NICE::FloatImage> imgv;
-  vector<NICE::FloatImage> gaussImgv;
-  for ( int i = 0; i < ( int ) scalepos.size(); i++ )
-  {
-    NICE::FloatImage img ( xsize, ysize );
-    NICE::FloatImage gaussImg ( xsize, ysize );
-    imgv.push_back ( img );
-    gaussImgv.push_back ( gaussImg );
-  }
-
-  for ( int d = 0; d < ex[0].second.svec->getDim(); d++ )
-  {
-    //TODO: max und min dynamisches bestimmen
-
-    for ( int i = 0; i < ( int ) scalepos.size(); i++ )
-    {
-      imgv[i].set ( 0.0 );
-      gaussImgv[i].set ( 0.0 );
-    }
-
-    for ( int i = 0; i < ( int ) ex.size(); i++ )
-    {
-      int xpos = ( ex[i].second.x - minx ) * valx;
-      int ypos = ( ex[i].second.y - miny ) * valy;
-
-      double val = ex[i].second.svec->get ( d );
-      imgv[scalepos[ex[i].second.scale]].setPixel ( xpos, ypos, val );
-    }
-
-    /*
-    for(int y = 0; y < ysize; y++)
-    {
-     for(int x = 0; x < xsize; x++)
-     {
-      // refactor-nice.pl: check this substitution
-      // old: double val = GetValD(img,x,y);
-      double val = img.getPixel(x,y);
-      double  c = 0.0;
-      if(val == 0.0)
-      {
-       if(x > 0)
-       {
-        // refactor-nice.pl: check this substitution
-        // old: val+=GetValD(img,x-1,y);
-        val+=img.getPixel(x-1,y);
-        c+=1.0;
-       }
-       if(y > 0)
-       {
-        // refactor-nice.pl: check this substitution
-        // old: val+=GetValD(img,x,y-1);
-        val+=img.getPixel(x,y-1);
-        c+=1.0;
-       }
-       if(x < xsize-1)
-       {
-        // refactor-nice.pl: check this substitution
-        // old: val+=GetValD(img,x+1,y);
-        val+=img.getPixel(x+1,y);
-        c+=1.0;
-       }
-       if(y < ysize-1)
-       {
-        // refactor-nice.pl: check this substitution
-        // old: val+=GetValD(img,x,y+1);
-        val+=img.getPixel(x,y+1);
-        c+=1.0;
-       }
-       // refactor-nice.pl: check this substitution
-       // old: PutValD(img,x,y,val/c);
-       img.setPixel(x,y,val/c);
-      }
-     }
-    }*/
-
-    for ( int i = 0; i < ( int ) imgv.size(); i++ )
-      filterGaussSigmaApproximate<float, float, float> ( imgv[i], sigma, &gaussImgv[i] );
-
-    for ( int i = 0; i < ( int ) ex.size(); i++ )
-    {
-      int xpos = ( ex[i].second.x - minx ) * valx;
-      int ypos = ( ex[i].second.y - miny ) * valy;
-      // refactor-nice.pl: check this substitution
-      // old: double val = GetValD ( gaussImgv[scalepos[ex[i].second.scale]], xpos, ypos );
-      double val = gaussImgv[scalepos[ex[i].second.scale]].getPixel ( xpos, ypos );
-
-      if ( fabs ( val ) < 1e-7 )
-      {
-        if ( ex[i].second.svec->get ( d ) != 0.0 )
-        {
-          ex[i].second.svec->erase ( d );
-        }
-      }
-      else
-      {
-        ( *ex[i].second.svec ) [d] = val;
-      }
-    }
-  }
-}
-
-void SemSegCsurka::initializePCA ( Examples &ex )
-{
-#ifdef DEBUG
-  cerr << "start computing pca" << endl;
-#endif
-  std::string filename = cache + "/pca";
-  FILE *value;
-  value = fopen ( filename.c_str(), "r" );
-
-  if ( value == NULL || calcpca )
-  {
-    srand ( time ( NULL ) );
-
-    int featsize = ( int ) ex.size();
-    int maxfeatures = dim * 10;
-    int olddim = ex[0].second.vec->size();
-
-    maxfeatures = std::min ( maxfeatures, featsize );
-
-    NICE::Matrix features ( maxfeatures, olddim );
-
-    for ( int i = 0; i < maxfeatures; i++ )
-    {
-      int k = rand() % featsize;
-
-      int vsize = ( int ) ex[k].second.vec->size();
-      for ( int j = 0; j < vsize; j++ )
-      {
-        features ( i, j ) = ( * ( ex[k].second.vec ) ) [j];
-      }
-    }
-    pca.calculateBasis ( features, dim );
-
-    if ( save_cache )
-      pca.save ( filename );
-
-  }
-  else
-  {
-    cout << "readpca: " << filename << endl;
-    pca.read ( filename );
-    cout << "end" << endl;
-  }
-#ifdef DEBUG
-  cerr << "finished computing pca" << endl;
-#endif
-}
-
-void SemSegCsurka::doPCA ( Examples &ex )
-{
-  cout << "converting features using pca starts" << endl;
-
-  std::string savedir = cname = conf->gS ( "cache", "root", "/dev/null/" );
-  std::string shortf = ex.filename;
-  if ( string::npos != ex.filename.rfind ( "/" ) )
-    shortf = ex.filename.substr ( ex.filename.rfind ( "/" ) );
-  std::string filename = savedir + "/pcasave/" + shortf;
-  std::string syscall = "mkdir " + savedir + "/pcasave";
-  system ( syscall.c_str() );
-  cout << "filename: " << filename << endl;
-
-  if ( !FileMgt::fileExists ( filename ) || calcpca )
-  {
-    ofstream ofStream;
-
-    //Opens the file binary
-    ofStream.open ( filename.c_str(), fstream::out | fstream::binary );
-
-    for ( int k = 0; k < ( int ) ex.size(); k++ )
-    {
-      NICE::Vector tmp = pca.getFeatureVector ( * ( ex[k].second.vec ), true );
-      delete ex[k].second.vec;
-      for ( int d = 0; d < ( int ) tmp.size(); d++ )
-        ofStream.write ( ( char* ) &tmp[d], sizeof ( double ) );
-      ex[k].second.vec = new NICE::Vector ( tmp );
-    }
-    ofStream.close();
-    cout << endl;
-  }
-  else
-  {
-    ifstream ifStream;
-    ifStream.open ( filename.c_str(), std::fstream::in | std::fstream::binary );
-    for ( int k = 0; k < ( int ) ex.size(); k++ )
-    {
-      NICE::Vector tmp = NICE::Vector ( dim );
-      delete ex[k].second.vec;
-      for ( int d = 0; d < dim; d++ )
-        ifStream.read ( ( char* ) &tmp[d], sizeof ( double ) );
-      ex[k].second.vec = new NICE::Vector ( tmp );
-    }
-
-    ifStream.close();
-  }
-  cout << "converting features using pca finished" << endl;
-}
-
-void SemSegCsurka::train ( const MultiDataset *md )
-{
-
-  /*die einzelnen Trainingsschritte
-  1. auf allen Trainingsbilder SIFT Merkmale an den Gitterpunkten bei allen Auflösungen bestimmen
-  2. PCA anwenden
-  3. aus diesen ein GMM erstellen
-  4. für jedes SIFT-Merkmal einen Vektor erstellen, der an der Stelle i die Wahrscheinlichkeit enthällt zur Verteilung i des GMM, Zur Zeit mit BoV-Alternative durch Moosman06 erledigt
-  5. diese Vektoren in einem diskriminitativen Klassifikator ( z.B. SLR oder Randomized Forests) zusammen mit ihrer Klassenzugehörigkeit anlernen
-  */
-#ifdef DEBUG
-  cerr << "SemSegCsurka:: training starts" << endl;
-#endif
-
-  Examples examples;
-  examples.filename = "training";
-
-
-  // Welche Opponentsift Implementierung soll genutzt werden ?
-  LocalFeatureRepresentation *cSIFT = NULL;
-  LocalFeatureRepresentation *writeFeats = NULL;
-  LocalFeatureRepresentation *readFeats = NULL;
-  LocalFeatureRepresentation *getFeats = NULL;
-
-  if ( opSiftImpl == "NICE" )
-  {
-    cSIFT = new LFonHSG ( conf, "HSGtrain" );
-  }
-  else if ( opSiftImpl == "VANDESANDE" )
-  {
-    // the used features
-    cSIFT = new LFColorSande ( conf, "LFColorSandeTrain" );
-  }
-  else
-  {
-    fthrow ( Exception, "feattype: %s not yet supported" << opSiftImpl );
-  }
-
-  getFeats = cSIFT;
-
-  if ( writefeat )
-  {
-    // write the features to a file, if there isn't any to read
-    writeFeats = new LFWriteCache ( conf, cSIFT );
-    getFeats = writeFeats;
-  }
-
-  if ( readfeat )
-  {
-    // read the features from a file
-    if ( writefeat )
-    {
-      readFeats = new LFReadCache ( conf, writeFeats, -1 );
-    }
-    else
-    {
-      readFeats = new LFReadCache ( conf, cSIFT, -1 );
-    }
-    getFeats = readFeats;
-  }
-
-  // additional Colorfeatures
-  LFColorWeijer lcw ( conf );
-
-  int lfdimension = -1;
-
-  const LabeledSet train = * ( *md ) ["train"];
-  const LabeledSet *trainp = &train;
-
-  ////////////////////////
-  // Merkmale berechnen //
-  ////////////////////////
-
-  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;
-
-  ProgressBar pb ( "Local Feature Extraction" );
-  pb.show();
-
-  int imgnb = 0;
-
-  LOOP_ALL_S ( *trainp )
-  {
-    //EACH_S(classno, currentFile);
-    EACH_INFO ( classno, info );
-
-    pb.update ( trainp->count() );
-
-    NICE::ColorImage img;
-
-    std::string currentFile = info.img();
-    
-    CachedExample *ce = new CachedExample ( currentFile );
-
-    const LocalizationResult *locResult = info.localization();
-    if ( locResult->size() <= 0 )
-    {
-      fprintf ( stderr, "WARNING: NO ground truth polygons found for %s !\n",
-                currentFile.c_str() );
-      continue;
-    }
-
-    fprintf ( stderr, "SemSegCsurka: Collecting pixel examples from localization info: %s\n",
-              currentFile.c_str() );
-
-    int xsize, ysize;
-    ce->getImageSize ( xsize, ysize );
-
-    NICE::Image pixelLabels ( xsize, ysize );
-    pixelLabels.set ( 0 );
-    locResult->calcLabeledImage ( pixelLabels, ( *classNames ).getBackgroundClass() );
-
-    try {
-      img = ColorImage ( currentFile );
-    } catch ( Exception ) {
-      cerr << "SemSegCsurka: error opening image file <" << currentFile << ">" << endl;
-      continue;
-    }
-
-    Globals::setCurrentImgFN ( currentFile );
-
-    VVector features;
-    VVector cfeatures;
-    VVector positions;
-
-    NICE::ColorImage cimg ( currentFile );
-
-    getFeats->extractFeatures ( img, features, positions );
-
-#ifdef DEBUG_CSURK
-    cout << "[log] SemSegCsruka::train -> " << currentFile << " an " << positions.size() << " Positionen wurden Features (Anz = " << features.size() << ") " << endl;
-    cout << "mit einer Dimension von " << features[ 0].size() << " extrahiert." << endl;
-#endif
-
-    if ( usecolorfeats )
-      lcw.getDescriptors ( cimg, cfeatures, positions );
-
-    int j = 0;
-
-    for ( VVector::const_iterator i = features.begin();
-          i != features.end();
-          i++, j++ )
-    {
-      const NICE::Vector & x = *i;
-      classno = pixelLabels.getPixel ( ( int ) positions[j][0], ( int ) positions[j][1] );
-
-      if ( forbidden_classes.find ( classno ) != forbidden_classes.end() )
-        continue;
-
-      if ( lfdimension < 0 )
-        lfdimension = ( int ) x.size();
-      else
-        assert ( lfdimension == ( int ) x.size() );
-
-      NICE::Vector *v = new NICE::Vector ( x );
-
-      if ( usecolorfeats && !usepca )
-        v->append ( cfeatures[j] );
-
-      Example example ( v );
-      example.position = imgnb;
-      examples.push_back (
-        pair<int, Example> ( classno, example ) );
-    }
-    features.clear();
-    positions.clear();
-    delete ce;
-    imgnb++;
-  }
-
-  pb.hide();
-
-  //////////////////
-  // PCA anwenden //
-  //////////////////
-
-  if ( usepca )
-  {
-    if ( !read_cache )
-    {
-      initializePCA ( examples );
-    }
-    doPCA ( examples );
-    lfdimension = dim;
-  }
-
-  /////////////////////////////////////////////////////
-  // Low-Level Features in High-Level transformieren //
-  /////////////////////////////////////////////////////
-
-  int hlfdimension = lfdimension;
-
-  if ( norm )
-    normalize ( examples );
-
-  if ( usegmm )
-  {
-    if ( !usepca && !norm )
-      normalize ( examples );
-    g = new GMM ( conf, gaussians );
-
-    if ( dogmm || !g->loadData ( cache + "/gmm" ) )
-    {
-      g->computeMixture ( examples );
-      if ( save_cache )
-        g->saveData ( cache + "/gmm" );
-    }
-
-    hlfdimension = gaussians;
-
-    if ( usefisher )
-      hlfdimension = gaussians * 2 * dim;
-  }
-
-  if ( usekmeans )
-  {
-    if ( !usepca || norm )
-      normalize ( examples );
-    k = new KMeansOnline ( gaussians );
-
-    k->cluster ( examples );
-
-    hlfdimension = gaussians;
-  }
-
-  if ( usekmeans || usegmm )
-  {
-    examples.clear();
-    pb.reset ( "Local Feature Extraction" );
-    lfdimension = -1;
-    pb.update ( trainp->count() );
-    LOOP_ALL_S ( *trainp )
-    {
-      EACH_INFO ( classno, info );
-
-      pb.update ( trainp->count() );
-
-      NICE::ColorImage img;
-
-      std::string currentFile = info.img();
-
-      CachedExample *ce = new CachedExample ( currentFile );
-
-      const LocalizationResult *locResult = info.localization();
-      if ( locResult->size() <= 0 )
-      {
-        fprintf ( stderr, "WARNING: NO ground truth polygons found for %s !\n",
-                  currentFile.c_str() );
-        continue;
-      }
-
-      fprintf ( stderr, "SemSegCsurka: Collecting pixel examples from localization info: %s\n",
-                currentFile.c_str() );
-
-      int xsize, ysize;
-      ce->getImageSize ( xsize, ysize );
-
-      NICE::Image pixelLabels ( xsize, ysize );
-      pixelLabels.set ( 0 );
-      locResult->calcLabeledImage ( pixelLabels, ( *classNames ).getBackgroundClass() );
-
-      try {
-        img = ColorImage ( currentFile );
-      }
-      catch ( Exception ) {
-        cerr << "SemSegCsurka: error opening image file <" << currentFile << ">" << endl;
-        continue;
-      }
-
-      Globals::setCurrentImgFN ( currentFile );
-
-      VVector features;
-      VVector cfeatures;
-      VVector positions;
-
-      NICE::ColorImage cimg ( currentFile );
-
-      getFeats->extractFeatures ( img, features, positions );
-
-      if ( usecolorfeats )
-        lcw.getDescriptors ( cimg, cfeatures, positions );
-
-      int j = 0;
-
-      Examples tmpex;
-
-      for ( VVector::const_iterator i = features.begin();
-            i != features.end();
-            i++, j++ )
-      {
-
-        const NICE::Vector & x = *i;
-
-        classno = pixelLabels.getPixel ( ( int ) positions[j][0], ( int ) positions[j][1] );
-
-        if ( forbidden_classes.find ( classno ) != forbidden_classes.end() )
-          continue;
-
-        if ( lfdimension < 0 )
-          lfdimension = ( int ) x.size();
-        else
-          assert ( lfdimension == ( int ) x.size() );
-
-        NICE::Vector *v = new NICE::Vector ( x );
-        if ( usecolorfeats )
-          v->append ( cfeatures[j] );
-
-        Example example ( v );
-        example.position = imgnb;
-        example.x = ( int ) positions[j][0];
-        example.y = ( int ) positions[j][1];
-        example.scale = positions[j][2];
-
-        tmpex.push_back ( pair<int, Example> ( classno, example ) );
-      }
-      tmpex.filename = currentFile;
-      if ( usepca )
-      {
-        doPCA ( tmpex );
-      }
-
-      convertLowToHigh ( tmpex, anteil );
-
-      smoothHL ( tmpex );
-
-      for ( int i = 0; i < ( int ) tmpex.size(); i++ )
-      {
-        examples.push_back ( pair<int, Example> ( tmpex[i].first, tmpex[i].second ) );
-      }
-
-      tmpex.clear();
-
-      features.clear();
-      positions.clear();
-      delete ce;
-      imgnb++;
-
-    }
-
-    pb.hide();
-  }
-  ////////////////////////////
-  // Klassifikator anlernen //
-  ////////////////////////////
-  FeaturePool fp;
-
-  Feature *f;
-
-  if ( usegmm || usekmeans )
-    f = new SparseVectorFeature ( hlfdimension );
-  else
-    f = new VectorFeature ( hlfdimension );
-
-  f->explode ( fp );
-  delete f;
-
-  if ( usecolorfeats && ! ( usekmeans || usegmm ) )
-  {
-    int dimension = hlfdimension + 11;
-    for ( int i = hlfdimension ; i < dimension ; i++ )
-    {
-      VectorFeature *f = new VectorFeature ( dimension );
-      f->feature_index = i;
-      fp.addFeature ( f, 1.0 / dimension );
-    }
-  }
-  /*
-  cout << "train classifier" << endl;
-  fp.store(cout);
-  getchar();
-  for(int z = 0; z < examples.size(); z++)
-  {
-  cout << "examples.size() " << examples.size() << endl;
-  cout << "class: " << examples[z].first << endl;
-   cout << *examples[z].second.vec << endl;
-   getchar();
-  }*/
-
-  if ( classifier != NULL )
-    classifier->train ( fp, examples );
-  else
-  {
-    LabeledSetVector lvec;
-    convertExamplesToLSet ( examples, lvec );
-    vclassifier->teach ( lvec );
-    if ( usegmm )
-      convertLSetToSparseExamples ( examples, lvec );
-    else
-      convertLSetToExamples ( examples, lvec );
-    vclassifier->finishTeaching();
-  }
-
-  fp.destroy();
-
-  if ( save_cache )
-  {
-    if ( classifier != NULL )
-      classifier->save ( cache + "/fpcrf.data" );
-    else
-      vclassifier->save ( cache + "/veccl.data" );
-  }
-
-  ////////////
-  //clean up//
-  ////////////
-  for ( int i = 0; i < ( int ) examples.size(); i++ )
-  {
-    examples[i].second.clean();
-  }
-  examples.clear();
-
-  if ( cSIFT != NULL )
-    delete cSIFT;
-  if ( writeFeats != NULL )
-    delete writeFeats;
-  if ( readFeats != NULL )
-    delete readFeats;
-  getFeats = NULL;
-
-  trainpostprocess ( md );
-
-  cerr << "SemSeg training finished" << endl;
-}
-
-void SemSegCsurka::trainpostprocess ( const MultiDataset *md )
-{
-  cout << "start postprocess" << endl;
-  ////////////////////////////
-  // Postprocess trainieren //
-  ////////////////////////////
-  const LabeledSet train = * ( *md ) ["train"];
-  const LabeledSet *trainp = &train;
-
-  if ( userellocprior || srg != NULL || gcopt != NULL )
-  {
-    clog << "[log] SemSegCsurka::trainpostprocess: if ( userellocprior || srg != NULL || gcopt !=NULL )" << endl;
-    if ( userellocprior )
-      relloc->setClassNo ( cn.numClasses() );
-
-    if ( gcopt != NULL )
-    {
-      gcopt->setClassNo ( cn.numClasses() );
-    }
-
-    ProgressBar pb ( "learn relative location prior maps" );
-    pb.show();
-    LOOP_ALL_S ( *trainp ) // für alle Bilder den ersten Klassifikationsschritt durchführen um den zweiten Klassifikator anzutrainieren
-    {
-      EACH_INFO ( classno, info );
-
-      pb.update ( trainp->count() );
-
-      NICE::ColorImage img;
-
-      std::string currentFile = info.img();
-      Globals::setCurrentImgFN ( currentFile );
-      CachedExample *ce = new CachedExample ( currentFile );
-
-      const LocalizationResult *locResult = info.localization();
-      if ( locResult->size() <= 0 )
-      {
-        fprintf ( stderr, "WARNING: NO ground truth polygons found for %s !\n",
-                  currentFile.c_str() );
-        continue;
-      }
-
-      fprintf ( stderr, "SemSegCsurka: Collecting pixel examples from localization info: %s\n",
-                currentFile.c_str() );
-
-      int xsize, ysize;
-      ce->getImageSize ( xsize, ysize );
-
-      NICE::Image pixelLabels ( xsize, ysize );
-      pixelLabels.set ( 0 );
-      locResult->calcLabeledImage ( pixelLabels, ( *classNames ).getBackgroundClass() );
-
-      try {
-        img = ColorImage ( currentFile );
-      }
-      catch ( Exception )
-      {
-        cerr << "SemSegCsurka: error opening image file <" << currentFile << ">" << endl;
-        continue;
-      }
-
-      //Regionen ermitteln
-      NICE::Matrix mask;
-
-      int regionsize = seg->segRegions ( img, mask );
-#ifdef DEBUG_CSURK
-      Image overlay ( img.width(), img.height() );
-
-      double maxval = -numeric_limits<double>::max();
-
-      for ( int y = 0; y < img.height(); y++ )
-      {
-        for ( int x = 0; x < img.width(); x++ )
-        {
-          int val = ( ( int ) mask ( x, y ) + 1 ) % 256;
-          overlay.setPixel ( x, y, val );
-          maxval = std::max ( mask ( x, y ), maxval );
-        }
-      }
-
-      cout << maxval << " different regions found" << endl;
-
-      NICE::showImageOverlay ( img, overlay, "Segmentation Result" );
-#endif
-
-      Examples regions;
-
-      vector<vector<int> > hists;
-
-      for ( int i = 0; i < regionsize; i++ )
-      {
-        Example tmp;
-        regions.push_back ( pair<int, Example> ( 0, tmp ) );
-        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 );
-          regions[numb].second.x += x;
-          regions[numb].second.y += y;
-          regions[numb].second.weight += 1.0;
-          hists[numb][pixelLabels.getPixel ( x,y ) ]++;
-        }
-      }
-
-      for ( int i = 0; i < regionsize; i++ )
-      {
-        regions[i].second.x /= ( int ) regions[i].second.weight;
-        regions[i].second.y /= ( int ) regions[i].second.weight;
-
-        int maxval = -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] )
-          {
-            maxval = hists[i][k];
-            secondpos = maxpos;
-            maxpos = k;
-          }
-        }
-
-        if ( cn.text ( maxpos ) == "various" )
-          regions[i].first = secondpos;
-        else
-          regions[i].first = maxpos;
-
-      }
-      if ( userellocprior )
-        relloc->trainPriorsMaps ( regions, xsize, ysize );
-
-      if ( srg != NULL )
-        srg->trainShape ( regions, mask );
-
-      if ( gcopt != NULL )
-        gcopt->trainImage ( regions, mask );
-
-      delete ce;
-
-    }
-    pb.hide();
-    if ( userellocprior )
-      relloc->finishPriorsMaps ( cn );
-
-    if ( srg != NULL )
-      srg->finishShape ( cn );
-
-    if ( gcopt != NULL )
-      gcopt->finishPP ( cn );
-  }
-  if ( userellocprior )
-  {
-    clog << "[log] SemSegCsurka::trainpostprocess: if ( userellocprior )" << endl;
-    ProgressBar pb ( "learn relative location classifier" );
-    pb.show();
-
-    int nummer = 0;
-    LOOP_ALL_S ( *trainp ) // für alle Bilder den ersten Klassifikationsschritt durchführen um den zweiten Klassifikator anzutrainieren
-    {
-      //EACH_S(classno, currentFile);
-      EACH_INFO ( classno, info );
-      nummer++;
-      pb.update ( trainp->count() );
-
-      NICE::Image img;
-      std::string currentFile = info.img();
-
-      CachedExample *ce = new CachedExample ( currentFile );
-
-      const LocalizationResult *locResult = info.localization();
-      if ( locResult->size() <= 0 )
-      {
-        fprintf ( stderr, "WARNING: NO ground truth polygons found for %s !\n",
-                  currentFile.c_str() );
-        continue;
-      }
-
-      fprintf ( stderr, "SemSegCsurka: Collecting pixel examples from localization info: %s\n",
-                currentFile.c_str() );
-
-      int xsize, ysize;
-      ce->getImageSize ( xsize, ysize );
-
-      NICE::Image pixelLabels ( xsize, ysize );
-      pixelLabels.set ( 0 );
-      locResult->calcLabeledImage ( pixelLabels, ( *classNames ).getBackgroundClass() );
-
-      try {
-        img = Preprocess::ReadImgAdv ( currentFile.c_str() );
-      }
-      catch ( Exception )
-      {
-        cerr << "SemSegCsurka: error opening image file <" << currentFile << ">" << endl;
-        continue;
-      }
-      Globals::setCurrentImgFN ( currentFile );
-
-      NICE::Image segresult;
-
-      NICE::MultiChannelImageT<double> probabilities ( xsize, ysize, classno );
-
-      Examples regions;
-
-      NICE::Matrix mask;
-
-      if ( savesteps )
-      {
-        std::ostringstream s1;
-        s1 << cache << "/rlpsave/" << nummer;
-
-        std::string filename = s1.str();
-        s1 << ".probs";
-
-        std::string fn2 = s1.str();
-
-        FILE *file;
-        file = fopen ( filename.c_str(), "r" );
-
-        if ( file == NULL )
-        {
-          //berechnen
-          classifyregions ( ce, segresult, probabilities, regions, mask );
-          //schreiben
-          ofstream fout ( filename.c_str(), ios::app );
-          fout << regions.size() << endl;
-          for ( int i = 0; i < ( int ) regions.size(); i++ )
-          {
-            regions[i].second.store ( fout );
-            fout << regions[i].first << endl;
-          }
-          fout.close();
-          probabilities.store ( fn2 );
-        }
-        else
-        {
-          //lesen
-          ifstream fin ( filename.c_str() );
-          int size;
-          fin >> size;
-
-          for ( int i = 0; i < size; i++ )
-          {
-            Example ex;
-            ex.restore ( fin );
-            int tmp;
-            fin >> tmp;
-            regions.push_back ( pair<int, Example> ( tmp, ex ) );
-          }
-
-          fin.close();
-
-          probabilities.restore ( fn2 );
-        }
-      }
-      else
-      {
-        classifyregions ( ce, segresult, probabilities, regions, mask );
-      }
-
-      relloc->trainClassifier ( regions, probabilities );
-
-      delete ce;
-
-    }
-    relloc->finishClassifier();
-    pb.hide();
-
-    relloc->save ( cache + "/rlp" );
-  }
-  cout << "finished postprocess" << endl;
-}
-
-void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult, NICE::MultiChannelImageT<double> & probabilities, Examples &Regionen, NICE::Matrix & mask )
-{
-  /* die einzelnen Testschritte:
-  1.x  auf dem Testbild alle SIFT Merkmale an den Gitterpunkten bei allen Auflösungen bestimmen
-  2.x  für jedes SIFT-Merkmal einen Vektor erstellen, der an der Stelle i die Wahrscheinlichkeit enthällt zur Verteilung i des GMM
-  3.x diese Vektoren klassifizieren, so dass für jede Klasse die Wahrscheinlichkeit gespeichert wird
-  4.x für jeden Pixel die Wahrscheinlichkeiten mitteln aus allen Patches, in denen der Pixel vorkommt
-  5.x das Originalbild in homogene Bereiche segmentieren
-  6.x die homogenen Bereiche bekommen die gemittelten Wahrscheinlichkeiten ihrer Pixel
-  7. (einzelne Klassen mit einem globalen Klassifikator ausschließen)
-  8.x jeder Pixel bekommt die Klasse seiner Region zugeordnet
-  */
-
-  clog << "[log] SemSegCsruka::classifyregions" << endl;
-  int xsize, ysize;
-
-  ce->getImageSize ( xsize, ysize );
-
-  probabilities.reInit ( xsize, ysize, classNames->getMaxClassno() + 1 );
-  clog << "[log] SemSegCsruka::classifyregions: probabilities.channels() = " << probabilities.channels() << endl;
-
-  segresult.resize ( xsize, ysize );
-
-  Examples pce;
-
-  // Welche Opponentsift Implementierung soll genutzt werden ?
-  LocalFeatureRepresentation *cSIFT = NULL;
-  LocalFeatureRepresentation *writeFeats = NULL;
-  LocalFeatureRepresentation *readFeats = NULL;
-  LocalFeatureRepresentation *getFeats = NULL;
-
-
-  if ( opSiftImpl == "NICE" )
-  {
-    cSIFT = new LFonHSG ( conf, "HSGtest" );
-  }
-  else if ( opSiftImpl == "VANDESANDE" )
-  {
-    // the used features
-    cSIFT = new LFColorSande ( conf, "LFColorSandeTrain" );
-  }
-  else
-  {
-    fthrow ( Exception, "feattype: %s not yet supported" << opSiftImpl );
-  }
-
-  getFeats = cSIFT;
-
-  if ( writefeat )
-  {
-    // write the features to a file, if there isn't any to read
-    writeFeats = new LFWriteCache ( conf, cSIFT );
-    getFeats = writeFeats;
-  }
-
-  if ( readfeat )
-  {
-    // read the features from a file
-    if ( writefeat )
-    {
-      readFeats = new LFReadCache ( conf, writeFeats, -1 );
-    }
-    else
-    {
-      readFeats = new LFReadCache ( conf, cSIFT, -1 );
-    }
-    getFeats = readFeats;
-  }
-
-
-  // additional Colorfeatures
-  LFColorWeijer lcw ( conf );
-
-  NICE::ColorImage img;
-
-  std::string currentFile = Globals::getCurrentImgFN();
-
-  try
-  {
-    img = ColorImage ( currentFile );
-  }
-  catch ( Exception )
-  {
-    cerr << "SemSegCsurka: error opening image file <" << currentFile << ">" << endl;
-  }
-
-  VVector features;
-  VVector cfeatures;
-  VVector positions;
-
-  getFeats->extractFeatures ( img, features, positions );
-
-  if ( usecolorfeats )
-    lcw.getDescriptors ( img, cfeatures, positions );
-
-  set<double> scales;
-
-  int j = 0;
-  int lfdimension = -1;
-  for ( VVector::const_iterator i = features.begin();
-        i != features.end();
-        i++, j++ )
-  {
-    const NICE::Vector & x = *i;
-
-    if ( lfdimension < 0 ) lfdimension = ( int ) x.size();
-    else assert ( lfdimension == ( int ) x.size() );
-
-    NICE::Vector *v = new NICE::Vector ( x );
-
-    if ( usecolorfeats )
-      v->append ( cfeatures[j] );
-
-    Example tmp = Example ( v );
-    tmp.x = ( int ) positions[j][0];
-    tmp.y = ( int ) positions[j][1];
-    tmp.width = ( int ) ( 16.0 * positions[j][2] );
-    tmp.height = tmp.width;
-    tmp.scale = positions[j][2];
-    scales.insert ( positions[j][2] );
-    pce.push_back ( pair<int, Example> ( 0, tmp ) );
-  }
-
-  //////////////////
-  // PCA anwenden //
-  //////////////////
-  pce.filename = currentFile;
-  if ( usepca )
-  {
-    doPCA ( pce );
-    lfdimension = dim;
-  }
-
-  //////////////////
-  // BoV anwenden //
-  //////////////////
-  if ( norm )
-    normalize ( pce );
-  if ( usegmm || usekmeans )
-  {
-    if ( !usepca && !norm )
-      normalize ( pce );
-    convertLowToHigh ( pce );
-    smoothHL ( pce );
-    lfdimension = gaussians;
-  }
-
-  /////////////////////////////////////////
-  // Wahrscheinlichkeitskarten erstellen //
-  /////////////////////////////////////////
-  int klassen = probabilities.channels();
-  NICE::MultiChannelImageT<double> preMap ( xsize, ysize, klassen*scales.size() );
-
-  // initialisieren
-  for ( int y = 0 ; y < ysize ; y++ )
-    for ( int x = 0 ; x < xsize ; x++ )
-    {
-      // alles zum Hintergrund machen
-      segresult.setPixel ( x, y, 0 );
-      // Die Wahrscheinlichkeitsmaps auf 0 initialisieren
-      for ( int i = 0 ; i < ( int ) probabilities.channels(); i++ )
-      {
-        probabilities[i](x,y) = 0.0;
-      }
-      for ( int j = 0; j < ( int ) preMap.channels(); j++ )
-      {
-        preMap[j](x,y) = 0.0;
-      }
-    }
-
-  // Die Wahrscheinlichkeitsmaps mit den einzelnen Wahrscheinlichkeiten je Skalierung füllen
-  int scalesize = scales.size();
-
-  // Globale Häufigkeiten akkumulieren
-  FullVector fV ( ( int ) probabilities.channels() );
-
-  for ( int i = 0; i < fV.size(); i++ )
-    fV[i] = 0.0;
-
-  // read allowed classes
-
-  string cndir = conf->gS ( "SemSegCsurka", "cndir", "" );
-  int classes = ( int ) probabilities.channels();
-  vector<int> useclass ( classes, 1 );
-
-  std::vector< std::string > list;
-  StringTools::split ( currentFile, '/', list );
-
-  string orgname = list.back();
-  if ( cndir != "" )
-  {
-    useclass = vector<int> ( classes, 0 );
-    ifstream infile ( ( cndir + "/" + orgname + ".dat" ).c_str() );
-    while ( !infile.eof() && infile.good() )
-    {
-      int tmp;
-      infile >> tmp;
-      if ( tmp >= 0 && tmp < classes )
-      {
-        useclass[tmp] = 1;
-      }
-    }
-  }
-
-#ifdef UNCERTAINTY
-  vector<FloatImage> uncert;
-  for(int s = 0; s < scalesize; s++)
-  {
-    uncert.push_back(FloatImage(xsize, ysize));
-    uncert[s].set(0.0);
-  }
-  ColorImage imgrgb ( xsize, ysize );
-  std::string s;
-  std::stringstream out;
-  std::vector< std::string > list2;
-  StringTools::split ( Globals::getCurrentImgFN (), '/', list2 );
-  out << "uncertainty/" << list2.back();
-  
-  double maxu = -numeric_limits<double>::max();
-  double minu = numeric_limits<double>::max();
-#endif
-
-  if ( classifier != NULL )
-  {
-    clog << "[log] SemSegCsruka::classifyregions: Wahrscheinlichkeitskarten erstellen: classifier != NULL" << endl;
-#pragma omp parallel for
-    for ( int s = 0; s < scalesize; s++ )
-    {
-#pragma omp parallel for
-      for ( int i = s; i < ( int ) pce.size(); i += scalesize )
-      {
-        ClassificationResult r = classifier->classify ( pce[i].second );
-
-        for ( int j = 0 ; j < fV.size(); j++ )
-        {
-          if ( useclass[j] == 0 )
-            continue;
-
-          fV[j] += r.scores[j];
-          preMap.set ( pce[i].second.x, pce[i].second.y, r.scores[j], j + s*klassen );
-        }
-
-        /*if(r.uncertainty < 0.0)
-        {
-          cerr << "uncertainty: " << r.uncertainty << endl;
-          pce[i].second.svec->store(cerr);
-          cerr << endl;
-          exit(-1);
-        }*/
-#ifdef UNCERTAINTY
-        uncert[s] ( pce[i].second.x, pce[i].second.y ) = r.uncertainty;
-        maxu = std::max ( r.uncertainty, maxu );
-        minu = std::min ( r.uncertainty, minu );
-#endif
-      }
-    }
-  }
-  else
-  {
-//#pragma omp parallel for
-    for ( int s = 0; s < scalesize; s++ )
-    {
-//#pragma omp parallel for
-      for ( int i = s; i < ( int ) pce.size(); i += scalesize )
-      {
-        ClassificationResult r = vclassifier->classify ( * ( pce[i].second.vec ) );
-        for ( int j = 0 ; j < ( int ) fV.size(); j++ )
-        {
-          if ( useclass[j] == 0 )
-            continue;
-          fV[j] += r.scores[j];
-          preMap.set ( pce[i].second.x, pce[i].second.y, r.scores[j], j + s*klassen );
-        }
-#ifdef UNCERTAINTY
-        uncert[s] ( pce[i].second.x, pce[i].second.y ) = r.uncertainty;
-        maxu = std::max ( r.uncertainty, maxu );
-        minu = std::min ( r.uncertainty, minu );
-#endif
-      }
-    }
-  }
-
-#ifdef UNCERTAINTY
-  cout << "maxvdirect: " << maxu << " minvdirect: " << minu << endl;
-  FloatImage gaussUncert ( xsize, ysize );
-  ICETools::convertToRGB ( uncert[0], imgrgb );
-  imgrgb.write ( out.str() + "rough.png" );
-#endif
-
-  vector<double> scalesVec;
-  for ( set<double>::const_iterator iter = scales.begin();
-        iter != scales.end();
-        ++iter )
-  {
-    scalesVec.push_back ( *iter );
-  }
-
-#undef VISSEMSEG
-#ifdef VISSEMSEG
-
-  for ( int j = 0 ; j < ( int ) preMap.channels(); j++ )
-  {
-    cout << "klasse: " << j << endl;//" " << cn.text ( j ) << endl;
-
-    NICE::Matrix tmp ( preMap.ysize, preMap.xsize );
-    double maxval = 0.0;
-    for ( int y = 0; y < preMap.ysize; y++ )
-      for ( int x = 0; x < preMap.xsize; x++ )
-      {
-        double val = preMap.get ( x, y, j );
-        tmp ( y, x ) = val;
-        maxval = std::max ( val, maxval );
-      }
-
-    NICE::ColorImage imgrgb ( preMap.xsize, preMap.ysize );
-    ICETools::convertToRGB ( tmp, imgrgb );
-
-    cout << "maxval = " << maxval << " for class " << j << endl; //cn.text ( j ) << endl;
-
-    //Show ( ON, imgrgb, cn.text ( j ) );
-    //showImage(imgrgb, "Ergebnis");
-
-    std::string s;
-    std::stringstream out;
-    out << "tmpprebmap" << j << ".ppm";
-    s = out.str();
-    imgrgb.writePPM ( s );
-
-    //getchar();
-  }
-#endif
-
-  // Gaußfiltern
-  clog << "[log] SemSegCsruka::classifyregions: Wahrscheinlichkeitskarten erstellen -> Gaussfiltern" << endl;
-  for ( int s = 0; s < scalesize; s++ )
-  {
-    double sigma = sigmaweight * 16.0 * scalesVec[s];
-    cerr << "sigma: " << sigma << endl;
-#pragma omp parallel for
-    for ( int i = 0; i < klassen; i++ )
-    {
-      if ( forbidden_classes.find ( i ) != forbidden_classes.end() )
-      {
-        continue;
-      }
-
-      int pos = i + s * klassen;
-
-      double maxval = preMap[pos](0,0);
-      double minval = maxval;
-
-      for ( int y = 0; y < ysize; y++ )
-      {
-        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 gaussImg ( xsize, ysize );
-
-      for ( int y = 0; y < ysize; y++ )
-      {
-        for ( int x = 0; x < xsize; x++ )
-        {
-          dblImg.setPixel ( x, y, preMap[pos](x,y) );
-        }
-      }
-
-      filterGaussSigmaApproximate<float, float, float> ( dblImg, sigma, &gaussImg );
-
-      for ( int y = 0; y < ysize; y++ )
-      {
-        for ( int x = 0; x < xsize; x++ )
-        {
-          preMap[pos](x,y) = gaussImg.getPixel ( x, y );
-        }
-      }
-    }
-#ifdef UNCERTAINTY
-    filterGaussSigmaApproximate<float, float, float> ( uncert[s], sigma, &gaussUncert );
-    uncert[s] = gaussUncert;
-#endif
-  }
-
-  // Zusammenfassen und auswerten
-  clog << "[log] SemSegCsruka::classifyregions: Wahrscheinlichkeitskarten erstellen -> zusammenfassen und auswerten" << endl;
-//#pragma omp parallel for
-  for ( int x = 0; x < xsize; x++ )
-  {
-    for ( int y = 0; y < ysize; y++ )
-    {
-      for ( int j = 0 ; j < ( int ) probabilities.channels(); j++ )
-      {
-        double prob = 0.0;
-        for ( int s = 0; s < ( int ) scalesize; s++ )
-        {
-          prob += preMap.get ( x, y, j + s * klassen );
-        }
-
-        double val = prob / ( double ) ( scalesize );
-        probabilities.set ( x, y, val, j );
-      }
-    }
-  }
-  
-#ifdef UNCERTAINTY
-  for ( int x = 0; x < xsize; x++ )
-  {
-    for ( int y = 0; y < ysize; y++ )
-    {
-      for ( int s = 0; s < ( int ) scalesize; s++ )
-      {
-        gaussUncert(x,y) += uncert[s](x,y);
-      }
-      gaussUncert(x,y)/=scalesize;
-    }
-  }
-
-  maxu = -numeric_limits<double>::max();
-  minu = numeric_limits<double>::max();
-  for ( int y = 0; y < ysize; y++ )
-  {
-    for ( int x = 0; x < xsize; x++ )
-    {
-      double val = uncert[0] ( x, y );
-      maxu = std::max ( val, maxu );
-      minu = std::min ( val, minu );
-    }
-  }
-  cout << "maxvo = " << maxu << " minvo = " << minu << endl;
-
-  maxu = -numeric_limits<float>::max();
-  minu = numeric_limits<float>::max();
-
-  for ( int y = 0; y < ysize; y++ )
-  {
-    for ( int x = 0; x < xsize; x++ )
-    {
-      double val = gaussUncert ( x, y );
-      maxu = std::max ( val, maxu );
-      minu = std::min ( val, minu );
-    }
-  }
-  cout << "maxvf = " << maxu << " minvf = " << minu << endl;
-  
-  gaussUncert(0,0) = 0.0;
-  gaussUncert(0,1) = 0.04;
-  ICETools::convertToRGB ( gaussUncert, imgrgb );
-  imgrgb.write ( out.str() + "filtered.png" );
-
-#endif
-
-#undef VISSEMSEG
-#ifdef VISSEMSEG
-
-  std::string s;
-  std::stringstream out;
-  std::vector< std::string > list2;
-  StringTools::split ( Globals::getCurrentImgFN (), '/', list2 );
-
-  out << "probmaps/" << list2.back() << ".probs";
-
-  s = out.str();
-
-  probabilities.store ( s );
-
-  for ( int j = 0 ; j < ( int ) probabilities.channels(); j++ )
-  {
-    cout << "klasse: " << j << endl;//" " << cn.text ( j ) << endl;
-
-    NICE::Matrix tmp ( probabilities.ysize, probabilities.xsize );
-    double maxval = 0.0;
-    for ( int y = 0; y < probabilities.ysize; y++ )
-      for ( int x = 0; x < probabilities.xsize; x++ )
-      {
-        double val = probabilities.get ( x, y, j );
-
-        tmp ( y, x ) = val;
-        maxval = std::max ( val, maxval );
-      }
-
-    NICE::ColorImage imgrgb ( probabilities.xsize, probabilities.ysize );
-    ICETools::convertToRGB ( tmp, imgrgb );
-
-    cout << "maxval = " << maxval << " for class " << j << endl; //cn.text ( j ) << endl;
-
-    //Show ( ON, imgrgb, cn.text ( j ) );
-    //showImage(imgrgb, "Ergebnis");
-
-    std::string s;
-    std::stringstream out;
-    out << "tmp" << j << ".ppm";
-    s = out.str();
-    imgrgb.writePPM ( s );
-
-    //getchar();
-  }
-#endif
-  if ( useregions )
-  {
-    if ( bestclasses > 0 )
-    {
-      PSSImageLevelPrior pss ( 0, bestclasses, 0.2 );
-      pss.setPrior ( fV );
-      pss.postprocess ( segresult, probabilities );
-    }
-
-    //Regionen ermitteln
-
-    int regionsize = seg->segRegions ( img, mask );
-
-    Regionen.clear();
-    vector<vector <double> > regionprob;
-
-#ifdef UNCERTAINTY
-    vector<double> regionUncert;
-#endif
-
-    // Wahrscheinlichkeiten für jede Region initialisieren
-    for ( int i = 0; i < regionsize; i++ )
-    {
-      vector<double> tmp;
-      for ( int j = 0; j < ( int ) probabilities.channels(); j++ )
-      {
-        tmp.push_back ( 0.0 );
-      }
-      regionprob.push_back ( tmp );
-      Regionen.push_back ( pair<int, Example> ( 0, Example() ) );
-#ifdef UNCERTAINTY
-      regionUncert.push_back ( 0.0 );
-#endif
-    }
-
-    // Wahrscheinlichkeiten für Regionen bestimmen
-    for ( int x = 0; x < xsize; x++ )
-    {
-      for ( int y = 0; y < ysize; y++ )
-      {
-        int pos = mask ( x, y );
-        Regionen[pos].second.weight += 1.0;
-        Regionen[pos].second.x += x;
-        Regionen[pos].second.y += y;
-        for ( int j = 0 ; j < ( int ) probabilities.channels(); j++ )
-        {
-          double val = probabilities.get ( x, y, j );
-          regionprob[pos][j] += val;
-        }
-#ifdef UNCERTAINTY
-        regionUncert[pos] += gaussUncert ( x, y );
-#endif
-      }
-    }
-
-
-    /*
-    cout << "regions: " << regionsize << endl;
-    cout << "outfeats: " << endl;
-    for(int j = 0; j < regionprob.size(); j++)
-    {
-     for(int i = 0; i < regionprob[j].size(); i++)
-     {
-      cout << regionprob[j][i] << " ";
-     }
-     cout << endl;
-    }
-    cout << endl;
-    getchar();*/
-
-    // beste Wahrscheinlichkeit je Region wählen
-    for ( int i = 0; i < regionsize; i++ )
-    {
-      if ( Regionen[i].second.weight > 0 )
-      {
-        Regionen[i].second.x /= ( int ) Regionen[i].second.weight;
-        Regionen[i].second.y /= ( int ) Regionen[i].second.weight;
-      }
-      double maxval = -numeric_limits<double>::max();
-      int maxpos = 0;
-
-      for ( int j = 0 ; j < ( int ) regionprob[i].size(); j++ )
-      {
-        if ( forbidden_classes.find ( j ) != forbidden_classes.end() )
-          continue;
-
-        regionprob[i][j] /= Regionen[i].second.weight;
-
-        if ( maxval < regionprob[i][j] )
-        {
-          maxval = regionprob[i][j];
-          maxpos = j;
-        }
-        probabilities.set ( Regionen[i].second.x, Regionen[i].second.y, regionprob[i][j], j );
-      }
-
-      Regionen[i].first = maxpos;
-#ifdef UNCERTAINTY
-      regionUncert[i] /= Regionen[i].second.weight;
-#endif
-    }
-
-    // Pixel jeder Region labeln
-    for ( int y = 0; y < ( int ) mask.cols(); y++ )
-    {
-      for ( int x = 0; x < ( int ) mask.rows(); x++ )
-      {
-        int pos = mask ( x, y );
-        segresult.setPixel ( x, y, Regionen[pos].first );
-#ifdef UNCERTAINTY
-        gaussUncert ( x, y ) = regionUncert[pos];
-#endif
-      }
-    }
-#ifdef UNCERTAINTY
-    maxu = -numeric_limits<float>::max();
-    minu = numeric_limits<float>::max();
-    for ( int y = 0; y < ysize; y++ )
-    {
-      for ( int x = 0; x < xsize; x++ )
-      {
-        //float val = uncert(x,y);
-        double val = gaussUncert ( x, y );
-        maxu = std::max ( val, maxu );
-        minu = std::min ( val, minu );
-      }
-    }
-    cout << "maxvr = " << maxu << " minvr = " << minu << endl;
-//    uncert(0,0) = 1;
-//    uncert(0,1) = 0;
-    ICETools::convertToRGB ( gaussUncert, imgrgb );
-    imgrgb.write ( out.str() + "region.png" );
-#endif
-
-#undef WRITEREGIONS
-#ifdef WRITEREGIONS
-    RegionGraph rg;
-    seg->getGraphRepresentation ( img, mask, rg );
-    for ( uint pos = 0; pos < regionprob.size(); pos++ )
-    {
-      rg[pos]->setProbs ( regionprob[pos] );
-    }
-
-    std::string s;
-    std::stringstream out;
-    std::vector< std::string > list;
-    StringTools::split ( Globals::getCurrentImgFN (), '/', list );
-
-    out << "rgout/" << list.back() << ".graph";
-    string writefile = out.str();
-    rg.write ( writefile );
-#endif
-  }
-  else
-  {
-
-    PSSImageLevelPrior pss ( 1, 4, 0.2 );
-    pss.setPrior ( fV );
-    pss.postprocess ( segresult, probabilities );
-
-  }
-
-  // Saubermachen:
-  clog << "[log] SemSegCsurka::classifyregions: sauber machen" << endl;
-  for ( int i = 0; i < ( int ) pce.size(); i++ )
-  {
-    pce[i].second.clean();
-  }
-  pce.clear();
-
-  if ( cSIFT != NULL )
-    delete cSIFT;
-  if ( writeFeats != NULL )
-    delete writeFeats;
-  if ( readFeats != NULL )
-    delete readFeats;
-  getFeats = NULL;
-}
-
-void SemSegCsurka::semanticseg ( CachedExample *ce, NICE::Image & segresult, NICE::MultiChannelImageT<double> & probabilities )
-{
-  Examples regions;
-  NICE::Matrix regionmask;
-  classifyregions ( ce, segresult, probabilities, regions, regionmask );
-  if ( userellocprior || srg != NULL || gcopt != NULL )
-  {
-    if ( userellocprior )
-      relloc->postprocess ( regions, probabilities );
-
-    if ( srg != NULL )
-      srg->optimizeShape ( regions, regionmask, probabilities );
-
-    if ( gcopt != NULL )
-      gcopt->optimizeImage ( regions, regionmask, probabilities );
-
-    // Pixel jeder Region labeln
-    for ( int y = 0; y < ( int ) regionmask.cols(); y++ )
-    {
-      for ( int x = 0; x < ( int ) regionmask.rows(); x++ )
-      {
-        int pos = regionmask ( x, y );
-        segresult.setPixel ( x, y, regions[pos].first );
-      }
-    }
-  }
-
-#ifndef NOVISUAL
-#undef VISSEMSEG
-#ifdef VISSEMSEG
-//  showImage(img);
-  for ( int j = 0 ; j < ( int ) probabilities.channels(); j++ )
-  {
-    cout << "klasse: " << j << " " << cn.text ( j ) << endl;
-
-    NICE::Matrix tmp ( probabilities.ysize, probabilities.xsize );
-    double maxval = -numeric_limits<double>::max();
-    for ( int y = 0; y < probabilities.ysize; y++ )
-      for ( int x = 0; x < probabilities.xsize; x++ )
-      {
-        double val = probabilities.get ( x, y, j );
-        tmp ( y, x ) = val;
-        maxval = std::max ( val, maxval );
-      }
-
-    NICE::ColorImage imgrgb ( probabilities.xsize, probabilities.ysize );
-    ICETools::convertToRGB ( tmp, imgrgb );
-
-    cout << "maxval = " << maxval << " for class " << cn.text ( j ) << endl;
-
-    Show ( ON, imgrgb, cn.text ( j ) );
-    imgrgb.Write ( "tmp.ppm" );
-
-    getchar();
-  }
-#endif
-#endif
-
-}

+ 0 - 250
semseg/SemSegCsurka.h

@@ -1,250 +0,0 @@
-/**
- * @file SemSegCsurka.h
- * @brief semantic segmentation using the method from Csurka08
- * @author Björn Fröhlich
- * @date 04/24/2009
- */
-#ifndef SemSegCsurkaINCLUDE
-#define SemSegCsurkaINCLUDE
-
-#include "SemanticSegmentation.h"
-
-#include "vislearning/math/ftransform/PCA.h"
-
-#include "vislearning/features/localfeatures/GenericLocalFeatureSelection.h"
-#include "vislearning/features/localfeatures/LFonHSG.h"
-#include "vislearning/features/localfeatures/LFColorSande.h"
-#include "vislearning/features/localfeatures/LFColorWeijer.h"
-#include "vislearning/features/localfeatures/LFReadCache.h"
-#include "vislearning/features/localfeatures/LFWriteCache.h"
-#include "vislearning/cbaselib/VectorFeature.h"
-#include "vislearning/features/fpfeatures/SparseVectorFeature.h"
-
-#include "vislearning/cbaselib/CachedExample.h"
-#include "vislearning/baselib/Preprocess.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 "SemSegTools.h"
-
-#include "vislearning/math/cluster/GMM.h"
-#include "vislearning/math/cluster/KMeansOnline.h"
-
-#include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
-#include "vislearning/classifier/fpclassifier/logisticregression/FPCSMLR.h"
-#include "gp-hik-exp/GPHIKClassifierNICE.h"
-
-#include "semseg/semseg/postsegmentation/RelativeLocationPrior.h"
-#include "semseg/semseg/postsegmentation/PPSuperregion.h"
-#include "semseg/semseg/postsegmentation/PPGraphCut.h"
-
-
-#include <objrec/iclassifier/icgeneric/CSGeneric.h>
-
-/** @brief pixelwise labeling systems */
-
-namespace OBJREC {
-
-class SemSegCsurka : public SemanticSegmentation
-{
-
-  protected:
-
-    //! for normalization
-    std::vector<double> vecmin, vecmax;
-
-    //! boolean whether to save the cache or not
-    bool save_cache;
-
-    //! boolean whether to read the cache or not, if read_cache is false, everything will be trained
-    bool read_cache;
-
-    //! The cached Data
-    std::string cache;
-
-    //! The PCA
-    PCA pca;
-
-    //! using normalization
-    bool norm;
-
-    //! feature Dimension after PCA
-    int dim;
-
-    //! Classifier
-    FeaturePoolClassifier *classifier;
-    VecClassifier *vclassifier;
-
-    //! Configuration File
-    const NICE::Config *conf;
-
-
-    //! name of all classes
-    ClassNames cn;
-
-    //! set of forbidden/background classes
-    std::set<int> forbidden_classes;
-
-    //! whether to use the colorfeats or not
-    bool usecolorfeats;
-
-    //! low level Segmentation method
-    RegionSegmentationMethod *seg;
-
-    //! weight for the gaussimage
-    double sigmaweight;
-
-    //! Gaussian Mixture
-    GMM *g;
-
-    //! KMeans
-    KMeansOnline *k;
-
-    //! use pca or not
-    bool usepca;
-
-    //! forced recalculation of the pca
-    bool calcpca;
-
-    //! use highlevel transformation with gmm or not
-    bool usegmm;
-
-    //! use highlevel transformation with kmeans or not
-    bool usekmeans;
-
-    int bestclasses;
-
-    //! how much clusters of the kmeans to use
-    int kmeansfeat;
-
-    //! use hard assignment or not
-    bool kmeanshard;
-
-    //! use fisher kernel for bag if visual words
-    bool usefisher;
-
-    //! forced recalculation of the gmm
-    bool dogmm;
-
-    //! number of gaussians
-    int gaussians;
-
-    //! whether to use the relative location features or not
-    bool userellocprior;
-
-    //! which classifier to use
-    std::string cname;
-
-    //! use regions segmentation or not
-    bool useregions;
-
-    //! how many features should be used for training the classifier (relative value between 0 and 1
-    double anteil;
-
-    //! save steps for faster computing postprocesses
-    bool savesteps;
-
-    //! the relative location features
-    RelativeLocationPrior *relloc;
-
-    //! Shape pp
-    PPSuperregion *srg;
-
-    //! Graph Cut pp
-    PPGraphCut *gcopt;
-
-    //! smooth high level features or not
-    bool smoothhl;
-
-    //! sigma for high level smoothing
-    double smoothfactor;
-
-    //! which OpponentSIFT implementation to use {NICE, VANDESANDE}
-    std::string opSiftImpl;
-
-    //! read features?
-    bool readfeat;
-
-    //! write features?
-    bool writefeat;
-
-    /**
-     * converts the low level features in high level features
-     * @param ex input and output features
-     * @param reduce reduce the dataset (1.0 means no reduction)
-     */
-    void convertLowToHigh ( Examples &ex, double reduce = 1.0 );
-
-    /**
-     * Starts the PCA
-     * @param ex input features
-     */
-    void initializePCA ( Examples &ex );
-
-    /**
-     * using PCA on al input features
-     * @param ex input features
-     */
-    void doPCA ( Examples &ex );
-
-    /**
-     * normalize the features between 0 and 1
-     * @param ex input features
-     */
-    void normalize ( Examples &ex );
-
-
-    /**
-     * smooth the high level features
-     * @param ex input features
-     */
-    void smoothHL ( Examples ex );
-
-  public:
-
-    /** constructor
-      *  @param conf needs a configfile
-      *  @param md and a MultiDataset (contains images and other things)
-      */
-    SemSegCsurka ( const NICE::Config *conf, const MultiDataset *md );
-
-    /** simple destructor */
-    virtual ~SemSegCsurka();
-
-    /** The trainingstep
-      *  @param md and a MultiDataset (contains images and other things)
-      */
-    void train ( const MultiDataset *md );
-
-    /** The trainingstep for the postprocess
-      *  @param md and a MultiDataset (contains images and other things)
-      */
-    void trainpostprocess ( 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 );
-
-    /** this procedure is equal semanticseg, if there is no post process
-    * @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
-    * @param Regionen the output regions
-    * @param mask the positions of the regions
-    */
-    void classifyregions ( CachedExample *ce, NICE::Image & segresult, NICE::MultiChannelImageT<double> & probabilities, Examples &Regionen, NICE::Matrix &mask );
-    void getFeats ( NICE::Image arg1, NICE::VVector arg2, NICE::VVector arg3 );
-};
-
-} //namespace
-
-#endif

+ 0 - 108
semseg/SemSegLocal.cpp

@@ -1,108 +0,0 @@
-/**
-* @file SemSegLocal.cpp
-* @brief semantic segmentation using image patches only
-* @author Erik Rodner
-* @date 05/08/2008
-
-*/
-#include <iostream>
-
-#include "SemSegLocal.h"
-#include "vislearning/cbaselib/CachedExample.h"
-#include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
-#include "vislearning/features/fpfeatures/PixelPairFeature.h"
-
-#include "SemSegTools.h"
-
-using namespace OBJREC;
-
-using namespace std;
-using namespace NICE;
-
-
-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 );
-  }
-}
-
-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 );
-  }
-
-  fp.destroy();
-}
-
-
-SemSegLocal::~SemSegLocal()
-{
-  if ( fpc != NULL )
-    delete fpc;
-}
-
-
-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 );
-  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];
-    }
-}

+ 0 - 48
semseg/SemSegLocal.h

@@ -1,48 +0,0 @@
-/**
-* @file SemSegLocal.h
-* @brief semantic segmentation using image patches only
-* @author Erik Rodner
-* @date 05/08/2008
-
-*/
-#ifndef SEMSEGLOCALINCLUDE
-#define SEMSEGLOCALINCLUDE
-
-#include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
-#include "SemanticSegmentation.h"
-
-
-namespace OBJREC
-{
-
-/** abstract interface for pixelwise localization systems */
-class SemSegLocal : public SemanticSegmentation
-{
-
-  protected:
-    bool save_cache;
-    bool read_cache;
-
-    std::string cache;
-    FeaturePoolClassifier *fpc;
-
-  public:
-
-    /** simple constructor */
-    SemSegLocal ( const NICE::Config *conf, const MultiDataset *md );
-
-    /** simple destructor */
-    virtual ~SemSegLocal();
-
-    void train ( const NICE::Config *conf, const MultiDataset *md );
-
-    void semanticseg ( CachedExample *ce,
-                       NICE::Image & segresult,
-                       NICE::MultiChannelImageT<double> & probabilities );
-
-};
-
-
-} // namespace
-
-#endif

+ 0 - 355
semseg/SemSegNovelty.cpp

@@ -1,355 +0,0 @@
-#include <sstream>
-#include <iostream>
-
-#include "SemSegNovelty.h"
-
-#include "core/image/FilterT.h"
-#include "gp-hik-exp/GPHIKClassifierNICE.h"
-#include "vislearning/baselib/ICETools.h"
-#include "vislearning/baselib/Globals.h"
-#include "vislearning/features/fpfeatures/SparseVectorFeature.h"
-#include "core/basics/StringTools.h"
-#include "core/basics/Timer.h"
-
-using namespace std;
-using namespace NICE;
-using namespace OBJREC;
-
-SemSegNovelty::SemSegNovelty ( const Config *conf,
-                               const MultiDataset *md )
-    : SemanticSegmentation ( conf, & ( md->getClassNames ( "train" ) ) )
-{
-  this->conf = conf;
-
-  string section = "SemSegNovelty";
-
-  featExtract = new LFColorWeijer ( conf );
-
-  save_cache = conf->gB ( "FPCPixel", "save_cache", true );
-  read_cache = conf->gB ( "FPCPixel", "read_cache", false );
-  uncertdir = conf->gS("debug", "uncertainty", "uncertainty");
-  cache = conf->gS ( "cache", "root", "" );
-
-
-  classifier = new GPHIKClassifierNICE ( conf, "ClassiferGPHIK" );;
-
-  whs = conf->gI ( section, "window_size", 10 );
-  featdist = conf->gI ( section, "grid", 10 );
-  testWSize = conf->gI (section, "test_window_size", 10);
-
-  cn = md->getClassNames ( "train" );
-
-  if ( read_cache )
-  {
-    string classifierdst = "/classifier.data";
-    fprintf ( stderr, "SemSegNovelty:: Reading classifier data from %s\n", ( cache + classifierdst ).c_str() );
-
-    try
-    {
-      if ( classifier != NULL )
-      {
-        classifier->read ( cache + classifierdst );
-      }
-
-      fprintf ( stderr, "SemSegNovelty:: successfully read\n" );
-    }
-    catch ( char *str )
-    {
-      cerr << "error reading data: " << str << endl;
-    }
-  }
-  else
-  {
-    train ( md );
-  }
-}
-
-SemSegNovelty::~SemSegNovelty()
-{
-  // clean-up
-  if ( classifier != NULL )
-    delete classifier;
-  if ( featExtract != NULL )
-    delete featExtract;
-}
-
-void SemSegNovelty::train ( const MultiDataset *md )
-{
-  const LabeledSet train = * ( *md ) ["train"];
-  const LabeledSet *trainp = &train;
-
-  ////////////////////////
-  // feature extraction //
-  ////////////////////////
-
-  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;
-
-  ProgressBar pb ( "Local Feature Extraction" );
-  pb.show();
-
-  int imgnb = 0;
-
-  Examples examples;
-  examples.filename = "training";
-
-  int featdim = -1;
-
-  LOOP_ALL_S ( *trainp )
-  {
-    //EACH_S(classno, currentFile);
-    EACH_INFO ( classno, info );
-
-    std::string currentFile = info.img();
-
-    CachedExample *ce = new CachedExample ( currentFile );
-
-    const LocalizationResult *locResult = info.localization();
-    if ( locResult->size() <= 0 )
-    {
-      fprintf ( stderr, "WARNING: NO ground truth polygons found for %s !\n",
-                currentFile.c_str() );
-      continue;
-    }
-
-    int xsize, ysize;
-    ce->getImageSize ( xsize, ysize );
-
-    Image labels ( xsize, ysize );
-    labels.set ( 0 );
-    locResult->calcLabeledImage ( labels, ( *classNames ).getBackgroundClass() );
-
-    NICE::ColorImage img;
-    try {
-      img = ColorImage ( currentFile );
-    } catch ( Exception ) {
-      cerr << "SemSegNovelty: error opening image file <" << currentFile << ">" << endl;
-      continue;
-    }
-
-    Globals::setCurrentImgFN ( currentFile );
-
-    MultiChannelImageT<double> feats;
-
-    // extract features
-    featExtract->getFeats ( img, feats );
-    featdim = feats.channels();
-    feats.addChannel(featdim);
-
-    for (int c = 0; c < featdim; c++)
-    {
-      ImageT<double> tmp = feats[c];
-      ImageT<double> tmp2 = feats[c+featdim];
-
-      NICE::FilterT<double, double, double>::gradientStrength (tmp, tmp2);
-    }
-    featdim += featdim;
-
-    // compute integral images
-    for ( int c = 0; c < featdim; c++ )
-    {
-      feats.calcIntegral ( c );
-    }
-
-    for ( int y = 0; y < ysize; y += featdist )
-    {
-      for ( int x = 0; x < xsize; x += featdist )
-      {
-        int classno = labels ( x, y );
-
-        if ( forbidden_classes.find ( classno ) != forbidden_classes.end() )
-          continue;
-
-
-        Example example;
-        example.vec = NULL;
-        example.svec = new SparseVector ( featdim );
-        for ( int f = 0; f < featdim; f++ )
-        {
-          double val = feats.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
-          if ( val > 1e-10 )
-            ( *example.svec ) [f] = val;
-        }
-
-        example.svec->normalize();
-
-        example.position = imgnb;
-        examples.push_back ( pair<int, Example> ( classno, example ) );
-      }
-    }
-
-    delete ce;
-    imgnb++;
-    pb.update ( trainp->count() );
-  }
-
-  pb.hide();
-
-
-  //////////////////////
-  // train classifier //
-  //////////////////////
-  FeaturePool fp;
-
-  Feature *f = new SparseVectorFeature ( featdim );
-
-  f->explode ( fp );
-  delete f;
-
-  if ( classifier != NULL )
-    classifier->train ( fp, examples );
-  else
-  {
-    cerr << "no classifier selected?!" << endl;
-    exit ( -1 );
-  }
-
-  fp.destroy();
-
-  if ( save_cache )
-  {
-    if ( classifier != NULL )
-      classifier->save ( cache + "/classifier.data" );
-  }
-
-  ////////////
-  //clean up//
-  ////////////
-  for ( int i = 0; i < ( int ) examples.size(); i++ )
-  {
-    examples[i].second.clean();
-  }
-  examples.clear();
-
-  cerr << "SemSeg training finished" << endl;
-}
-
-void SemSegNovelty::semanticseg ( CachedExample *ce, NICE::Image & segresult, NICE::MultiChannelImageT<double> & probabilities )
-{
-  Timer timer;
-  timer.start();
-
-  Examples examples;
-  examples.filename = "testing";
-
-  segresult.set ( 0 );
-
-  int featdim = -1;
-
-  std::string currentFile = Globals::getCurrentImgFN();
-
-
-  int xsize, ysize;
-  ce->getImageSize ( xsize, ysize );
-
-  probabilities.reInit( xsize, ysize, cn.getMaxClassno() + 1);
-  probabilities.set ( 0.0 );
-
-  NICE::ColorImage img;
-  try {
-    img = ColorImage ( currentFile );
-  } catch ( Exception ) {
-    cerr << "SemSegNovelty: error opening image file <" << currentFile << ">" << endl;
-    return;
-  }
-
-  MultiChannelImageT<double> feats;
-
-  // extract features
-  featExtract->getFeats ( img, feats );
-  featdim = feats.channels();
-  feats.addChannel(featdim);
-
-  for (int c = 0; c < featdim; c++)
-  {
-    ImageT<double> tmp = feats[c];
-    ImageT<double> tmp2 = feats[c+featdim];
-
-    NICE::FilterT<double, double, double>::gradientStrength (tmp, tmp2);
-  }
-  featdim += featdim;
-
-  // compute integral images
-  for ( int c = 0; c < featdim; c++ )
-  {
-    feats.calcIntegral ( c );
-  }
-
-  FloatImage uncert ( xsize, ysize );
-  uncert.set ( 0.0 );
-
-  double maxunc = -numeric_limits<double>::max();
-  timer.stop();
-  cout << "first: " << timer.getLastAbsolute() << endl;
-  timer.start();
-#pragma omp parallel for
-  for ( int y = 0; y < ysize; y += testWSize )
-  {
-    Example example;
-    example.vec = NULL;
-    example.svec = new SparseVector ( featdim );
-    for ( int x = 0; x < xsize; x += testWSize)
-    {
-      for ( int f = 0; f < featdim; f++ )
-      {
-        double val = feats.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
-        if ( val > 1e-10 )
-          ( *example.svec ) [f] = val;
-      }
-      example.svec->normalize();
-
-      ClassificationResult cr = classifier->classify ( example );
-
-      int xs = std::max(0, x - testWSize/2);
-      int xe = std::min(xsize - 1, x + testWSize/2);
-      int ys = std::max(0, y - testWSize/2);
-      int ye = std::min(ysize - 1, y + testWSize/2);
-      for (int yl = ys; yl <= ye; yl++)
-      {
-        for (int xl = xs; xl <= xe; xl++)
-        {
-          for ( int j = 0 ; j < cr.scores.size(); j++ )
-          {
-            probabilities ( xl, yl, j ) = cr.scores[j];
-          }
-          segresult ( xl, yl ) = cr.classno;
-          uncert ( xl, yl ) = cr.uncertainty;
-        }
-      }
-
-      if (maxunc < cr.uncertainty)
-        maxunc = cr.uncertainty;
-      example.svec->clear();
-    }
-    delete example.svec;
-    example.svec = NULL;
-  }
-
-  cout << "maxunertainty: " << maxunc << endl;
-
-  timer.stop();
-  cout << "second: " << timer.getLastAbsolute() << endl;
-  timer.start();
-
-  ColorImage imgrgb ( xsize, ysize );
-
-  std::stringstream out;
-  std::vector< std::string > list2;
-  StringTools::split ( Globals::getCurrentImgFN (), '/', list2 );
-  out << uncertdir << "/" << list2.back();
-
-  uncert.writeRaw(out.str() + ".rawfloat");
-  uncert(0, 0) = 0.0;
-  uncert(0, 1) = 1.0;
-  ICETools::convertToRGB ( uncert, imgrgb );
-  imgrgb.write ( out.str() + "rough.png" );
-
-
-  timer.stop();
-  cout << "last: " << timer.getLastAbsolute() << endl;
-}

+ 0 - 89
semseg/SemSegNovelty.h

@@ -1,89 +0,0 @@
-/**
- * @file SemSegNovelty.h
- * @brief semantic segmentation using the method from Csurka08
- * @author Björn Fröhlich
- * @date 04/24/2009
- */
-#ifndef SemSegNoveltyINCLUDE
-#define SemSegNoveltyINCLUDE
-
-#include "SemanticSegmentation.h"
-
-#include "SemSegTools.h"
-#include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
-#include "vislearning/features/localfeatures/LFColorWeijer.h"
-
-
-/** @brief pixelwise labeling systems */
-
-namespace OBJREC {
-
-class SemSegNovelty : public SemanticSegmentation
-{
-
-  protected:
-    //! boolean whether to save the cache or not
-    bool save_cache;
-
-    //! boolean whether to read the cache or not, if read_cache is false, everything will be trained
-    bool read_cache;
-
-    //! The cached Data
-    std::string cache;
-    
-    //! Classifier
-    FeaturePoolClassifier *classifier;
-    
-    //! feature extraction
-    LFColorWeijer *featExtract;
-    
-    //! Configuration File
-    const NICE::Config *conf;
-    
-    //! distance between features for training
-    int featdist;
-    
-    //! half of the window size for local features
-    int whs;
-    
-    //! rectangle size for classification, 1 means pixelwise
-    int testWSize;
-    
-    //! name of all classes
-    ClassNames cn;
-    
-    //! set of forbidden/background classes
-    std::set<int> forbidden_classes;
-    
-    //! where to save the uncertainty
-    std::string uncertdir;
-   
-  public:
-
-    /** constructor
-      *  @param conf needs a configfile
-      *  @param md and a MultiDataset (contains images and other things)
-      */
-    SemSegNovelty ( const NICE::Config *conf, const MultiDataset *md );
-
-    /** simple destructor */
-    virtual ~SemSegNovelty();
-
-    /** 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 );
-};
-
-} //namespace
-
-#endif

+ 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

+ 70 - 18
semseg/SemanticSegmentation.cpp

@@ -10,6 +10,8 @@
 #include "SemanticSegmentation.h"
 #include "vislearning/baselib/Preprocess.h"
 #include "vislearning/baselib/Globals.h"
+#include "semseg3d/image/MultiChannelImage3DT.h"
+#include "core/basics/StringTools.h"
 
 using namespace OBJREC;
 using namespace std;
@@ -145,8 +147,7 @@ SemanticSegmentation::SemanticSegmentation ( const Config *conf,
 
   Preprocess::Init ( conf );
 
-  std::string imagetype_s = conf->gS ( "main", "imagetype", "rgb" );
-
+  std::string imagetype_s = conf->gS ( "main", "imagetype", "gray" );
   if ( imagetype_s == "rgb" )
     imagetype = IMAGETYPE_RGB;
   else if ( imagetype_s == "gray" )
@@ -161,23 +162,74 @@ SemanticSegmentation::~SemanticSegmentation()
 {
 }
 
-void SemanticSegmentation::semanticseg ( const std::string & filename,
-    NICE::Image & segresult,
-    NICE::MultiChannelImageT<double> & probabilities )
+void SemanticSegmentation::getDepthVector( const LabeledSet *Files, vector<int> & depthVec )
 {
-  Globals::setCurrentImgFN ( filename );
-  CachedExample *ce;
-  if ( imagetype == IMAGETYPE_RGB )
-  {
-    NICE::ColorImage img = Preprocess::ReadImgAdvRGB ( filename );
-    ce = new CachedExample ( img );
-  } else {
+	std::string oldName = "0";
+	int zsize = 0;
 
-    NICE::Image img = Preprocess::ReadImgAdv ( filename );
-    ce = new CachedExample ( img );
-  }
-  fprintf ( stderr, "Starting Semantic Segmentation !\n" );
-  semanticseg ( ce, segresult, probabilities );
-  delete ce;
+	LOOP_ALL_S( *Files )
+  {
+		EACH_INFO( classno, info );
+		std::string file = info.img();
+
+		std::vector< std::string > list;
+		StringTools::split (file, '/', list);
+		std::string filename = list.back();
+		uint found = filename.find_last_of("_");
+		std::string curName = filename.substr(found-1,1);
+		if ( curName.compare( oldName ) == 0 )
+		{
+			zsize++;
+		}
+		else
+		{
+			depthVec.push_back( zsize );
+			zsize = 1;
+			oldName = curName;
+		}
+
+	}
+	depthVec.push_back( zsize );
 }
 
+void SemanticSegmentation::make3DImage( const std::vector<std::string> & filelist,
+																				NICE::MultiChannelImage3DT<double> & imgData )
+{
+	bool isInit = false;
+	for( int it = 0; it < (int)filelist.size(); it++ )
+	{
+		if( imagetype == IMAGETYPE_RGB )
+		{
+			NICE::ColorImage img = Preprocess::ReadImgAdvRGB( filelist[it] );
+			if (!isInit)
+			{
+				imgData.reInit(img.width(),img.height(),filelist.size(),3);
+				isInit = true;
+			}
+			for( int y = 0; y < img.height(); y++ )
+			{
+				for( int x = 0; x < img.width(); x++ )
+				{
+					for( int r = 0; r < 3; r++)
+					{
+						imgData.set(x, y, it, img.getPixel(x,y,r), r);
+					}
+				}
+			}
+		} else {
+			NICE::Image img = Preprocess::ReadImgAdv( filelist[it] );
+			if (!isInit)
+			{
+				imgData.reInit(img.width(),img.height(),filelist.size(),1);
+				isInit = true;
+			}
+			for( int y = 0; y < img.height(); y++ )
+			{
+				for( int x = 0; x < img.width(); x++ )
+				{
+					imgData.set(x, y, it, img.getPixel(x,y), 0);
+				}
+			}
+		}
+	}
+}

+ 20 - 9
semseg/SemanticSegmentation.h

@@ -8,6 +8,8 @@
 #ifndef SEMANTICSEGMENTATIONINCLUDE
 #define SEMANTICSEGMENTATIONINCLUDE
 
+#include <vector>
+#include "semseg3d/image/MultiChannelImage3DT.h"
 #include "vislearning/cbaselib/MultiDataset.h"
 #include "vislearning/cbaselib/LocalizationResult.h"
 #include "vislearning/cbaselib/CachedExample.h"
@@ -49,15 +51,24 @@ class SemanticSegmentation
     virtual ~SemanticSegmentation();
 
     /** this function has to be overloaded by all subclasses
-        @param ce image data
+        @param imgData 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
     */
-    virtual void semanticseg ( OBJREC::CachedExample *ce,
-                               NICE::Image & segresult,
-                               NICE::MultiChannelImageT<double> & probabilities ) = 0;
+		
+		/**
+		 * collect information about the depth of 3d images
+		 * @param *Files a labeled set of data
+		 * @param depthVec output of depth values
+		 */
+		void getDepthVector( const LabeledSet *Files, std::vector<int> & depthVec );
+		
+		virtual void semanticseg ( NICE::MultiChannelImage3DT<double> & imgData,
+															 NICE::MultiChannelImageT<double> & segresult,
+															 NICE::MultiChannelImage3DT<double> & probabilities,
+															 const std::vector<std::string> & filelist ) = 0;
 
     /**
      * convert different datatypes
@@ -68,11 +79,11 @@ class SemanticSegmentation
     void convertLSetToExamples ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec );
     void convertLSetToSparseExamples ( OBJREC::Examples &examples, OBJREC::LabeledSetVector &lvec );
 
-
-    /** load img from file call localize(CachedExample *ce) etc. */
-    void semanticseg ( const std::string & filename,
-                       NICE::Image & segresult,
-                       NICE::MultiChannelImageT<double> & probabilities );
+		/** 
+		 *load image slices into a single MCI3DT 
+		 */
+		void make3DImage ( const std::vector<std::string> & filelist,
+											 NICE::MultiChannelImage3DT<double> & imgData );
 
 };
 

+ 1 - 2
semseg/libdepend.inc

@@ -1,8 +1,7 @@
 $(call PKG_DEPEND_EXT,OPENMP)
 $(call PKG_DEPEND_INT,objrec/iclassifier)
-$(call PKG_DEPEND_INT,objrec/segmentation)
+$(call PKG_DEPEND_INT,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)

+ 133 - 56
semseg/operations/Operations.cpp

@@ -10,12 +10,14 @@ Operation::Operation()
   maxtypes = 1000;
 }
 
-void Operation::set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values )
+void Operation::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, ValueAccess *_values )
 {
   x1 = _x1;
   y1 = _y1;
+	z1 = _z1;
   x2 = _x2;
   y2 = _y2;
+	z2 = _z2;
   channel1 = _channel1;
   channel2 = _channel2;
   values = _values;
@@ -41,16 +43,17 @@ int Operation::getFeatType()
   return featType;
 }
 
-void Operation::getXY ( const Features &feats, int &xsize, int &ysize )
+void Operation::getXYZ ( const Features &feats, int &xsize, int &ysize, int &zsize )
 {
   xsize = feats.feats->width();
   ysize = feats.feats->height();
+	zsize = feats.feats->depth();
 }
 
 
 void Operation::store ( std::ostream & os )
 {
-  os << x1 << " " << x2 << " " << y1 << " " << y2 << " " << channel1 << " " << channel2 << " " << featType << std::endl;
+  os << x1 << " " << x2 << " " << y1 << " " << y2 << " " << z1 << " " << z2 << " " << channel1 << " " << channel2 << " " << featType << std::endl;
   if ( values == NULL )
     os << -1 << std::endl;
   else
@@ -63,6 +66,8 @@ void Operation::restore ( std::istream &is )
   is >> x2;
   is >> y1;
   is >> y2;
+	is >> z1;
+  is >> z2;
   is >> channel1;
   is >> channel2;
   is >> featType;
@@ -94,169 +99,241 @@ void Operation::restore ( std::istream &is )
 std::string Operation::writeInfos()
 {
   std::stringstream ss;
-  ss << " x1: " << x1 << " y1: " << y1 << " x2: " << x2 << " y2: " << y2 << " c1: " << channel1 << " c2: " << channel2;
+  ss << " x1: " << x1 << " y1: " << y1 << " z1: " << z1 << " x2: " << x2 << " y2: " << y2 << " z2: " << z2 <<  " c1: " << channel1 << " c2: " << channel2;
   return ss.str();
 }
 
-double RegionFeat::getVal ( const Features &feats, const int &x, const int &y )
+double RegionFeat::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
-  return (*feats.rProbs)[(*feats.feats)(x,y,channel1)][channel2];
+  return (*feats.rProbs)[(*feats.feats)(x,y,z,channel1)][channel2];
 }
 
-double Minus::getVal ( const Features &feats, const int &x, const int &y )
+double Minus::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
-  double v1 = values->getVal ( feats, BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), channel1 );
-  double v2 = values->getVal ( feats, BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), channel2 );
+  int xsize, ysize, zsize;
+  getXYZ ( feats, xsize, ysize, zsize );
+  double v1 = values->getVal ( feats, BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), channel1 );
+  double v2 = values->getVal ( feats, BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), BOUND ( z + z2, 0, zsize - 1 ), channel2 );
   return v1 -v2;
 }
 
-double MinusAbs::getVal ( const Features &feats, const int &x, const int &y )
+double MinusAbs::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
-  double v1 = values->getVal ( feats, BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), channel1 );
-  double v2 = values->getVal ( feats, BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), channel2 );
+  int xsize, ysize, zsize;
+  getXYZ ( feats, xsize, ysize, zsize );
+  double v1 = values->getVal ( feats, BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), channel1 );
+  double v2 = values->getVal ( feats, BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), BOUND ( z + z2, 0, zsize - 1 ), channel2 );
   return abs ( v1 -v2 );
 }
 
-double Addition::getVal ( const Features &feats, const int &x, const int &y )
+double Addition::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
-  double v1 = values->getVal ( feats, BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), channel1 );
-  double v2 = values->getVal ( feats, BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize -
-                               1 ), channel2 );
+  int xsize, ysize, zsize;
+  getXYZ ( feats, xsize, ysize, zsize );
+  double v1 = values->getVal ( feats, BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), channel1 );
+  double v2 = values->getVal ( feats, BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), BOUND ( z + z2, 0, zsize - 1 ), channel2 );
   return v1 + v2;
 }
 
-double Only1::getVal ( const Features &feats, const int &x, const int &y )
+double Only1::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
-  double v1 = values->getVal ( feats, BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), channel1 );
+  int xsize, ysize, zsize;
+  getXYZ ( feats, xsize, ysize, zsize );
+  double v1 = values->getVal ( feats, BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), channel1 );
   return v1;
 }
 
-double RelativeXPosition::getVal ( const Features &feats, const int &x, const int &y )
+double RelativeXPosition::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
+  int xsize, ysize, zsize;
+  getXYZ ( feats, xsize, ysize, zsize );
   return ( double ) x / ( double ) xsize;
 }
 
-double RelativeYPosition::getVal ( const Features &feats, const int &x, const int &y )
+double RelativeYPosition::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
-  return ( double ) x / ( double ) xsize;
+  int xsize, ysize, zsize;
+  getXYZ ( feats, xsize, ysize, zsize );
+  return ( double ) y / ( double ) ysize;
+}
+
+double RelativeZPosition::getVal ( const Features &feats, const int &x, const int &y, const int &z )
+{
+  int xsize, ysize, zsize;
+  getXYZ ( feats, xsize, ysize, zsize );
+  return ( double ) z / ( double ) zsize;
+}
+
+double IntegralOps::getVal ( const Features &feats, const int &x, const int &y, const int &z )
+{
+  return feats.feats->getIntegralValue(x + x1, y + y1, z + z1, x + x2, y + y2, z + z2, channel1);
+}
+
+double GlobalFeats::getVal ( const Features &feats, const int &x, const int &y, const int &z )
+{
+  int xsize, ysize, zsize;
+  getXYZ ( feats, xsize, ysize, zsize );
+  return feats.feats->getIntegralValue( 0, 0, 0, xsize - 1, ysize - 1, zsize - 1, channel1 );
 }
 
-double IntegralOps::getVal ( const Features &feats, const int &x, const int &y )
+double IntegralCenteredOps::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
-  return feats.feats->getIntegralValue(x + x1, y + y1, x + x2, y + y2, channel1);
+  return feats.feats->getIntegralValue(x - x1, y - y1, z - z1, x + x1, y + y1, z + z1, channel1);
 }
 
-double GlobalFeats::getVal ( const Features &feats, const int &x, const int &y )
+double BiIntegralCenteredOps::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
-  return feats.feats->getIntegralValue( 0, 0, xsize - 1, ysize - 1, channel1 );
+  return feats.feats->getIntegralValue(x - x1, y - y1, z - z1, x + x1, y + y1, z + z1, channel1 ) - feats.feats->getIntegralValue(x - x2, y - y2, z - z2, x + x2, y + y2, z + z2, channel1);
+}
+
+double HaarHorizontal::getVal ( const Features &feats, const int &x, const int &y, const int &z )
+{
+  int tlx = x - x1;
+  int tly = y - y1;
+	int tlz = z - z1;
+  int lrx = x + x1;
+  int lry = y + y1;
+	int lrz = z + z1;
+
+  return feats.feats->getIntegralValue(tlx, tly, tlz, lrx, y, lrz, channel1 ) - feats.feats->getIntegralValue(tlx, y, tlz, lrx, lry, lrz, channel1);
 }
 
-double IntegralCenteredOps::getVal ( const Features &feats, const int &x, const int &y )
+double HaarVertical::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
-  return feats.feats->getIntegralValue(x - x1, y - y1, x + x1, y + y1, channel1);
+  int tlx = x - x1;
+  int tly = y - y1;
+	int tlz = z - z1;
+  int lrx = x + x1;
+  int lry = y + y1;
+	int lrz = z + z1;
+
+  return feats.feats->getIntegralValue(tlx, tly, tlz, x, lry, lrz, channel1) - feats.feats->getIntegralValue(x, tly, tlz, lrx, lry, lrz, channel1);
 }
 
-double BiIntegralCenteredOps::getVal ( const Features &feats, const int &x, const int &y )
+double HaarStacked::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
-  return feats.feats->getIntegralValue(x - x1, y - y1, x + x1, y + y1, channel1 ) - feats.feats->getIntegralValue(x - x2, y - y2, x + x2, y + y2, channel1);
+  int tlx = x - x1;
+  int tly = y - y1;
+	int tlz = z - z1;
+  int lrx = x + x1;
+  int lry = y + y1;
+	int lrz = z + z1;
+
+  return feats.feats->getIntegralValue(tlx, tly, tlz, lrx, lry, z, channel1) - feats.feats->getIntegralValue(tlx, tly, z, lrx, lry, lrz, channel1);
 }
 
-double HaarHorizontal::getVal ( const Features &feats, const int &x, const int &y )
+double HaarDiagXY::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
   int tlx = x - x1;
   int tly = y - y1;
+	int tlz = z - z1;
   int lrx = x + x1;
   int lry = y + y1;
+	int lrz = z + z1;
 
-  return feats.feats->getIntegralValue(tlx, tly, lrx, y, channel1 ) - feats.feats->getIntegralValue(tlx, y, lrx, lry, channel1);
+  return feats.feats->getIntegralValue(tlx, tly, tlz, x, y, lrz, channel1) + feats.feats->getIntegralValue(x, y, tlz, lrx, lry, lrz, channel1) - feats.feats->getIntegralValue(tlx, y, tlz, x, lry, lrz, channel1) - feats.feats->getIntegralValue(x, tly, tlz, lrx, y, lrz, channel1);
 }
 
-double HaarVertical::getVal ( const Features &feats, const int &x, const int &y )
+double HaarDiagXZ::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
   int tlx = x - x1;
   int tly = y - y1;
+	int tlz = z - z1;
   int lrx = x + x1;
   int lry = y + y1;
+	int lrz = z + z1;
 
-  return feats.feats->getIntegralValue(tlx, tly, x, lry, channel1) - feats.feats->getIntegralValue(x, tly, lrx, lry, channel1);
+  return feats.feats->getIntegralValue(tlx, tly, tlz, x, lry, z, channel1) + feats.feats->getIntegralValue(x, tly, z, lrx, lry, lrz, channel1) - feats.feats->getIntegralValue(tlx, tly, z, x, lry, lrz, channel1) - feats.feats->getIntegralValue(x, tly, tlz, lrx, lry, z, channel1);
 }
 
-double HaarDiag::getVal ( const Features &feats, const int &x, const int &y )
+double HaarDiagYZ::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
   int tlx = x - x1;
   int tly = y - y1;
+	int tlz = z - z1;
   int lrx = x + x1;
   int lry = y + y1;
+	int lrz = z + z1;
 
-  return feats.feats->getIntegralValue(tlx, tly, x, y, channel1) + feats.feats->getIntegralValue(x, y, lrx, lry, channel1) - feats.feats->getIntegralValue(tlx, y, x, lry, channel1) - feats.feats->getIntegralValue(x, tly, lrx, y, channel1);
+  return feats.feats->getIntegralValue(tlx, tly, tlz, lrx, y, z, channel1) + feats.feats->getIntegralValue(tlx, y, z, lrx, lry, lrz, channel1) - feats.feats->getIntegralValue(tlx, tly, z, lrx, y, lrz, channel1) - feats.feats->getIntegralValue(tlx, y, tlz, lrx, lry, z, channel1);
 }
 
-double Haar3Horiz::getVal ( const Features &feats, const int &x, const int &y )
+double Haar3Horiz::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
   int tlx = x - x2;
   int tly = y - y2;
+	int tlz = z - z2;
   int mtly = y - y1;
   int mlry = y + y1;
   int lrx = x + x2;
   int lry = y + y2;
+	int lrz = z + z2;
 
-  return feats.feats->getIntegralValue(tlx, tly, lrx, mtly, channel1) - feats.feats->getIntegralValue(tlx, mtly, lrx, mlry, channel1) + feats.feats->getIntegralValue(tlx, mlry, lrx, lry, channel1);
+  return feats.feats->getIntegralValue(tlx, tly, tlz, lrx, mtly, lrz, channel1) - feats.feats->getIntegralValue(tlx, mtly, tlz, lrx, mlry, lrz, channel1) + feats.feats->getIntegralValue(tlx, mlry, tlz, lrx, lry, lrz, channel1);
 }
 
-double Haar3Vert::getVal ( const Features &feats, const int &x, const int &y )
+double Haar3Vert::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 {
   int tlx = x - x2;
   int tly = y - y2;
+	int tlz = z - z2;
   int mtlx = x - x1;
   int mlrx = x + x1;
   int lrx = x + x2;
   int lry = y + y2;
+	int lrz = z + z2;
+
+  return feats.feats->getIntegralValue(tlx, tly, tlz, mtlx, lry, lrz, channel1) - feats.feats->getIntegralValue(mtlx, tly, tlz, mlrx, lry, lrz, channel1) + feats.feats->getIntegralValue(mlrx, tly, tlz, lrx, lry, lrz, channel1);
+}
+
+double Haar3Stack::getVal ( const Features &feats, const int &x, const int &y, const int &z )
+{
+  int tlx = x - x2;
+  int tly = y - y2;
+	int tlz = z - z2;
+  int mtlz = z - z1;
+  int mlrz = z + z1;
+  int lrx = x + x2;
+  int lry = y + y2;
+	int lrz = z + z2;
 
-  return feats.feats->getIntegralValue(tlx, tly, mtlx, lry, channel1) - feats.feats->getIntegralValue(mtlx, tly, mlrx, lry, channel1) + feats.feats->getIntegralValue(mlrx, tly, lrx, lry, channel1);
+  return feats.feats->getIntegralValue(tlx, tly, tlz, lrx, lry, mtlz, channel1) - feats.feats->getIntegralValue(tlx, tly, mtlz, lrx, lry, mlrz, channel1) + feats.feats->getIntegralValue(tlx, tly, mlrz, lrx, lry, lrz, channel1);
 }
 
-void IntegralOps::set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values )
+void IntegralOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, ValueAccess *_values )
 {
   x1 = std::min ( _x1, _x2 );
   y1 = std::min ( _y1, _y2 );
+	z1 = std::min ( _z1, _z2 );
   x2 = std::max ( _x1, _x2 );
   y2 = std::max ( _y1, _y2 );
+	z2 = std::max ( _z1, _z2 );
   channel1 = _channel1;
   channel2 = _channel2;
   values = _values;
 }
 
-void IntegralCenteredOps::set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values )
+void IntegralCenteredOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, ValueAccess *_values )
 {
   x1 = abs ( _x1 );
   y1 = abs ( _y1 );
+	z1 = abs ( _z1 );
   x2 = abs ( _x2 );
   y2 = abs ( _y2 );
+	z2 = abs ( _z2 );
   channel1 = _channel1;
   channel2 = _channel2;
   values = _values;
 }
 
-void BiIntegralCenteredOps::set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values )
+void BiIntegralCenteredOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, ValueAccess *_values )
 {
   x1 = std::min ( abs ( _x1 ), abs ( _x2 ) );
   y1 = std::min ( abs ( _y1 ), abs ( _y2 ) );
+	z1 = std::min ( abs ( _z1 ), abs ( _z2 ) );
   x2 = std::max ( abs ( _x1 ), abs ( _x2 ) );
   y2 = std::max ( abs ( _y1 ), abs ( _y2 ) );
+	z2 = std::max ( abs ( _z1 ), abs ( _z2 ) );
   channel1 = _channel1;
   channel2 = _channel2;
   values = _values;

+ 312 - 44
semseg/operations/Operations.h

@@ -1,12 +1,13 @@
 /**
 * @file Operation.h
-* @brief abstract class for any kind of feature extraction from images
-* @author Björn Fröhlich
+* @brief abstract class for any kind of feature extraction from 3d images
+* @author Björn Fröhlich, Sven Sickert
 * @date 24.04.2012
 
 */
 
 #include "core/image/MultiChannelImageT.h"
+#include "semseg3d/image/MultiChannelImage3DT.h"
 
 #define BOUND(x,min,max) (((x)<(min))?(min):((x)>(max)?(max):(x)))
 
@@ -38,11 +39,16 @@ enum OperationTypes {
   BIINTEGRALCENT,
   HAARHORIZ,
   HAARVERT,
-  HAARDIAG,
+	HAARSTACK,
+  HAARDIAGXY,
+	HAARDIAGXZ,
+	HAARDIAGYZ,
   HAAR3HORIZ,
   HAAR3VERT,
+	HAAR3STACK,
   RELATIVEXPOSITION,
   RELATIVEYPOSITION,
+	RELATIVEZPOSITION,
   GLOBALFEATS,
   EQUALITY,
   NBOPERATIONS
@@ -90,14 +96,14 @@ class TreeNode
 };
 
 /**
- * @brief holds all necessary information for feature extraction
+ * @brief holds all necessary information for feature extraction of 3d images
  **/
 struct Features {
   /** simple features like RGB values */
-  NICE::MultiChannelImageT<double> *feats;
+  NICE::MultiChannelImage3DT<double> *feats;
 
   /** current leaf position for each pixel and each tree */
-  NICE::MultiChannelImageT<unsigned short int> *cfeats;
+  NICE::MultiChannelImage3DT<unsigned short int> *cfeats;
 
   /** amount of trees */
   int cTree;
@@ -121,10 +127,11 @@ class ValueAccess
      * @param feats see struct Features
      * @param x position of feature
      * @param y position of feature
+		 * @param z position of feature
      * @param channel position of feature
      * @return double value
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &channel ) = 0;
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z, const int &channel ) = 0;
 
     /**
      * @brief print some infos about feature type
@@ -149,17 +156,18 @@ class MCImageAccess: public ValueAccess
 
   public:
     /**
-     * @brief extract value on specific position x,y and channel;
+     * @brief extract value on specific position x,y,z and channel;
      *
      * @param feats see struct Features
      * @param x position of feature
      * @param y position of feature
+		 * @param z position of feature
      * @param channel position of feature
      * @return double value
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &channel )
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z, const int &channel )
     {
-      return feats.feats->get ( x, y, channel );
+      return feats.feats->get ( x, y, z, channel );
     }
 
     /**
@@ -187,17 +195,18 @@ class ClassificationResultAccess: public ValueAccess
 {
   public:
     /**
-     * @brief extract value on specific position x,y and channel;
+     * @brief extract value on specific position x,y,z and channel;
      *
      * @param feats see struct Features
      * @param x position of feature
      * @param y position of feature
+		 * @param z position of feature
      * @param channel position of feature
      * @return double value
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &channel )
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z, const int &channel )
     {
-      return ( *feats.tree ) [feats.cfeats->get ( x,y,feats.cTree ) ].dist[channel];
+      return ( *feats.tree ) [feats.cfeats->get ( x,y,z,feats.cTree ) ].dist[channel];
     }
 
     /**
@@ -276,7 +285,7 @@ class Operation
 {
   protected:
     /** two different points (e.g. for an rectangle or two positions), channels and size  */
-    int x1, y1, x2, y2, channel1, channel2, maxtypes;
+    int x1, y1, z1, x2, y2, z2, channel1, channel2, maxtypes;
     
     /** type of feature */
     int featType;
@@ -294,14 +303,16 @@ class Operation
      * @brief set all parameters
      * @param _x1 position 1
      * @param _y1 position 1
+		 * @param _z1 position 1
      * @param _x2 position 2
      * @param _y2 position 2
+		 * @param _z2 position 2
      * @param _channel1 channel 1
      * @param _channel2 channel 2
      * @param _values value extraction method
      * @return void nothing
      **/
-    virtual void set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values );
+    virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, ValueAccess *_values );
 
     /**
      * @brief set whether it is a context feature or not
@@ -338,9 +349,10 @@ class Operation
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y ) = 0;
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z ) = 0;
 
     /**
      * @brief virtual clone operation instead of copy constructor (copy constructor does not work)
@@ -358,9 +370,10 @@ class Operation
      * @param feats image information
      * @param xsize width
      * @param ysize height
+		 * @param zsize depth
      * @return void
      **/
-    inline void getXY ( const Features &feats, int &xsize, int &ysize );
+    inline void getXYZ ( const Features &feats, int &xsize, int &ysize, int &zsize );
 
     /**
      * @brief return operation type (for store and restor)
@@ -396,9 +409,10 @@ class RegionFeat: public Operation
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -445,9 +459,10 @@ class Minus: public Operation
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -495,9 +510,10 @@ class MinusAbs: public Operation
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -545,9 +561,10 @@ class Addition: public Operation
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -594,9 +611,10 @@ class Only1: public Operation
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -643,9 +661,10 @@ class RelativeXPosition: public Operation
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -687,9 +706,10 @@ class RelativeYPosition: public Operation
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -718,9 +738,53 @@ class RelativeYPosition: public Operation
     }
 };
 
+/**
+ * @brief get current relative z position
+ **/
+class RelativeZPosition: public Operation
+{
+  public:
+    /**
+     * @brief interface for feature computation
+     * @param feats features
+     * @param cfeats number of tree node for each pixel
+     * @param tree current tree
+     * @param x current x position
+     * @param y current y position
+		 * @param z current z position
+     * @return double distance
+     **/
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
+
+    /**
+     * @brief clone operation instead of copy constructor (copy constructor does not work)
+     **/
+    virtual Operation* clone()
+    {
+      return new RelativeZPosition();
+    }
+
+    /**
+     * @brief print some infos about operation extraction type
+     * @return string feature type
+     **/
+    virtual std::string writeInfos()
+    {
+      return "RelativeZPosition" + Operation::writeInfos();
+    }
+
+    /**
+     * @brief return operation type (for store and restor)
+     * @return OperationTypes
+     **/
+    virtual OperationTypes getOps()
+    {
+      return RELATIVEZPOSITION;
+    }
+};
 
 /**
- * @brief uses mean in a window given by (x1,y1) (x2,y2)
+ * @brief uses mean in a window given by (x1,y1,z1) (x2,y2,z2)
  **/
 class IntegralOps: public Operation
 {
@@ -729,14 +793,16 @@ class IntegralOps: public Operation
      * @brief set all parameters
      * @param _x1 position 1
      * @param _y1 position 1
+		 * @param _z1 position 1
      * @param _x2 position 2
      * @param _y2 position 2
+		 * @param _z2 position 2
      * @param _channel1 channel 1
      * @param _channel2 channel 2
      * @param _values value extraction method
      * @return void nothing
      **/
-    virtual void set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values );
+    virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, ValueAccess *_values );
 
     /**
      * @brief interface for feature computation
@@ -745,9 +811,10 @@ class IntegralOps: public Operation
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -791,9 +858,10 @@ class GlobalFeats: public IntegralOps
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -823,7 +891,7 @@ class GlobalFeats: public IntegralOps
 };
 
 /**
- * @brief uses mean of Integral image given by x1, y1 with current pixel as center
+ * @brief uses mean of Integral image given by x1, y1, z1 with current pixel as center
  **/
 class IntegralCenteredOps: public IntegralOps
 {
@@ -832,14 +900,16 @@ class IntegralCenteredOps: public IntegralOps
      * @brief set all parameters
      * @param _x1 position 1
      * @param _y1 position 1
+		 * @param _z1 position 1
      * @param _x2 position 2
      * @param _y2 position 2
+		 * @param _z2 position 2
      * @param _channel1 channel 1
      * @param _channel2 channel 2
      * @param _values value extraction method
      * @return void nothing
      **/
-    virtual void set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values );
+    virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, ValueAccess *_values );
 
     /**
      * @brief interface for feature computation
@@ -848,9 +918,10 @@ class IntegralCenteredOps: public IntegralOps
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -880,7 +951,7 @@ class IntegralCenteredOps: public IntegralOps
 };
 
 /**
- * @brief uses different of mean of Integral image given by two windows, where (x1,y1) is the width and height of window1 and (x2,y2) of window 2
+ * @brief uses different of mean of Integral image given by two windows, where (x1,y1,z1) is the width, height & depth of window1 and (x2,y2,z2) of window 2
  **/
 class BiIntegralCenteredOps: public IntegralCenteredOps
 {
@@ -889,14 +960,16 @@ class BiIntegralCenteredOps: public IntegralCenteredOps
      * @brief set all parameters
      * @param _x1 position 1
      * @param _y1 position 1
+		 * @param _z1 position 1
      * @param _x2 position 2
      * @param _y2 position 2
+		 * @param _z2 position 2
      * @param _channel1 channel 1
      * @param _channel2 channel 2
      * @param _values value extraction method
      * @return void nothing
      **/
-    virtual void set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values );
+    virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, ValueAccess *_values );
 
     /**
      * @brief interface for feature computation
@@ -905,9 +978,10 @@ class BiIntegralCenteredOps: public IntegralCenteredOps
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -951,9 +1025,10 @@ class HaarHorizontal: public IntegralCenteredOps
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -997,9 +1072,10 @@ class HaarVertical: public IntegralCenteredOps
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -1029,11 +1105,105 @@ class HaarVertical: public IntegralCenteredOps
 };
 
 /**
- * @brief diagonal Haar features
+ * @brief stacked (depth) Haar features
+ * +-
+ * +-
+ **/
+class HaarStacked: public IntegralCenteredOps
+{
+  public:
+    /**
+     * @brief interface for feature computation
+     * @param feats features
+     * @param cfeats number of tree node for each pixel
+     * @param tree current tree
+     * @param x current x position
+     * @param y current y position
+		 * @param z current z position
+     * @return double distance
+     **/
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
+
+    /**
+     * @brief clone operation instead of copy constructor (copy constructor does not work)
+     **/
+    virtual Operation* clone()
+    {
+      return new HaarStacked();
+    }
+
+    /**
+     * @brief print some infos about operation extraction type
+     * @return string feature type
+     **/
+    virtual std::string writeInfos()
+    {
+      return "HaarStacked" + Operation::writeInfos();
+    }
+
+    /**
+     * @brief return operation type (for store and restor)
+     * @return OperationTypes
+     **/
+    virtual OperationTypes getOps()
+    {
+      return HAARSTACK;
+    }
+};
+
+/**
+ * @brief x-y diagonal Haar features
+ * +-
+ * -+
+ **/
+class HaarDiagXY: public IntegralCenteredOps
+{
+  public:
+    /**
+     * @brief interface for feature computation
+     * @param feats features
+     * @param cfeats number of tree node for each pixel
+     * @param tree current tree
+     * @param x current x position
+     * @param y current y position
+		 * @param z current z position
+     * @return double distance
+     **/
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
+
+    /**
+     * @brief clone operation instead of copy constructor (copy constructor does not work)
+     **/
+    virtual Operation* clone()
+    {
+      return new HaarDiagXY();
+    }
+
+    /**
+     * @brief print some infos about operation extraction type
+     * @return string feature type
+     **/
+    virtual std::string writeInfos()
+    {
+      return "HaarDiagXY" + Operation::writeInfos();
+    }
+
+    /**
+     * @brief return operation type (for store and restor)
+     * @return OperationTypes
+     **/
+    virtual OperationTypes getOps()
+    {
+      return HAARDIAGXY;
+    }
+};
+
+/**
+ * @brief x-z diagonal Haar features
  * +-
  * -+
  **/
-class HaarDiag: public IntegralCenteredOps
+class HaarDiagXZ: public IntegralCenteredOps
 {
   public:
     /**
@@ -1043,16 +1213,17 @@ class HaarDiag: public IntegralCenteredOps
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
      **/
     virtual Operation* clone()
     {
-      return new HaarDiag();
+      return new HaarDiagXZ();
     }
 
     /**
@@ -1061,7 +1232,7 @@ class HaarDiag: public IntegralCenteredOps
      **/
     virtual std::string writeInfos()
     {
-      return "HaarDiag" + Operation::writeInfos();
+      return "HaarDiagXZ" + Operation::writeInfos();
     }
 
     /**
@@ -1070,7 +1241,54 @@ class HaarDiag: public IntegralCenteredOps
      **/
     virtual OperationTypes getOps()
     {
-      return HAARDIAG;
+      return HAARDIAGXZ;
+    }
+};
+
+/**
+ * @brief y-z diagonal Haar features
+ * +-
+ * -+
+ **/
+class HaarDiagYZ: public IntegralCenteredOps
+{
+  public:
+    /**
+     * @brief interface for feature computation
+     * @param feats features
+     * @param cfeats number of tree node for each pixel
+     * @param tree current tree
+     * @param x current x position
+     * @param y current y position
+		 * @param z current z position
+     * @return double distance
+     **/
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
+
+    /**
+     * @brief clone operation instead of copy constructor (copy constructor does not work)
+     **/
+    virtual Operation* clone()
+    {
+      return new HaarDiagYZ();
+    }
+
+    /**
+     * @brief print some infos about operation extraction type
+     * @return string feature type
+     **/
+    virtual std::string writeInfos()
+    {
+      return "HaarDiagYZ" + Operation::writeInfos();
+    }
+
+    /**
+     * @brief return operation type (for store and restor)
+     * @return OperationTypes
+     **/
+    virtual OperationTypes getOps()
+    {
+      return HAARDIAGYZ;
     }
 };
 
@@ -1091,9 +1309,10 @@ class Haar3Horiz: public BiIntegralCenteredOps
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -1138,9 +1357,10 @@ class Haar3Vert: public BiIntegralCenteredOps
      * @param tree current tree
      * @param x current x position
      * @param y current y position
+		 * @param z current z position
      * @return double distance
      **/
-    virtual double getVal ( const Features &feats, const int &x, const int &y );
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
 
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
@@ -1169,5 +1389,53 @@ class Haar3Vert: public BiIntegralCenteredOps
     }
 };
 
+/**
+ * @brief stacked Haar features
+ * +-+
+ * +-+
+ * +-+
+ */
+class Haar3Stack: public BiIntegralCenteredOps
+{
+  public:
+    /**
+     * @brief interface for feature computation
+     * @param feats features
+     * @param cfeats number of tree node for each pixel
+     * @param tree current tree
+     * @param x current x position
+     * @param y current y position
+		 * @param z current z position
+     * @return double distance
+     **/
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &z );
+
+    /**
+     * @brief clone operation instead of copy constructor (copy constructor does not work)
+     **/
+    virtual Operation* clone()
+    {
+      return new Haar3Stack();
+    }
+
+    /**
+     * @brief print some infos about operation extraction type
+     * @return string feature type
+     **/
+    virtual std::string writeInfos()
+    {
+      return "Haar3Stack" + Operation::writeInfos();
+    }
+
+    /**
+     * @brief return operation type (for store and restor)
+     * @return OperationTypes
+     **/
+    virtual OperationTypes getOps()
+    {
+      return HAAR3STACK;
+    }
+};
+
 } //end namespace
 

+ 0 - 8
semseg/postsegmentation/Makefile

@@ -1,8 +0,0 @@
-#TARGETS_FROM:=$(notdir $(patsubst %/,%,$(shell pwd)))/$(TARGETS_FROM)
-#$(info recursivly going up: $(TARGETS_FROM) ($(shell pwd)))
-
-all:
-
-%:
-	$(MAKE) TARGETS_FROM=$(notdir $(patsubst %/,%,$(shell pwd)))/$(TARGETS_FROM) -C .. $@
-

+ 0 - 103
semseg/postsegmentation/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 - 199
semseg/postsegmentation/PPGraphCut.cpp

@@ -1,199 +0,0 @@
-#include "PPGraphCut.h"
-
-#include "objrec/segmentation/RegionGraph.h"
-
-using namespace std;
-using namespace NICE;
-using namespace OBJREC;
-
-void PPGraphCut::setClassNo(int _classno)
-{
-	classno = _classno;
-
-	coocurence = new double[classno*classno];
-	
-	for(int i = 0; i < classno*classno; i++)
-	{
-		coocurence[i] = 0.0;
-	}
-
-}
-
-PPGraphCut::PPGraphCut()
-{
-	conf = new Config();
-	Init();
-}
-
-PPGraphCut::PPGraphCut(const Config *_conf):conf(_conf)
-{
-	Init();
-}
-
-void PPGraphCut::Init()
-{
-	std::string section = "PostProcess";
-}
-
-PPGraphCut::~PPGraphCut()
-{
-	
-}
-
-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));
-	}
-}
-
-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);
-}
-
-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;
-		}
-	}
-}
-
-void PPGraphCut::trainImage(Examples &regions, NICE::Matrix &mask)
-{
-	// coocurence Matrix bestimmen
-	RegionGraph g;
-	g.computeGraph(regions, mask);
-	trainImage(g);
-}
-		
-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();
-}
-
-void PPGraphCut::restore (istream & is, int format)
-{
-	
-}
-		
-void PPGraphCut::store (ostream & os, int format) const
-{
-	
-}
-
-void PPGraphCut::clear()
-{
-	
-}

+ 0 - 126
semseg/postsegmentation/PPGraphCut.h

@@ -1,126 +0,0 @@
-/**
- * @file PPGraphCut.h
- * @brief a post procession step after semantic segmentation which use a variant of GraphCut
- * @author Björn Fröhlich
- * @date 09/08/2009
-
- */
-#ifndef PPGRAPHCUTINCLUDE
-#define PPGRAPHCUTINCLUDE
-
-#include "core/image/MultiChannelImageT.h"
-
-#include "vislearning/cbaselib/CachedExample.h"
-#include "vislearning/baselib/Preprocess.h"
-#include "vislearning/baselib/Globals.h"
-
-#include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
-
-#include <vislearning/cbaselib/VectorFeature.h>
-
-#include "vislearning/cbaselib/ClassNames.h"
-
-#include "objrec/segmentation/RSMeanShift.h"
-
-#include "objrec/mrf/mrfmin/GCoptimization.h"
-
-
-namespace OBJREC
-{
-
-class PPGraphCut : public NICE::Persistent
-{
-
-  protected:
-    //! the configfile
-    const NICE::Config *conf;
-
-    //! count of classes
-    int classno;
-
-    //! Shape features
-    Examples shapefeats;
-
-    //! classifier for shape features
-    FPCRandomForests *rf;
-
-    double *coocurence;
-
-  public:
-
-    /** simple constructor */
-    PPGraphCut();
-
-    /** simple constructor */
-    PPGraphCut ( const NICE::Config *_conf );
-
-    /** simple destructor */
-    ~PPGraphCut();
-
-    /**
-     * set the count of classes
-     * @param _classno count of classes
-     */
-    void setClassNo ( int _classno );
-
-    /** initialize the RelativeLocationPrior Variables*/
-    void Init();
-
-    /**
-     * train region
-     * @param regions input regions with size and position
-     * @param mask
-     */
-    void trainImage ( Examples &regions, NICE::Matrix &mask );
-
-    /**
-     * train region
-     * @param regions input regions with size and position
-     */
-    void trainImage ( RegionGraph &regions );
-
-
-    /**
-     * finish the priors maps
-     */
-    void finishPP ( ClassNames &cn );
-
-    /**
-     * use shape pp
-     * @param regions
-     * @param mask
-     * @param probabilities probability maps for each pixel
-     */
-    void optimizeImage ( Examples &regions, NICE::Matrix &mask, NICE::MultiChannelImageT<double> & probabilities );
-
-    /**
-     * use shape pp
-     * @param regions
-     * @param mask
-     * @param probabilities for each region
-     */
-    void optimizeImage ( OBJREC::RegionGraph &regions, std::vector<std::vector<double> > & probabilities );
-
-    /**
-     * load data from an input stream
-     * @param is input stream
-     * @param format
-     */
-    void restore ( std::istream & is, int format = 0 );
-
-    /**
-     * write data to an output stream
-     * @param os outputstream
-     * @param format
-     */
-    void store ( std::ostream & os, int format = 0 ) const;
-
-    /**
-     * clear all informations
-     */
-    void clear ();
-};
-
-} //namespace
-
-#endif

+ 0 - 286
semseg/postsegmentation/PPSuperregion.cpp

@@ -1,286 +0,0 @@
-#include "PPSuperregion.h"
-
-#ifdef NICE_USELIB_ICE
-#include <core/iceconversion/convertice.h>
-#endif
-
-#include "objrec/segmentation/RegionGraph.h"
-
-using namespace std;
-using namespace NICE;
-using namespace OBJREC;
-
-PPSuperregion::PPSuperregion()
-{
-	conf = new Config();
-	Init();
-}
-
-PPSuperregion::PPSuperregion(const Config *_conf):conf(_conf)
-{
-	Init();
-}
-
-void PPSuperregion::Init()
-{
-	std::string section = "PostProcessSG";
-	rf = new FPCRandomForests( conf, "ShapeRF" );
-}
-
-PPSuperregion::~PPSuperregion()
-{
-}
-
-
-void PPSuperregion::optimizeShape(Examples &regions, NICE::Matrix &mask, NICE::MultiChannelImageT<double> & probabilities)
-{
-#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]];
-	}
-#else
-	throw("PPSuperRegion.cpp: please use ice library for this function");
-#endif
-}
-#ifdef NICE_USELIB_ICE
-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;
-		}
-	}
-}
-#endif
-
-void PPSuperregion::trainShape(Examples &regions, NICE::Matrix &mask)
-{
-#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)));
-	}
-#else
-	throw("PPSuperRegion.cpp: please use ice library for this function");
-#endif
-}
-		
-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);
-}
-
-void PPSuperregion::restore (istream & is, int format)
-{
-	
-}
-		
-void PPSuperregion::store (ostream & os, int format) const
-{
-	
-}
-
-void PPSuperregion::clear()
-{
-	
-}

+ 0 - 121
semseg/postsegmentation/PPSuperregion.h

@@ -1,121 +0,0 @@
-/**
- * @file PPSuperregion.h
- * @brief a post procession step after semantic segmentation which use a variant of Region Growing
- * @author Björn Fröhlich
- * @date 08/19/2009
-
- */
-
-#ifndef PPSUPERREGIONINCLUDE
-#define PPSUPERREGIONINCLUDE
-
-#include "core/image/MultiChannelImageT.h"
-
-#include "vislearning/cbaselib/CachedExample.h"
-#include "vislearning/baselib/Preprocess.h"
-#include "vislearning/baselib/Globals.h"
-
-#include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
-
-#include "vislearning/cbaselib/VectorFeature.h"
-
-#include "vislearning/cbaselib/ClassNames.h"
-
-#include "objrec/segmentation/RSMeanShift.h"
-
-#ifdef NICE_USELIB_ICE
-#include <image_nonvis.h>
-#endif
-
-namespace OBJREC
-{
-
-class PPSuperregion : public NICE::Persistent
-{
-
-  protected:
-    //! the configfile
-    const NICE::Config *conf;
-
-    //! count of classes
-    int classno;
-
-    //! Shape features
-    Examples shapefeats;
-
-    //! classifier for shape features
-    FPCRandomForests *rf;
-
-  public:
-
-    /** simple constructor */
-    PPSuperregion();
-
-    /** simple constructor */
-    PPSuperregion ( const NICE::Config *_conf );
-
-    /** simple destructor */
-    ~PPSuperregion();
-
-    /**
-     * set the count of classes
-     * @param _classno count of classes
-     */
-    void setClassNo ( int _classno );
-
-    /** initialize the RelativeLocationPrior Variables*/
-    void Init();
-
-    /**
-     * combines connected regions with the same label to superregions
-     * @param regions the input regions
-     * @param mask the mask for the regions
-     * @param superregions the superregions
-     * @param classes the classlabels of the superregions
-     */
-#ifdef NICE_USELIB_ICE
-    void getSuperregions ( const Examples &regions, const NICE::Matrix &mask, std::vector<ice::Region> &superregions, std::vector<int> &classes, NICE::Matrix &smask );
-#endif
-
-    /**
-     * Lerne Form der Regionen an
-     * @param regions input regions with size and position
-     * @param mask
-     */
-    void trainShape ( Examples &regions, NICE::Matrix &mask );
-
-    /**
-     * finish the priors maps
-     */
-    void finishShape ( ClassNames &cn );
-
-    /**
-     * use shape pp
-     * @param regions
-     * @param mask
-     */
-    void optimizeShape ( Examples &regions, NICE::Matrix &mask, NICE::MultiChannelImageT<double> & probabilities );
-
-    /**
-     * load data from an input stream
-     * @param is input stream
-     * @param format
-     */
-    void restore ( std::istream & is, int format = 0 );
-
-    /**
-     * write data to an output stream
-     * @param os outputstream
-     * @param format
-     */
-    void store ( std::ostream & os, int format = 0 ) const;
-
-    /**
-     * clear all informations
-     */
-    void clear ();
-};
-
-} //namespace
-
-#endif

+ 0 - 115
semseg/postsegmentation/PSSImageLevelPrior.cpp

@@ -1,115 +0,0 @@
-/**
-* @file PSSImageLevelPrior.cpp
-* @brief incorporate prior from image categorization method
-* @author Erik Rodner
-* @date 03/19/2009
-
-*/
-
-#include <iostream>
-#include <set>
-#include <assert.h>
-#include <algorithm>
-#include "PSSImageLevelPrior.h"
-
-using namespace OBJREC;
-
-using namespace std;
-
-using namespace NICE;
-
-
-
-PSSImageLevelPrior::PSSImageLevelPrior ( int imagePriorMethod, int priorK, double alphaImagePrior )
-{
-  this->imagePriorMethod = imagePriorMethod;
-  this->priorK = priorK;
-  this->alphaImagePrior = alphaImagePrior;
-}
-
-PSSImageLevelPrior::~PSSImageLevelPrior()
-{
-}
-
-void PSSImageLevelPrior::setPrior ( FullVector & prior )
-{
-  this->prior = prior;
-}
-
-void PSSImageLevelPrior::postprocess ( NICE::Image & result, NICE::MultiChannelImageT<double> & probabilities )
-{
-  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 - 51
semseg/postsegmentation/PSSImageLevelPrior.h

@@ -1,51 +0,0 @@
-/**
-* @file PSSImageLevelPrior.h
-* @brief incorporate prior from image categorization method
-* @author Erik Rodner
-* @date 03/19/2009
-
-*/
-#ifndef PSSIMAGELEVELPRIORINCLUDE
-#define PSSIMAGELEVELPRIORINCLUDE
-
-#include "PostSemSeg.h"
-#include "vislearning/math/mathbase/FullVector.h"
-
-
-namespace OBJREC
-{
-
-/** incorporate prior from image categorization method */
-class PSSImageLevelPrior : public PostSemSeg
-{
-
-  protected:
-    int imagePriorMethod;
-    FullVector prior;
-
-    int priorK;
-    double alphaImagePrior;
-
-  public:
-
-    enum
-    {
-      IMAGE_PRIOR_BEST_K = 0,
-      IMAGE_PRIOR_PSEUDOPROB
-    };
-
-    /** simple constructor */
-    PSSImageLevelPrior ( int imagePriorMethod, int priorK, double alphaImagePrior );
-
-    /** simple destructor */
-    virtual ~PSSImageLevelPrior();
-
-    void setPrior ( FullVector & prior );
-
-    void postprocess ( NICE::Image & result, NICE::MultiChannelImageT<double> & probabilities );
-};
-
-
-} // namespace
-
-#endif

+ 0 - 27
semseg/postsegmentation/PostSemSeg.cpp

@@ -1,27 +0,0 @@
-/** 
-* @file PostSemSeg.cpp
-* @brief abstract interface for post processing steps concerning semantic segmentation routines
-* @author Erik Rodner
-* @date 03/19/2009
-
-*/
-#include <iostream>
-
-#include "PostSemSeg.h"
-
-using namespace OBJREC;
-
-using namespace std;
-
-using namespace NICE;
-
-
-
-PostSemSeg::PostSemSeg()
-{
-}
-
-PostSemSeg::~PostSemSeg()
-{
-}
-

+ 0 - 38
semseg/postsegmentation/PostSemSeg.h

@@ -1,38 +0,0 @@
-/**
-* @file PostSemSeg.h
-* @brief abstract interface for post processing steps concerning semantic segmentation routines
-* @author Erik Rodner
-* @date 03/19/2009
-
-*/
-#ifndef POSTSEMSEGINCLUDE
-#define POSTSEMSEGINCLUDE
-
-#include "core/image/MultiChannelImageT.h"
-
-
-namespace OBJREC
-{
-
-/** abstract interface for post processing steps concerning semantic segmentation routines */
-class PostSemSeg
-{
-
-  protected:
-
-  public:
-
-    /** simple constructor */
-    PostSemSeg();
-
-    /** simple destructor */
-    virtual ~PostSemSeg();
-
-    virtual void postprocess ( NICE::Image & result, NICE::MultiChannelImageT<double> & probabilities ) = 0;
-
-};
-
-
-} // namespace
-
-#endif

+ 0 - 561
semseg/postsegmentation/RelativeLocationPrior.cpp

@@ -1,561 +0,0 @@
-#include "RelativeLocationPrior.h"
-
-#include "core/image/Filter.h"
-
-using namespace std;
-using namespace NICE;
-using namespace OBJREC;
-
-RelativeLocationPrior::RelativeLocationPrior()
-{
-  conf = new Config();
-  mapsize = 200;
-}
-
-RelativeLocationPrior::RelativeLocationPrior ( const Config *_conf ) : conf ( _conf )
-{
-}
-
-void RelativeLocationPrior::setClassNo ( int _classno )
-{
-  classno = _classno;
-  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);
-    tmp->setAll ( 0.0 );
-    priormaps.push_back ( tmp );
-  }
-}
-
-RelativeLocationPrior::~RelativeLocationPrior()
-{
-  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::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 );
-
-#undef DIRICHLET
-#ifdef DIRICHLET
-            old = ( old + alpha ) / ( val + classno * alpha );
-#else
-            old /= val;
-#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 );
-          }
-        }
-      }
-    }
-  }
-
-#undef VISDEBUG
-#ifdef VISDEBUG
-#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" );
-#endif
-#endif
-}
-
-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;
-  }
-}
-
-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();
-}
-
-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.channels(); j++ )
-      {
-        cout << "j: " << j << " score: " << r.scores[j] << endl;
-      }
-    }
-    regions[i].first = bestclass;
-  }
-}
-
-void RelativeLocationPrior::convertCoords ( int &x, int xsize )
-{
-  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 );
-}
-
-void RelativeLocationPrior::getFeature ( Examples &regions, NICE::MultiChannelImageT<double> & probabilities )
-{
-
-  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 )
-{
-  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
-{
-  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 ()
-{
-
-}

+ 0 - 135
semseg/postsegmentation/RelativeLocationPrior.h

@@ -1,135 +0,0 @@
-/**
- * @file RelativeLocationPrior.h
- * @brief a post procession step after semantic segmentation which use relative location priors
- * @author Björn Fröhlich
- * @date 06/10/2009
-
- */
-#ifndef RELATIVELOCATIONPRIORINCLUDE
-#define RELATIVELOCATIONPRIORINCLUDE
-
-#include "core/image/MultiChannelImageT.h"
-
-#include "vislearning/cbaselib/CachedExample.h"
-#include "vislearning/baselib/Preprocess.h"
-#include "vislearning/baselib/Globals.h"
-
-#include "vislearning/classifier/fpclassifier/logisticregression/SLR.h"
-#include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
-
-#include "vislearning/features/fpfeatures/SparseVectorFeature.h"
-
-#include "vislearning/cbaselib/ClassNames.h"
-
-namespace OBJREC
-{
-
-class RelativeLocationPrior : public NICE::Persistent
-{
-
-  protected:
-    //! the priormaps
-    std::vector<NICE::MultiChannelImageT<double> *> priormaps;
-
-    //! the configfile
-    const NICE::Config *conf;
-
-    //! count of classes
-    int classno;
-
-    //! size of the priormaps (mapsize x mapsize)
-    int mapsize;
-
-    //! convert Image coordinates to priormaps coordinates
-    void convertCoords ( int &x, int xsize );
-
-    //! the trainingsdata will be added subsequently to this object
-    Examples trainingsdata;
-
-    //! the one vs all sparse logistic classifiers
-    std::vector<SLR> classifiers;
-
-    //! dimension of the features
-    int featdim;
-
-  public:
-
-    /** simple constructor */
-    RelativeLocationPrior();
-
-    /** simple constructor */
-    RelativeLocationPrior ( const NICE::Config *_conf );
-
-    /** simple destructor */
-    ~RelativeLocationPrior();
-
-    /**
-     * set the count of classes
-     * @param _classno count of classes
-     */
-    void setClassNo ( int _classno );
-
-    /** initialize the RelativeLocationPrior Variables*/
-    void Init();
-
-    /**
-     * Bestimme aus dem Trainingsbild, die location priors maps
-     * @param regions input regions with size, position and label
-     */
-    void trainPriorsMaps ( Examples &regions, int xsize, int ysize );
-
-    /**
-     * finish the priors maps
-     */
-    void finishPriorsMaps ( ClassNames &cn );
-
-    /**
-     * Bestimme aus dem Trainingsbild, die location priors maps
-     * @param regions input regions with size and position
-     * @param probabilities the probabiltiy maps
-     */
-    void trainClassifier ( Examples &regions, NICE::MultiChannelImageT<double> & probabilities );
-
-    /**
-     * finish the classfiers
-     */
-    void finishClassifier();
-
-    /**
-     * appends the featurevector to the given example
-     * @param regions input regions with size and position
-     * @param probabilities the probabiltiy maps
-     */
-    void getFeature ( Examples &regions, NICE::MultiChannelImageT<double> & probabilities );
-
-    /**
-     * uses the rlp for reclassification
-     * @param regions
-     * @param result
-     * @param probabilities
-     */
-    void postprocess ( Examples &regions, NICE::MultiChannelImageT<double> & probabilities );
-
-    /**
-     * load data from an input stream
-     * @param is input stream
-     * @param format
-     */
-    void restore ( std::istream & is, int format = 0 );
-
-    /**
-     * write data to an output stream
-     * @param os outputstream
-     * @param format
-     */
-    void store ( std::ostream & os, int format = 0 ) const;
-
-    /**
-     * clear all informations
-     */
-    void clear ();
-};
-
-} //namespace
-
-#endif

+ 0 - 4
semseg/postsegmentation/libdepend.inc

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

Some files were not shown because too many files changed in this diff