瀏覽代碼

making classes of nice-segmentation persistent

Alexander Freytag 11 年之前
父節點
當前提交
2f00ae4f61
共有 12 個文件被更改,包括 1009 次插入81 次删除
  1. 80 0
      RSCache.cpp
  2. 25 0
      RSCache.h
  3. 125 9
      RSGraphBased.cpp
  4. 55 6
      RSGraphBased.h
  5. 152 9
      RSMarkovCluster.cpp
  6. 58 1
      RSMarkovCluster.h
  7. 182 22
      RSMeanShift.cpp
  8. 57 5
      RSMeanShift.h
  9. 138 11
      RSSlic.cpp
  10. 62 9
      RSSlic.h
  11. 16 2
      RegionSegmentationMethod.cpp
  12. 59 7
      RegionSegmentationMethod.h

+ 80 - 0
RSCache.cpp

@@ -159,3 +159,83 @@ int RSCache::segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask ) co
 
   return cn;
 }
+
+///////////////////// INTERFACE PERSISTENT /////////////////////
+// interface specific methods for store and restore
+///////////////////// INTERFACE PERSISTENT ///////////////////// 
+
+void RSCache::restore ( std::istream & is, int format )
+{
+  //delete everything we knew so far...
+  this->clear();
+  
+  
+  if ( is.good() )
+  {
+    
+    std::string tmp;
+    is >> tmp; //class name 
+    
+    if ( ! this->isStartTag( tmp, "RSCache" ) )
+    {
+      std::cerr << " WARNING - attempt to restore RSCache, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+      throw;
+    }   
+    
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "RSCache" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );     
+     
+      if ( tmp.compare("") == 0 )
+      {
+	//TODO
+        //is >> minimumRegionArea;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else
+      {
+      std::cerr << "WARNING -- unexpected RSCache object -- " << tmp << " -- for restoration... aborting" << std::endl;
+      throw;
+      }
+    }
+  }
+  else
+  {
+    std::cerr << "RSCache::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    throw;
+  }
+}
+
+void RSCache::store ( std::ostream & os, int format ) const
+{ 
+  if (os.good())
+  {
+    // show starting point
+    os << this->createStartTag( "RSCache" ) << std::endl;    
+    
+    //TODO
+    
+    // done
+    os << this->createEndTag( "RSCache" ) << std::endl;    
+  }
+  else
+  {
+    std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
+  }
+}
+
+void RSCache::clear ()
+{
+  //TODO
+}

+ 25 - 0
RSCache.h

@@ -50,6 +50,31 @@ class RSCache: public RegionSegmentationMethod
      * @return count of region
      */
     virtual int segRegions ( const NICE::ColorImage & cimg, NICE::Matrix & mask ) const;
+    
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+    // interface specific methods for store and restore
+    ///////////////////// INTERFACE PERSISTENT /////////////////////   
+    
+    /** 
+     * @brief Load object from external file (stream)
+     * @author Alexander Freytag
+     * @date 07-02-2014 ( dd-mm-yyyy )
+     */     
+    void restore ( std::istream & is, int format = 0 );
+    
+    /** 
+     * @brief Save object to external file (stream)
+     * @author Alexander Freytag
+     * @date 07-02-2014 ( dd-mm-yyyy )
+     */     
+    void store ( std::ostream & os, int format = 0 ) const;
+    
+    /** 
+     * @brief Clear object
+     * @author Alexander Freytag
+     * @date 07-02-2014 ( dd-mm-yyyy )
+     */     
+    void clear ();     
 };
 
 } // namespace

+ 125 - 9
RSGraphBased.cpp

@@ -17,25 +17,40 @@ using namespace NICE;
 using namespace OBJREC;
 using namespace felzenszwalb;
 
-RSGraphBased::RSGraphBased()
+///////////////////// ///////////////////// /////////////////////
+//                   CONSTRUCTORS / DESTRUCTORS
+///////////////////// ///////////////////// /////////////////////
+
+RSGraphBased::RSGraphBased() : RegionSegmentationMethod()
 {
-  parameter_k = 500;
-  parameter_min_size = 200;
-  parameter_sigma = 1.5;
+  this->parameter_k = 500;
+  this->parameter_min_size = 200;
+  this->parameter_sigma = 1.5;
 }
 
-RSGraphBased::RSGraphBased(const Config *conf )
+RSGraphBased::RSGraphBased( const NICE::Config * _conf )
 {
-  //thr = conf->gD( "RSGraphBased", "threshold", 5.0);
-  parameter_k = conf->gD("RSGraphBased", "k", 500);
-  parameter_min_size = conf->gI("RSGraphBased", "min_size", 200);
-  parameter_sigma = conf->gD("RSGraphBased", "sigma", 1.5);
+  this->initFromConfig ( _conf );  
 }
 
 RSGraphBased::~RSGraphBased()
 {
 }
 
+void RSGraphBased::initFromConfig( const NICE::Config* _conf, const std::string & _confSection )
+{
+  //thr = _conf->gD( _confSection, "threshold", 5.0);
+  this->parameter_k        = _conf->gD(_confSection, "k",        500);
+  this->parameter_min_size = _conf->gI(_confSection, "min_size", 200);
+  this->parameter_sigma    = _conf->gD(_confSection, "sigma",    1.5);
+}
+
+
+
+///////////////////// ///////////////////// /////////////////////
+//                      SEGMENTATION STUFF
+///////////////////// ///////////////////// //////////////////
+
 int RSGraphBased::segRegions ( const NICE::Image & img, NICE::Matrix & mask) const
 {
   NICE::ColorImage cimg(img, img, img);
@@ -91,3 +106,104 @@ int RSGraphBased::segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask
 
   return num_ccs;
 }
