|
@@ -1,8 +1,8 @@
|
|
|
/**
|
|
|
* @file SemanticSegmentation.cpp
|
|
|
* @brief abstract interface for semantic segmentation algorithms
|
|
|
-* @author Erik Rodner
|
|
|
-* @date 03/19/2009
|
|
|
+* @author Erik Rodner, Alexander Freytag
|
|
|
+* @date 03/19/2009, latest update: 29-01-2014 (dd-mm-yyyy)
|
|
|
|
|
|
*/
|
|
|
#include <iostream>
|
|
@@ -15,6 +15,63 @@ using namespace OBJREC;
|
|
|
using namespace std;
|
|
|
using namespace NICE;
|
|
|
|
|
|
+
|
|
|
+ ///////////////////// ///////////////////// /////////////////////
|
|
|
+ // CONSTRUCTORS / DESTRUCTORS
|
|
|
+ ///////////////////// ///////////////////// /////////////////////
|
|
|
+
|
|
|
+SemanticSegmentation::SemanticSegmentation ( const Config *conf,
|
|
|
+ const ClassNames *classNames )
|
|
|
+{
|
|
|
+ this->classNames = classNames;
|
|
|
+
|
|
|
+ Preprocess::Init ( conf );
|
|
|
+
|
|
|
+ std::string imagetype_s = conf->gS ( "main", "imagetype", "rgb" );
|
|
|
+
|
|
|
+ if ( imagetype_s == "rgb" )
|
|
|
+ imagetype = IMAGETYPE_RGB;
|
|
|
+ else if ( imagetype_s == "gray" )
|
|
|
+ imagetype = IMAGETYPE_GRAY;
|
|
|
+ else {
|
|
|
+ fprintf ( stderr, "SemanticSegmentation:: unknown image type option\n" );
|
|
|
+ exit ( -1 );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+SemanticSegmentation::~SemanticSegmentation()
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ ///////////////////// ///////////////////// /////////////////////
|
|
|
+ // SEGMENTATION STUFF
|
|
|
+ ///////////////////// ///////////////////// /////////////////////
|
|
|
+
|
|
|
+void SemanticSegmentation::semanticseg ( const std::string & filename,
|
|
|
+ NICE::Image & segresult,
|
|
|
+ NICE::MultiChannelImageT<double> & probabilities )
|
|
|
+{
|
|
|
+ Globals::setCurrentImgFN ( filename );
|
|
|
+ CachedExample *ce;
|
|
|
+ if ( imagetype == IMAGETYPE_RGB )
|
|
|
+ {
|
|
|
+ NICE::ColorImage img = Preprocess::ReadImgAdvRGB ( filename );
|
|
|
+ ce = new CachedExample ( img );
|
|
|
+ } else {
|
|
|
+
|
|
|
+ NICE::Image img = Preprocess::ReadImgAdv ( filename );
|
|
|
+ ce = new CachedExample ( img );
|
|
|
+ }
|
|
|
+ fprintf ( stderr, "Starting Semantic Segmentation !\n" );
|
|
|
+ semanticseg ( ce, segresult, probabilities );
|
|
|
+ delete ce;
|
|
|
+}
|
|
|
+
|
|
|
+ ///////////////////// ///////////////////// /////////////////////
|
|
|
+ // DATA CONVERSION
|
|
|
+ ///////////////////// ///////////////////// /////////////////////
|
|
|
+
|
|
|
void SemanticSegmentation::convertLSetToSparseExamples ( Examples &examples, LabeledSetVector &lvec )
|
|
|
{
|
|
|
#ifdef DEBUG_PRINTS
|
|
@@ -155,46 +212,127 @@ void SemanticSegmentation::convertVVectorToExamples ( VVector &feats, Examples &
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-SemanticSegmentation::SemanticSegmentation ( const Config *conf,
|
|
|
- const ClassNames *classNames )
|
|
|
-{
|
|
|
- this->classNames = classNames;
|
|
|
-
|
|
|
- Preprocess::Init ( conf );
|
|
|
-
|
|
|
- std::string imagetype_s = conf->gS ( "main", "imagetype", "rgb" );
|
|
|
+///////////////////// INTERFACE PERSISTENT /////////////////////
|
|
|
+// interface specific methods for store and restore
|
|
|
+///////////////////// INTERFACE PERSISTENT /////////////////////
|
|
|
|
|
|
- if ( imagetype_s == "rgb" )
|
|
|
- imagetype = IMAGETYPE_RGB;
|
|
|
- else if ( imagetype_s == "gray" )
|
|
|
- imagetype = IMAGETYPE_GRAY;
|
|
|
- else {
|
|
|
- fprintf ( stderr, "SemanticSegmentation:: unknown image type option\n" );
|
|
|
- exit ( -1 );
|
|
|
+void SemanticSegmentation::restore ( std::istream & is, int format )
|
|
|
+{
|
|
|
+ //delete everything we knew so far...
|
|
|
+ this->clear();
|
|
|
+
|
|
|
+ bool b_restoreVerbose ( false );
|
|
|
+#ifdef B_RESTOREVERBOSE
|
|
|
+ b_restoreVerbose = true;
|
|
|
+#endif
|
|
|
+
|
|
|
+ if ( is.good() )
|
|
|
+ {
|
|
|
+ if ( b_restoreVerbose )
|
|
|
+ std::cerr << " restore SemanticSegmentation" << std::endl;
|
|
|
+
|
|
|
+ std::string tmp;
|
|
|
+ is >> tmp; //class name
|
|
|
+
|
|
|
+ if ( ! this->isStartTag( tmp, "SemanticSegmentation" ) )
|
|
|
+ {
|
|
|
+ std::cerr << " WARNING - attempt to restore SemanticSegmentation, but start flag " << tmp << " does not match! Aborting... " << std::endl;
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+
|
|
|
+ is.precision (numeric_limits<double>::digits10 + 1);
|
|
|
+
|
|
|
+ bool b_endOfBlock ( false ) ;
|
|
|
+
|
|
|
+ while ( !b_endOfBlock )
|
|
|
+ {
|
|
|
+ is >> tmp; // start of block
|
|
|
+
|
|
|
+ if ( this->isEndTag( tmp, "SemanticSegmentation" ) )
|
|
|
+ {
|
|
|
+ b_endOfBlock = true;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ tmp = this->removeStartTag ( tmp );
|
|
|
+
|
|
|
+ if ( b_restoreVerbose )
|
|
|
+ std::cerr << " currently restore section " << tmp << " in SemanticSegmentation" << std::endl;
|
|
|
+
|
|
|
+ if ( tmp.compare("classNames") == 0 )
|
|
|
+ {
|
|
|
+ const_cast<ClassNames*>(this->classNames)->restore ( is, format );
|
|
|
+
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("imagetype") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->imagetype;
|
|
|
+
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("iterationCountSuffix") == 0 )
|
|
|
+ {
|
|
|
+ is >> this->iterationCountSuffix;
|
|
|
+
|
|
|
+ is >> tmp; // end of block
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << "WARNING -- unexpected SemanticSegmentation object -- " << tmp << " -- for restoration... aborting" << std::endl;
|
|
|
+ throw;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << "SemanticSegmentation::restore -- InStream not initialized - restoring not possible!" << std::endl;
|
|
|
+ throw;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //TODO check whether we also have to do something linke Preprocess::Init ( conf );
|
|
|
}
|
|
|
|
|
|
-SemanticSegmentation::~SemanticSegmentation()
|
|
|
-{
|
|
|
+void SemanticSegmentation::store ( std::ostream & os, int format ) const
|
|
|
+{
|
|
|
+ if (os.good())
|
|
|
+ {
|
|
|
+ // show starting point
|
|
|
+ os << this->createStartTag( "SemanticSegmentation" ) << std::endl;
|
|
|
+
|
|
|
+ os.precision (numeric_limits<double>::digits10 + 1);
|
|
|
+
|
|
|
+ os << this->createStartTag( "classNames" ) << std::endl;
|
|
|
+ this->classNames->store ( os, format );
|
|
|
+ os << this->createEndTag( "classNames" ) << std::endl;
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ os << this->createStartTag( "imagetype" ) << std::endl;
|
|
|
+ os << imagetype << std::endl;
|
|
|
+ os << this->createEndTag( "imagetype" ) << std::endl;
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ os << this->createStartTag( "iterationCountSuffix" ) << std::endl;
|
|
|
+ os << iterationCountSuffix << std::endl;
|
|
|
+ os << this->createEndTag( "iterationCountSuffix" ) << std::endl;
|
|
|
+
|
|
|
+ // done
|
|
|
+ os << this->createEndTag( "SemanticSegmentation" ) << std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-void SemanticSegmentation::semanticseg ( const std::string & filename,
|
|
|
- NICE::Image & segresult,
|
|
|
- NICE::MultiChannelImageT<double> & probabilities )
|
|
|
+void SemanticSegmentation::clear ()
|
|
|
{
|
|
|
- Globals::setCurrentImgFN ( filename );
|
|
|
- CachedExample *ce;
|
|
|
- if ( imagetype == IMAGETYPE_RGB )
|
|
|
- {
|
|
|
- NICE::ColorImage img = Preprocess::ReadImgAdvRGB ( filename );
|
|
|
- ce = new CachedExample ( img );
|
|
|
- } else {
|
|
|
-
|
|
|
- NICE::Image img = Preprocess::ReadImgAdv ( filename );
|
|
|
- ce = new CachedExample ( img );
|
|
|
- }
|
|
|
- fprintf ( stderr, "Starting Semantic Segmentation !\n" );
|
|
|
- semanticseg ( ce, segresult, probabilities );
|
|
|
- delete ce;
|
|
|
+ //TODO
|
|
|
}
|
|
|
|