+
+///////////////////// INTERFACE PERSISTENT /////////////////////
+// interface specific methods for store and restore
+///////////////////// INTERFACE PERSISTENT ///////////////////// 
+
+void RSGraphBased::restore ( std::istream & is, int format )
+{
+  //delete everything we knew so far...
+  this->clear();
+  
+  
+  if ( is.good() )
+  {
+    
+    std::string tmp;
+    is >> tmp; //class name 
+    
+    if ( ! this->isStartTag( tmp, "RSGraphBased" ) )
+    {
+      std::cerr << " WARNING - attempt to restore RSGraphBased, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+      throw;
+    }   
+    
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "RSGraphBased" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );    
+     
+      if ( tmp.compare("parameter_k") == 0 )
+      {
+        is >> this->parameter_k;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("parameter_min_size") == 0 )
+      {
+        is >> this->parameter_min_size;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }      
+      else if ( tmp.compare("parameter_sigma") == 0 )
+      {
+        is >> this->parameter_sigma;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else
+      {
+      std::cerr << "WARNING -- unexpected RSGraphBased object -- " << tmp << " -- for restoration... aborting" << std::endl;
+      throw;
+      }
+    }
+  }
+  else
+  {
+    std::cerr << "RSGraphBased::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    throw;
+  }
+}
+
+void RSGraphBased::store ( std::ostream & os, int format ) const
+{ 
+  if (os.good())
+  {
+    // show starting point
+    os << this->createStartTag( "RSGraphBased" ) << std::endl;    
+
+    os << this->createStartTag( "parameter_k" ) << std::endl;
+    os << this->parameter_k << std::endl;
+    os << this->createEndTag( "parameter_k" ) << std::endl;
+    
+    os << this->createStartTag( "parameter_min_size" ) << std::endl;
+    os << this->parameter_min_size << std::endl;
+    os << this->createEndTag( "parameter_min_size" ) << std::endl;  
+
+    os << this->createStartTag( "parameter_sigma" ) << std::endl;
+    os << this->parameter_sigma << std::endl;
+    os << this->createEndTag( "parameter_sigma" ) << std::endl;  
+    
+    // done
+    os << this->createEndTag( "RSGraphBased" ) << std::endl;    
+  }
+  else
+  {
+    std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
+  }
+}
+
+void RSGraphBased::clear ()
+{
+  //TODO
+}

+ 55 - 6
RSGraphBased.h

@@ -1,7 +1,7 @@
 /**
  * @file RSGraphBased.h
  * @brief fast Segmentation Method based on Felzenszwalb2004
- * @author Björn Fröhlich
+ * @author Björn Fröhlich, Alexander Freytag
  * @date 02/22/2010
  */
 #ifndef RSGraphBasedINCLUDE
@@ -16,26 +16,50 @@ class RSGraphBased: public RegionSegmentationMethod
 {
 
   protected:
+    
+    /////////////////////////
+    /////////////////////////
+    // PROTECTED VARIABLES //
+    /////////////////////////
+    /////////////////////////
+    
     double parameter_k;
+    
     int parameter_min_size;
+    
     double parameter_sigma;
 
   public:
-    /** simple constructor */
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                   CONSTRUCTORS / DESTRUCTORS
+    ///////////////////// ///////////////////// /////////////////////
+    
+    /** default constructor */
     RSGraphBased();
 
-    /** simple constructor */
-    RSGraphBased(double t);
-
     /**
      * standard constructor
      * @param conf config file
      */
-    RSGraphBased(const NICE::Config *conf );
+    RSGraphBased( const NICE::Config * _conf );
 
     /** simple destructor */
     virtual ~RSGraphBased();
+    
+    /** 
+    * @brief Setup internal variables and objects used
+    * @author Alexander Freytag
+    * @param conf Config file to specify variable settings
+    * @param s_confSection
+    * @date 08-02-2014 ( dd-mm-yyyy )
+    */       
+    virtual void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "RSGraphBased" );     
 
+    ///////////////////// ///////////////////// /////////////////////
+    //                      SEGMENTATION STUFF
+    ///////////////////// ///////////////////// //////////////////    
+    
     /**
      * returns the regions of a given image
      * @param img input image
@@ -51,6 +75,31 @@ class RSGraphBased: public RegionSegmentationMethod
      * @return count of region
      */
     virtual int segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask) const;
+    
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+    // interface specific methods for store and restore
+    ///////////////////// INTERFACE PERSISTENT /////////////////////   
+    
+    /** 
+     * @brief Load object from external file (stream)
+     * @author Alexander Freytag
+     * @date 08-02-2014 ( dd-mm-yyyy )
+     */     
+    void restore ( std::istream & is, int format = 0 );
+    
+    /** 
+     * @brief Save object to external file (stream)
+     * @author Alexander Freytag
+     * @date 08-02-2014 ( dd-mm-yyyy )
+     */     
+    void store ( std::ostream & os, int format = 0 ) const;
+    
+    /** 
+     * @brief Clear object
+     * @author Alexander Freytag
+     * @date 08-02-2014 ( dd-mm-yyyy )
+     */     
+    void clear ();     
 };
 
 } //namespace

+ 152 - 9
RSMarkovCluster.cpp

@@ -18,18 +18,43 @@ using namespace std;
 using namespace boost::posix_time;
 #endif
 
-RSMarkovCluster::RSMarkovCluster ( const Config* conf )
+///////////////////// ///////////////////// /////////////////////
+//                   CONSTRUCTORS / DESTRUCTORS
+///////////////////// ///////////////////// /////////////////////
+
+RSMarkovCluster::RSMarkovCluster () : RegionSegmentationMethod()
+{
+  this->r = 4.5;
+  this->mu = 10.0;
+  this->p = 1.4;
+  this->chaosThreshold = 0.001;
+  this->iterations = 23;
+}
+
+RSMarkovCluster::RSMarkovCluster ( const NICE::Config * _conf )
 {
-  const string section = "MarkovCluster";
-
-  // Parameter aus der Konfigurationsdatei auslesen
-  r   = conf->gD ( section, "clusterradius", 4.5 );
-  mu   = conf->gD ( section, "edgeweight_parameter", 10.0 );
-  p   = conf->gD ( section, "inflation_parameter", 1.4 );
-  chaosThreshold  = conf->gD ( section, "chaos_threshold", 0.001 );
-  iterations = conf->gI ( section, "iterations", 23 );
+  this->initFromConfig ( _conf );
+}
+
+RSMarkovCluster::~RSMarkovCluster()
+{
+}
+
+void RSMarkovCluster::initFromConfig( const NICE::Config* _conf, const std::string & _confSection )
+{
+  //NOTE previously, the confSection defaulted to "MarkovCluster" !!!!!
+
+  this->r               = _conf->gD ( _confSection, "clusterradius",        4.5 );
+  this->mu              = _conf->gD ( _confSection, "edgeweight_parameter", 10.0 );
+  this->p               = _conf->gD ( _confSection, "inflation_parameter",  1.4 );
+  this->chaosThreshold  = _conf->gD ( _confSection, "chaos_threshold",      0.001 );
+  this->iterations      = _conf->gI ( _confSection, "iterations",           23 );
 }
 
+///////////////////// ///////////////////// /////////////////////
+//                      SEGMENTATION STUFF
+///////////////////// ///////////////////// //////////////////
+
 
 /*
  offsets = {(y,x) | norm((y,x),2)<=r}
@@ -765,4 +790,122 @@ RSMarkovCluster::printMatrix ( const NodeCentricRepMatrix& L, const RSMarkovClus
   fout.close();
 }
 
+///////////////////// INTERFACE PERSISTENT /////////////////////
+// interface specific methods for store and restore
+///////////////////// INTERFACE PERSISTENT ///////////////////// 
 
+void RSMarkovCluster::restore ( std::istream & is, int format )
+{
+  //delete everything we knew so far...
+  this->clear();
+  
+  
+  if ( is.good() )
+  {
+    
+    std::string tmp;
+    is >> tmp; //class name 
+    
+    if ( ! this->isStartTag( tmp, "RSMarkovCluster" ) )
+    {
+      std::cerr << " WARNING - attempt to restore RSMarkovCluster, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+      throw;
+    }   
+    
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "RSMarkovCluster" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );
+     
+      if ( tmp.compare("r") == 0 )
+      {
+        is >> this->r;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("mu") == 0 )
+      {
+        is >> this->mu;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }      
+      else if ( tmp.compare("p") == 0 )
+      {
+        is >> this->p;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("chaosThreshold") == 0 )
+      {
+        is >> this->chaosThreshold;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("iterations") == 0 )
+      {
+        is >> this->iterations;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }  
+      else
+      {
+      std::cerr << "WARNING -- unexpected RSMarkovCluster object -- " << tmp << " -- for restoration... aborting" << std::endl;
+      throw;
+      }
+    }
+  }
+  else
+  {
+    std::cerr << "RSMarkovCluster::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    throw;
+  }
+}
+
+void RSMarkovCluster::store ( std::ostream & os, int format ) const
+{ 
+  if (os.good())
+  {
+    // show starting point
+    os << this->createStartTag( "RSMarkovCluster" ) << std::endl;    
+
+    os << this->createStartTag( "r" ) << std::endl;
+    os << this->r << std::endl;
+    os << this->createEndTag( "r" ) << std::endl;
+    
+    os << this->createStartTag( "mu" ) << std::endl;
+    os << this->mu << std::endl;
+    os << this->createEndTag( "mu" ) << std::endl;
+    
+    os << this->createStartTag( "p" ) << std::endl;
+    os << this->p << std::endl;
+    os << this->createEndTag( "p" ) << std::endl;  
+
+    os << this->createStartTag( "chaosThreshold" ) << std::endl;
+    os << this->chaosThreshold << std::endl;
+    os << this->createEndTag( "chaosThreshold" ) << std::endl;  
+
+    os << this->createStartTag( "iterations" ) << std::endl;
+    os << this->iterations << std::endl;
+    os << this->createEndTag( "iterations" ) << std::endl;  
+    
+    // done
+    os << this->createEndTag( "RSMarkovCluster" ) << std::endl;    
+  }
+  else
+  {
+    std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
+  }
+}
+
+void RSMarkovCluster::clear ()
+{
+}

+ 58 - 1
RSMarkovCluster.h

@@ -1,6 +1,13 @@
 #ifndef RSMARKOVCLUSTER
 #define RSMARKOVCLUSTER
 
+/**
+ * @file RSMarkovCluster.h
+ * @brief ...
+ * @author Björn Fröhlich, Alexander Freytag
+ * @date ???
+ */
+
 #include <core/vector/VectorT.h>
 #include <core/basics/Config.h>
 #include <segmentation/math/NodeCentricRepMatrix.h>
@@ -73,11 +80,36 @@ class RSMarkovCluster : public RegionSegmentationMethod
 
     /* Membermethoden und -variablen */
   public:
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                   CONSTRUCTORS / DESTRUCTORS
+    ///////////////////// ///////////////////// /////////////////////
+    
+    /**
+     * @brief default constructor 
+     * @author Alexander Freytag
+     * @date 08-02-2014 ( dd-mm-yyyy )
+     */
+    RSMarkovCluster();    
+    
     //! Standard-Konstruktor
     RSMarkovCluster ( const NICE::Config* conf );
 
     //! Standard-Destruktor
-    virtual ~RSMarkovCluster() {};
+    virtual ~RSMarkovCluster();
+    
+    /** 
+    * @brief Setup internal variables and objects used
+    * @author Alexander Freytag
+    * @param conf Config file to specify variable settings
+    * @param s_confSection
+    * @date 08-02-2014 ( dd-mm-yyyy )
+    */       
+    virtual void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "RSMarkovCluster" );      
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                      SEGMENTATION STUFF
+    ///////////////////// ///////////////////// //////////////////    
 
     /* Ueberschriebene Methoden */
     /**
@@ -167,6 +199,31 @@ class RSMarkovCluster : public RegionSegmentationMethod
     * @brief Ausgabe der Matrix in eine Datei. VORSICHT: nur fuer sehr kleine Bilder anwenden.
     */
     void printMatrix ( const OBJREC::NodeCentricRepMatrix& L, const Offsets& offsets, const std::string& filename ) const;
+    
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+    // interface specific methods for store and restore
+    ///////////////////// INTERFACE PERSISTENT /////////////////////   
+    
+    /** 
+     * @brief Load object from external file (stream)
+     * @author Alexander Freytag
+     * @date 08-02-2014 ( dd-mm-yyyy )
+     */     
+    void restore ( std::istream & is, int format = 0 );
+    
+    /** 
+     * @brief Save object to external file (stream)
+     * @author Alexander Freytag
+     * @date 08-02-2014 ( dd-mm-yyyy )
+     */     
+    void store ( std::ostream & os, int format = 0 ) const;
+    
+    /** 
+     * @brief Clear object
+     * @author Alexander Freytag
+     * @date 08-02-2014 ( dd-mm-yyyy )
+     */     
+    void clear ();     
 
 };
 }

+ 182 - 22
RSMeanShift.cpp

@@ -12,38 +12,70 @@
 using namespace std;
 using namespace NICE;
 using namespace OBJREC;
-RSMeanShift::RSMeanShift()
-{
-  minimumRegionArea = 50;
-  rangeBandwidth = 6.5;
-
-  spatialBandwidth = 7;
 
-  imageProc = new msImageProcessor();
-  speedUpLevel =  MED_SPEEDUP;
-}
-RSMeanShift::RSMeanShift ( const Config *conf )
+void RSMeanShift::setSpeedUpLevel( const string& _speedUpLevelString )
 {
-  imageProc = new msImageProcessor();
-  minimumRegionArea = conf->gI ( "RSMeanShift", "MinimumRegionArea",            50 );
-  rangeBandwidth    = conf->gD ( "RSMeanShift", "RangeBandwidth",              6.5 );
-  spatialBandwidth  = conf->gI ( "RSMeanShift", "SpatialBandwidth",              7 );
-  speedUpLvlStr     = conf->gS ( "RSMeanShift", "SpeedUpLevel",           "MEDIUM" );
-  if ( speedUpLvlStr ==   "NONE" ) speedUpLevel =   NO_SPEEDUP;
-  else if ( speedUpLvlStr == "MEDIUM" ) speedUpLevel =  MED_SPEEDUP;
-  else if ( speedUpLvlStr ==   "HIGH" ) speedUpLevel = HIGH_SPEEDUP;
+  if ( speedUpLvlString ==   "NONE" )
+    this->speedUpLevel =   NO_SPEEDUP;
+  else if ( speedUpLvlString == "MEDIUM" ) 
+    this->speedUpLevel =  MED_SPEEDUP;
+  else if ( speedUpLvlString ==   "HIGH" )
+    this->speedUpLevel = HIGH_SPEEDUP;
   else
   {
-    cerr << "[err] RSMeanShift::RSMeanShift: Wrong SpeedUpLevel-Value (" << speedUpLvlStr << ") only NONE, MEDIUM and HIGH allowed! Take default Value (MED_SPEEDUP)" << endl;
-    speedUpLevel = MED_SPEEDUP;
+    std::cerr << "[err] RSMeanShift::RSMeanShift: Wrong SpeedUpLevel-Value (" << speedUpLvlString << ") only NONE, MEDIUM and HIGH allowed! Take default Value (MED_SPEEDUP)" << std::endl;
+    this->speedUpLevel = MED_SPEEDUP;
   }
 }
 
+///////////////////// ///////////////////// /////////////////////
+//                   CONSTRUCTORS / DESTRUCTORS
+///////////////////// ///////////////////// /////////////////////
+
+
+RSMeanShift::RSMeanShift() : RegionSegmentationMethod()
+{
+  this->minimumRegionArea = 50;
+  this->rangeBandwidth = 6.5;
+
+  this->spatialBandwidth = 7;
+
+  this->imageProc = new msImageProcessor();
+  this->speedUpLvlString = "MEDIUM";
+  this->setSpeedUpLevel( this->speedUpLvlString );
+}
+
+RSMeanShift::RSMeanShift ( const Config * _conf )
+{
+    this->initFromConfig( _conf );
+}
+
 RSMeanShift::~RSMeanShift()
 {
-  delete imageProc;
+  if ( this->imageProc != NULL )
+    delete imageProc;
+  this->imageProc = NULL;
+}
+
+void RSMeanShift::initFromConfig( const NICE::Config* _conf, const std::string & _confSection )
+{
+  //first, call method for parent object
+  OBJREC::RegionSegmentationMethod::initFromConfig( _conf );
+    
+  //now set own member variables
+  this->imageProc = new msImageProcessor();
+  this->minimumRegionArea = _conf->gI ( _confSection, "MinimumRegionArea",            50 );
+  this->rangeBandwidth    = _conf->gD ( _confSection, "RangeBandwidth",              6.5 );
+  this->spatialBandwidth  = _conf->gI ( _confSection, "SpatialBandwidth",              7 );
+  this->speedUpLvlString  = _conf->gS ( _confSection, "SpeedUpLevel",           "MEDIUM" );
+  this->setSpeedUpLevel( this->speedUpLvlString );    
 }
 
+
+///////////////////// ///////////////////// /////////////////////
+//                      SEGMENTATION STUFF
+///////////////////// ///////////////////// ////////////////// 
+
 int RSMeanShift::segRegions ( const NICE::Image & img, NICE::Matrix & mask ) const
 {
   ColorImage cimg ( img, img, img );
@@ -108,7 +140,7 @@ int RSMeanShift::segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask
   delete[] rawImageData;
   rawImageData = 0;
 
-  ColorImage ippTempImage ( width, height );
+  NICE::ColorImage ippTempImage ( width, height );
 
   x = y = 0;
 
@@ -129,3 +161,131 @@ int RSMeanShift::segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask
   return transformSegmentedImg ( ColorImage ( resultRawImageData, width, height, GrayColorImageCommonImplementation::noAlignment ), mask );
 #endif
 }
+
+///////////////////// INTERFACE PERSISTENT /////////////////////
+// interface specific methods for store and restore
+///////////////////// INTERFACE PERSISTENT ///////////////////// 
+
+void RSMeanShift::restore ( std::istream & is, int format )
+{
+  //delete everything we knew so far...
+  this->clear();
+  
+  
+  if ( is.good() )
+  {
+    
+    std::string tmp;
+    is >> tmp; //class name 
+    
+    if ( ! this->isStartTag( tmp, "RSMeanShift" ) )
+    {
+      std::cerr << " WARNING - attempt to restore RSMeanShift, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+      throw;
+    }   
+    
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "RSMeanShift" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );     
+     
+      if ( tmp.compare("minimumRegionArea") == 0 )
+      {
+        is >> minimumRegionArea;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("rangeBandwidth") == 0 )
+      {
+        is >> rangeBandwidth;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("spatialBandwidth") == 0 )
+      {
+        is >> spatialBandwidth;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }      
+      else if ( tmp.compare("imageProc") == 0 )
+      {
+	//nothing to read actually :)
+	imageProc = new msImageProcessor();
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("speedUpLvlString") == 0 )
+      {
+        is >> speedUpLvlString;
+	this->setSpeedUpLevel( this->speedUpLvlString );
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else
+      {
+      std::cerr << "WARNING -- unexpected RSMeanShift object -- " << tmp << " -- for restoration... aborting" << std::endl;
+      throw;
+      }
+    }
+  }
+  else
+  {
+    std::cerr << "RSMeanShift::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    throw;
+  }
+}
+
+void RSMeanShift::store ( std::ostream & os, int format ) const
+{ 
+  if (os.good())
+  {
+    // show starting point
+    os << this->createStartTag( "RSMeanShift" ) << std::endl;    
+    
+       
+    os << this->createStartTag( "minimumRegionArea" ) << std::endl;
+    os << this->minimumRegionArea << std::endl;
+    os << this->createEndTag( "minimumRegionArea" ) << std::endl; 
+   
+    os << this->createStartTag( "rangeBandwidth" ) << std::endl;
+    os << this->rangeBandwidth << std::endl;
+    os << this->createEndTag( "rangeBandwidth" ) << std::endl; 
+    
+    os << this->createStartTag( "spatialBandwidth" ) << std::endl;
+    os << this->spatialBandwidth << std::endl;
+    os << this->createEndTag( "spatialBandwidth" ) << std::endl; 
+
+    os << this->createStartTag( "imageProc" ) << std::endl;
+    //nothing to write actually :)
+    os << this->createEndTag( "imageProc" ) << std::endl; 
+
+    os << this->createStartTag( "speedUpLvlString" ) << std::endl;
+    os << this->speedUpLvlString << std::endl;
+    os << this->createEndTag( "speedUpLvlString" ) << std::endl;    
+  
+    
+    
+    // done
+    os << this->createEndTag( "RSMeanShift" ) << std::endl;    
+  }
+  else
+  {
+    std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
+  }
+}
+
+void RSMeanShift::clear ()
+{
+  if ( this->imageProc != NULL )
+    delete imageProc;
+  this->imageProc = NULL;  
+}

+ 57 - 5
RSMeanShift.h

@@ -1,7 +1,7 @@
 /**
  * @file RSMeanShift.h
  * @brief implementation of the MeanShift algorithm (uses EDISON)
- * @author Björn Fröhlich
+ * @author Björn Fröhlich, Alexander Freytag
  * @date 05/05/2009
  */
 #ifndef RSMEANSHIFT
@@ -19,6 +19,12 @@ class RSMeanShift: public RegionSegmentationMethod
 {
 
   protected:
+    
+    /////////////////////////
+    /////////////////////////
+    // PROTECTED VARIABLES //
+    /////////////////////////
+    /////////////////////////    
     //! Specifies the minimum allowable region area (in pixels) contained in the segmented image
     int minimumRegionArea;
 
@@ -29,25 +35,46 @@ class RSMeanShift: public RegionSegmentationMethod
     int spatialBandwidth;
 
     //! Specifies the SpeedUpLevel. See EDISON Manual for details.
-    std::string speedUpLvlStr;
+    std::string speedUpLvlString;
     SpeedUpLevel speedUpLevel;
 
     //! EDISON - ImageProcessor
     msImageProcessor *imageProc;
+    
+    
+    void setSpeedUpLevel ( const std::string & _speedUpLevelString );
 
   public:
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                   CONSTRUCTORS / DESTRUCTORS
+    ///////////////////// ///////////////////// /////////////////////     
     /** simple constructor */
     RSMeanShift();
 
     /**
-     * standard constructor
+     * @brief standard constructor, calls this->initFromConfig
      * @param conf config file
+     * @author Bjoern Froehlich, Alexander Freytag
      */
-    RSMeanShift(const NICE::Config *conf );
+    RSMeanShift(const NICE::Config * _conf );
 
     /** simple destructor */
     virtual ~RSMeanShift();
-
+    
+    /** 
+    * @brief Setup internal variables and objects used
+    * @author Alexander Freytag
+    * @param conf Config file to specify variable settings
+    * @param s_confSection
+    * @date 07-02-2014 ( dd-mm-yyyy )
+    */       
+    virtual void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "RSMeanShift" );    
+
+    ///////////////////// ///////////////////// /////////////////////
+    //                      SEGMENTATION STUFF
+    ///////////////////// ///////////////////// //////////////////     
+    
     /**
      * returns the regions of a given image
      * @param img input image
@@ -63,6 +90,31 @@ class RSMeanShift: public RegionSegmentationMethod
      * @return count of region
      */
     int segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask ) const;
+    
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+    // interface specific methods for store and restore
+    ///////////////////// INTERFACE PERSISTENT /////////////////////   
+    
+    /** 
+     * @brief Load object from external file (stream)
+     * @author Alexander Freytag
+     * @date 07-02-2014 ( dd-mm-yyyy )
+     */     
+    void restore ( std::istream & is, int format = 0 );
+    
+    /** 
+     * @brief Save object to external file (stream)
+     * @author Alexander Freytag
+     * @date 07-02-2014 ( dd-mm-yyyy )
+     */     
+    void store ( std::ostream & os, int format = 0 ) const;
+    
+    /** 
+     * @brief Clear object
+     * @author Alexander Freytag
+     * @date 07-02-2014 ( dd-mm-yyyy )
+     */     
+    void clear ();    
 };
 
 } //namespace

+ 138 - 11
RSSlic.cpp

@@ -13,26 +13,43 @@ using namespace std;
 using namespace NICE;
 using namespace OBJREC;
 
-RSSlic::RSSlic()
+///////////////////// ///////////////////// /////////////////////
+//                   CONSTRUCTORS / DESTRUCTORS
+///////////////////// ///////////////////// /////////////////////
+
+RSSlic::RSSlic() : RegionSegmentationMethod()
 {
-  spcount = -1;
-  regionsize = 50;
-  compactness = 10.0;
-  lab = true;
+  this->spcount = -1;
+  this->regionsize = 50;
+  this->compactness = 10.0;
+  this->b_lab = true;
 }
 
-RSSlic::RSSlic(const Config *conf )
+RSSlic::RSSlic( const NICE::Config * _conf )
 {
-  spcount = conf->gI("RSSlic", "spcount", -1);
-  regionsize = conf->gI("RSSlic", "regionsize", 50);
-  compactness = conf->gD("RSSlic", "compactness", 10.0);
-  lab = conf->gB("RSSlic", "useLAB", true);
+  this->initFromConfig( _conf );
 }
 
 RSSlic::~RSSlic()
 {
 }
 
+void RSSlic::initFromConfig(const NICE::Config* _conf, const std::string & _confSection )
+{
+  //first, call method for parent object
+  OBJREC::RegionSegmentationMethod::initFromConfig( _conf );
+    
+  //now set own member variables
+  this->spcount     = _conf->gI( _confSection, "spcount",     -1);
+  this->regionsize  = _conf->gI( _confSection, "regionsize",  50);
+  this->compactness = _conf->gD( _confSection, "compactness", 10.0);
+  this->b_lab       = _conf->gB( _confSection, "useLAB",      true);
+}
+
+///////////////////// ///////////////////// /////////////////////
+//                      SEGMENTATION STUFF
+///////////////////// ///////////////////// ////////////////// 
+
 int RSSlic::segRegions ( const NICE::Image & img, NICE::Matrix & mask) const
 {
   cerr << "not implemented yet" << endl;
@@ -75,7 +92,7 @@ int RSSlic::segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask) cons
     superpixelsize = 0.5+double(imageWidth*imageHeight)/double(spcount);
   }
    
-  slic.DoSuperpixelSegmentation_ForGivenSuperpixelSize(inputImage, imageWidth, imageHeight, labels, numlabels, superpixelsize, compactness, lab);
+  slic.DoSuperpixelSegmentation_ForGivenSuperpixelSize(inputImage, imageWidth, imageHeight, labels, numlabels, superpixelsize, compactness, b_lab);
 
   mask.resize(imageWidth, imageHeight);
   counter = 0;
@@ -109,3 +126,113 @@ int RSSlic::segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask) cons
 
   return numlabels;
 }
+
+///////////////////// INTERFACE PERSISTENT /////////////////////
+// interface specific methods for store and restore
+///////////////////// INTERFACE PERSISTENT ///////////////////// 
+
+void RSSlic::restore ( std::istream & is, int format )
+{
+  //delete everything we knew so far...
+  this->clear();
+  
+  
+  if ( is.good() )
+  {
+    
+    std::string tmp;
+    is >> tmp; //class name 
+    
+    if ( ! this->isStartTag( tmp, "RSSlic" ) )
+    {
+      std::cerr << " WARNING - attempt to restore RSSlic, but start flag " << tmp << " does not match! Aborting... " << std::endl;
+      throw;
+    }   
+    
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
+    {
+      is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "RSSlic" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }      
+      
+      tmp = this->removeStartTag ( tmp );     
+      
+      if ( tmp.compare("spcount") == 0 )
+      {
+        is >> this->spcount;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("regionsize") == 0 )
+      {
+        is >> this->regionsize;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("compactness") == 0 )
+      {
+        is >> this->compactness;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }
+      else if ( tmp.compare("b_lab") == 0 )
+      {
+        is >> this->b_lab;
+        is >> tmp; // end of block 
+        tmp = this->removeEndTag ( tmp );
+      }      
+      else
+      {
+      std::cerr << "WARNING -- unexpected RSSlic object -- " << tmp << " -- for restoration... aborting" << std::endl;
+      throw;
+      }
+    }
+  }
+  else
+  {
+    std::cerr << "RSSlic::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    throw;
+  }
+}
+
+void RSSlic::store ( std::ostream & os, int format ) const
+{ 
+  if (os.good())
+  {
+    // show starting point
+    os << this->createStartTag( "RSSlic" ) << std::endl;    
+  
+    os << this->createStartTag( "spcount" ) << std::endl;
+    os << this->spcount << std::endl;
+    os << this->createEndTag( "spcount" ) << std::endl;
+    
+    os << this->createStartTag( "regionsize" ) << std::endl;
+    os << this->regionsize << std::endl;
+    os << this->createEndTag( "regionsize" ) << std::endl;  
+
+    os << this->createStartTag( "compactness" ) << std::endl;
+    os << this->compactness << std::endl;
+    os << this->createEndTag( "compactness" ) << std::endl;  
+
+    os << this->createStartTag( "b_lab" ) << std::endl;
+    os << this->b_lab << std::endl;
+    os << this->createEndTag( "b_lab" ) << std::endl;      
+    
+    // done
+    os << this->createEndTag( "RSSlic" ) << std::endl;    
+  }
+  else
+  {
+    std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
+  }
+}
+
+void RSSlic::clear ()
+{
+}

+ 62 - 9
RSSlic.h

@@ -1,7 +1,7 @@
 /**
  * @file RSSlic.h
  * @brief SLIC Superpixels from "SLIC Superpixels Compared to State-of-the-art Superpixel Methods,"
- * @author Björn Fröhlich
+ * @author Björn Fröhlich, Alexander Freytag
  * @date 02/02/2013
  */
 #ifndef RSSlicINCLUDE
@@ -16,26 +16,54 @@ class RSSlic: public RegionSegmentationMethod
 {
 
 protected:
-    int spcount; //number of regions
-    double compactness; //value between 0 and 40
-    int regionsize; //average size of each region
-    bool lab; //use lab space or not
+  
+    /////////////////////////
+    /////////////////////////
+    // PROTECTED VARIABLES //
+    /////////////////////////
+    /////////////////////////
+  
+    //!number of regions
+    int spcount; 
+    
+    //!value between 0 and 40
+    double compactness; 
+    
+    //!average size of each region
+    int regionsize;
+    
+    //!use lab space or not
+    bool b_lab; 
 
 public:
+  
+    ///////////////////// ///////////////////// /////////////////////
+    //                   CONSTRUCTORS / DESTRUCTORS
+    ///////////////////// ///////////////////// /////////////////////   
     /** simple constructor */
     RSSlic();
 
-    /** simple constructor */
-    RSSlic(double t);
-
     /**
      * standard constructor
      * @param conf config file
      */
-    RSSlic(const NICE::Config *conf );
+    RSSlic( const NICE::Config * _conf );
 
     /** simple destructor */
     virtual ~RSSlic();
+    
+    /** 
+    * @brief Setup internal variables and objects used
+    * @author Alexander Freytag
+    * @param conf Config file to specify variable settings
+    * @param s_confSection
+    * @date 08-02-2014 ( dd-mm-yyyy )
+    */       
+    virtual void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "RSSlic" );    
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                      SEGMENTATION STUFF
+    ///////////////////// ///////////////////// //////////////////     
 
     /**
      * returns the regions of a given image
@@ -52,6 +80,31 @@ public:
      * @return count of region
      */
     virtual int segRegions ( const NICE::ColorImage & img, NICE::Matrix & mask) const;
+    
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+    // interface specific methods for store and restore
+    ///////////////////// INTERFACE PERSISTENT /////////////////////   
+    
+    /** 
+     * @brief Load object from external file (stream)
+     * @author Alexander Freytag
+     * @date 08-02-2014 ( dd-mm-yyyy )
+     */     
+    void restore ( std::istream & is, int format = 0 );
+    
+    /** 
+     * @brief Save object to external file (stream)
+     * @author Alexander Freytag
+     * @date 08-02-2014 ( dd-mm-yyyy )
+     */     
+    void store ( std::ostream & os, int format = 0 ) const;
+    
+    /** 
+     * @brief Clear object
+     * @author Alexander Freytag
+     * @date 08-02-2014 ( dd-mm-yyyy )
+     */     
+    void clear ();     
 };
 
 } //namespace

+ 16 - 2
RegionSegmentationMethod.cpp

@@ -14,9 +14,10 @@ RegionSegmentationMethod::RegionSegmentationMethod()
 
 }
 
-RegionSegmentationMethod::RegionSegmentationMethod ( const Config *c )
+RegionSegmentationMethod::RegionSegmentationMethod ( const NICE::Config * _conf )
 {
-  conf = c;
+//   conf = c;
+  this->initFromConfig ( _conf );
 }
 
 RegionSegmentationMethod::~RegionSegmentationMethod()
@@ -24,6 +25,11 @@ RegionSegmentationMethod::~RegionSegmentationMethod()
 
 }
 
+void RegionSegmentationMethod::initFromConfig ( const NICE::Config * _conf, const std::string & _confSection )
+{
+  //nothing to do here
+}
+
 //überprüfe, ob Elterpixel neugelabelt wurde, wenn ja dann label auch Kind neu
 inline int rootOf ( int *l, int j )
 {
@@ -35,6 +41,10 @@ inline int rootOf ( int *l, int j )
   return j;
 }
 
+///////////////////// ///////////////////// /////////////////////
+//                      SEGMENTATION STUFF
+///////////////////// ///////////////////// ////////////////// 
+
 int RegionSegmentationMethod::transformSegmentedImg ( const NICE::ColorImage & img, NICE::Matrix & mask ) const
 {
   int xsize = img.width();
@@ -177,6 +187,10 @@ int RegionSegmentationMethod::transformSegmentedImg ( const NICE::ColorImage & i
   return size;
 }
 
+///////////////////// ///////////////////// /////////////////////
+//                         GET / SET
+///////////////////// ///////////////////// /////////////////////  
+
 void RegionSegmentationMethod::getGraphRepresentation ( const NICE::ColorImage & cimg, NICE::Matrix & mask, RegionGraph & rg )
 {
   int regioncount = segRegions ( cimg, mask );

+ 59 - 7
RegionSegmentationMethod.h

@@ -1,16 +1,21 @@
 /**
  * @file RegionSegmentationMethod.h
  * @brief abstract interface for region segmantation
- * @author Björn Fröhlich
+ * @author Björn Fröhlich, Alexander Freytag
  * @date 05/05/2009
  */
 #ifndef REGIONSEGMENTATIONMETHOD
 #define REGIONSEGMENTATIONMETHOD
 
-#include "core/basics/Config.h"
-
+// STL includes
 #include <vector>
 
+// NICE-core includes
+#include <core/basics/Config.h>
+#include <core/basics/Persistent.h>
+
+
+
 #undef DEBUGRS
 
 #include "RegionGraph.h"
@@ -19,23 +24,45 @@
 
 namespace OBJREC {
 
-class RegionSegmentationMethod
+class RegionSegmentationMethod : public NICE::Persistent
 {
 
   protected:
-    const NICE::Config *conf;
+    /////////////////////////
+    /////////////////////////
+    // PROTECTED VARIABLES //
+    /////////////////////////
+    /////////////////////////    
+//     const NICE::Config *conf;
 
   public:
+    
+    ///////////////////// ///////////////////// /////////////////////
+    //                   CONSTRUCTORS / DESTRUCTORS
+    ///////////////////// ///////////////////// /////////////////////     
 
     /** simple constructor */
     RegionSegmentationMethod();
 
     /** simple constructor */
-    RegionSegmentationMethod(const NICE::Config *c );
+    RegionSegmentationMethod( const NICE::Config *c );
 
     /** simple destructor */
     virtual ~RegionSegmentationMethod();
-
+    
+    /** 
+    * @brief Setup internal variables and objects used
+    * @author Alexander Freytag
+    * @param conf Config file to specify variable settings
+    * @param s_confSection
+    * @date 07-02-2014 ( dd-mm-yyyy )
+    */       
+    virtual void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "RegionSegmentation" );
+
+    ///////////////////// ///////////////////// /////////////////////
+    //                      SEGMENTATION STUFF
+    ///////////////////// ///////////////////// //////////////////    
+    
     /**
      * returns the regions of a given image
      * @param img input image
@@ -95,6 +122,31 @@ class RegionSegmentationMethod
      * @param mask result mask of the regions
      */
     void visualizeGraphRepresentation(const NICE::ColorImage & cimg, NICE::Matrix & mask);
+
+    ///////////////////// INTERFACE PERSISTENT /////////////////////
+    // interface specific methods for store and restore
+    ///////////////////// INTERFACE PERSISTENT /////////////////////   
+    
+    /** 
+     * @brief Load object from external file (stream)
+     * @author Alexander Freytag
+     * @date 07-02-2014 ( dd-mm-yyyy )
+     */     
+    void restore ( std::istream & is, int format = 0 ) = 0;
+    
+    /** 
+     * @brief Save object to external file (stream)
+     * @author Alexander Freytag
+     * @date 07-02-2014 ( dd-mm-yyyy )
+     */     
+    void store ( std::ostream & os, int format = 0 ) const = 0;
+    
+    /** 
+     * @brief Clear object
+     * @author Alexander Freytag
+     * @date 07-02-2014 ( dd-mm-yyyy )
+     */     
+    void clear () = 0; 
 };