Преглед на файлове

fixed issues with context features

Sven Sickert преди 11 години
родител
ревизия
e908207655
променени са 4 файла, в които са добавени 83 реда и са изтрити 362 реда
  1. 56 140
      semseg/SemSegContextTree.cpp
  2. 1 1
      semseg/SemanticSegmentation.cpp
  3. 22 48
      semseg/operations/Operations.cpp
  4. 4 173
      semseg/operations/Operations.h

+ 56 - 140
semseg/SemSegContextTree.cpp

@@ -72,8 +72,8 @@ SemSegContextTree::SemSegContextTree ( const Config *conf, const MultiDataset *m
   fileLocation = conf->gS ( "debug", "datafile", "tmp.txt" );
   fileLocation = conf->gS ( "debug", "datafile", "tmp.txt" );
 
 
   useRegionFeature = conf->gB ( section, "use_region_feat", false );
   useRegionFeature = conf->gB ( section, "use_region_feat", false );
+  pixelWiseLabeling = conf->gB ( section, "pixelWiseLabeling", false );
 
 
-  pixelWiseLabeling = false;
   if ( segmentationtype == "meanshift" )
   if ( segmentationtype == "meanshift" )
     segmentation = new RSMeanShift ( conf );
     segmentation = new RSMeanShift ( conf );
   else if ( segmentationtype == "felzenszwalb" )
   else if ( segmentationtype == "felzenszwalb" )
@@ -94,75 +94,55 @@ SemSegContextTree::SemSegContextTree ( const Config *conf, const MultiDataset *m
   string featsec = "Features";
   string featsec = "Features";
 
 
   // feature extraction prototypes
   // feature extraction prototypes
-  vector<Operation*> tops;
+  vector<Operation*> tops0, tops1, tops2;
 
 
   if ( conf->gB ( featsec, "minus", true ) )
   if ( conf->gB ( featsec, "minus", true ) )
-    tops.push_back ( new Minus() );
+    tops0.push_back ( new Minus() );
   if ( conf->gB ( featsec, "minus_abs", true ) )
   if ( conf->gB ( featsec, "minus_abs", true ) )
-    tops.push_back ( new MinusAbs() );
+    tops0.push_back ( new MinusAbs() );
   if ( conf->gB ( featsec, "addition", true ) )
   if ( conf->gB ( featsec, "addition", true ) )
-    tops.push_back ( new Addition() );
+    tops0.push_back ( new Addition() );
   if ( conf->gB ( featsec, "only1", true ) )
   if ( conf->gB ( featsec, "only1", true ) )
-    tops.push_back ( new Only1() );
+    tops0.push_back ( new Only1() );
   if ( conf->gB ( featsec, "rel_x", true ) )
   if ( conf->gB ( featsec, "rel_x", true ) )
-    tops.push_back ( new RelativeXPosition() );
+    tops0.push_back ( new RelativeXPosition() );
   if ( conf->gB ( featsec, "rel_y", true ) )
   if ( conf->gB ( featsec, "rel_y", true ) )
-    tops.push_back ( new RelativeYPosition() );
+    tops0.push_back ( new RelativeYPosition() );
   if ( conf->gB ( featsec, "rel_z", true ) )
   if ( conf->gB ( featsec, "rel_z", true ) )
-    tops.push_back ( new RelativeZPosition() );
+    tops0.push_back ( new RelativeZPosition() );
 
 
-  ops.push_back ( tops );
+  tops1.push_back ( new RegionFeat() );
 
 
-  tops.clear();
-  tops.push_back ( new RegionFeat() );
-  ops.push_back ( tops );
-
-  tops.clear();
   if ( conf->gB ( featsec, "int", true ) )
   if ( conf->gB ( featsec, "int", true ) )
-    tops.push_back ( new IntegralOps() );
+    tops2.push_back ( new IntegralOps() );
   if ( conf->gB ( featsec, "bi_int_cent", true ) )
   if ( conf->gB ( featsec, "bi_int_cent", true ) )
-    tops.push_back ( new BiIntegralCenteredOps() );
+    tops2.push_back ( new BiIntegralCenteredOps() );
   if ( conf->gB ( featsec, "int_cent", true ) )
   if ( conf->gB ( featsec, "int_cent", true ) )
-    tops.push_back ( new IntegralCenteredOps() );
+    tops2.push_back ( new IntegralCenteredOps() );
   if ( conf->gB ( featsec, "haar_horz", true ) )
   if ( conf->gB ( featsec, "haar_horz", true ) )
-    tops.push_back ( new HaarHorizontal() );
+    tops2.push_back ( new HaarHorizontal() );
   if ( conf->gB ( featsec, "haar_vert", true ) )
   if ( conf->gB ( featsec, "haar_vert", true ) )
-    tops.push_back ( new HaarVertical() );
+    tops2.push_back ( new HaarVertical() );
   if ( conf->gB ( featsec, "haar_stack", true ) )
   if ( conf->gB ( featsec, "haar_stack", true ) )
-    tops.push_back ( new HaarStacked() );
+    tops2.push_back ( new HaarStacked() );
   if ( conf->gB ( featsec, "haar_diagxy", true ) )
   if ( conf->gB ( featsec, "haar_diagxy", true ) )
-    tops.push_back ( new HaarDiagXY() );
+    tops2.push_back ( new HaarDiagXY() );
   if ( conf->gB ( featsec, "haar_diagxz", true ) )
   if ( conf->gB ( featsec, "haar_diagxz", true ) )
-    tops.push_back ( new HaarDiagXZ() );
+    tops2.push_back ( new HaarDiagXZ() );
   if ( conf->gB ( featsec, "haar_diagyz", true ) )
   if ( conf->gB ( featsec, "haar_diagyz", true ) )
-    tops.push_back ( new HaarDiagYZ() );
+    tops2.push_back ( new HaarDiagYZ() );
   if ( conf->gB ( featsec, "haar3_horz", true ) )
   if ( conf->gB ( featsec, "haar3_horz", true ) )
-    tops.push_back ( new Haar3Horiz() );
+    tops2.push_back ( new Haar3Horiz() );
   if ( conf->gB ( featsec, "haar3_vert", true ) )
   if ( conf->gB ( featsec, "haar3_vert", true ) )
-    tops.push_back ( new Haar3Vert() );
+    tops2.push_back ( new Haar3Vert() );
   if ( conf->gB ( featsec, "haar3_stack", true ) )
   if ( conf->gB ( featsec, "haar3_stack", true ) )
-    tops.push_back ( new Haar3Stack() );
+    tops2.push_back ( new Haar3Stack() );
 
 
-  ops.push_back ( tops );
-  ops.push_back ( tops );
-
-  tops.clear();
-  if ( conf->gB ( featsec, "minus", true ) )
-    tops.push_back ( new Minus() );
-  if ( conf->gB ( featsec, "minus_abs", true ) )
-    tops.push_back ( new MinusAbs() );
-  if ( conf->gB ( featsec, "addition", true ) )
-    tops.push_back ( new Addition() );
-  if ( conf->gB ( featsec, "only1", true ) )
-    tops.push_back ( new Only1() );
-  if ( conf->gB ( featsec, "rel_x", true ) )
-    tops.push_back ( new RelativeXPosition() );
-  if ( conf->gB ( featsec, "rel_y", true ) )
-    tops.push_back ( new RelativeYPosition() );
-  if ( conf->gB ( featsec, "rel_z", true ) )
-    tops.push_back ( new RelativeZPosition() );
-
-  ops.push_back ( tops );
+  ops.push_back ( tops0 );
+  ops.push_back ( tops1 );
+  ops.push_back ( tops2 );
+  ops.push_back ( tops2 );
+  ops.push_back ( tops0 );
 
 
   useGradient = conf->gB ( featsec, "use_gradient", true );
   useGradient = conf->gB ( featsec, "use_gradient", true );
 
 
@@ -363,7 +343,6 @@ double SemSegContextTree::getBestSplit (
     
     
     Operation *op = ops[ft][o]->clone();
     Operation *op = ops[ft][o]->clone();
     op->set ( x1, y1, z1, x2, y2, z2, f1, f2, ft );
     op->set ( x1, y1, z1, x2, y2, z2, f1, f2, ft );
-//    op->setFeatType ( ft );
 
 
     if ( ft == 3 || ft == 4 )
     if ( ft == 3 || ft == 4 )
       op->setContext ( true );
       op->setContext ( true );
@@ -501,12 +480,13 @@ inline double SemSegContextTree::getMeanProb ( const int &x, const int &y, const
   return val / ( double ) nbTrees;
   return val / ( double ) nbTrees;
 }
 }
 
 
-void SemSegContextTree::computeIntegralImage ( const NICE::MultiChannelImage3DT<unsigned short int> &nodeIndices, NICE::MultiChannelImage3DT<double> &integralImage, int firstChannel )
+void SemSegContextTree::computeIntegralImage ( const NICE::MultiChannelImage3DT<unsigned short int> &nodeIndices, NICE::MultiChannelImage3DT<double> &feats, int firstChannel )
 {
 {
-  int xsize = integralImage.width();
-  int ysize = integralImage.height();
-  int zsize = integralImage.depth();
+  int xsize = feats.width();
+  int ysize = feats.height();
+  int zsize = feats.depth();
 
 
+  // integral images for raw channels
   if ( firstiteration )
   if ( firstiteration )
   {
   {
 #pragma omp parallel for
 #pragma omp parallel for
@@ -521,97 +501,33 @@ void SemSegContextTree::computeIntegralImage ( const NICE::MultiChannelImage3DT<
         {
         {
           for ( int x = 0; x < xsize; x++ )
           for ( int x = 0; x < xsize; x++ )
           {
           {
-            integralImage ( x, y, z, cint ) = integralImage ( x, y, z, corg );
+            feats ( x, y, z, cint ) = feats ( x, y, z, corg );
           }
           }
         }
         }
       }
       }
-      integralImage.calcIntegral ( cint );
+      feats.calcIntegral ( cint );
     }
     }
   }
   }
 
 
-  int channels = ( int ) forest[0][0].dist.size();
+  int channels = ( int ) forest[0][0].dist.size();    // channels = classes
 
 
+  // integral images for context channels (probability maps for each class)
 #pragma omp parallel for
 #pragma omp parallel for
   for ( int c = 0; c < channels; c++ )
   for ( int c = 0; c < channels; c++ )
   {
   {
-
-    integralImage ( 0, 0, 0, firstChannel + c ) = getMeanProb ( 0, 0, 0, c, nodeIndices );
-
-    //first column
-    for ( int y = 1; y < ysize; y++ )
-    {
-      integralImage ( 0, y, 0, firstChannel + c ) = getMeanProb ( 0, y, 0, c, nodeIndices )
-                                            + integralImage ( 0, y - 1, 0, firstChannel + c );
-    }
-
-    //first row
-    for ( int x = 1; x < xsize; x++ )
-    {
-      integralImage ( x, 0, 0, firstChannel + c ) = getMeanProb ( x, 0, 0, c, nodeIndices )
-                                            + integralImage ( x - 1, 0, 0, firstChannel + c );
-    }
-
-    //first stack
-    for ( int z = 1; z < zsize; z++ )
-    {
-      integralImage ( 0, 0, z, firstChannel + c ) = getMeanProb ( 0, 0, z, c, nodeIndices )
-                                            + integralImage ( 0, 0, z - 1, firstChannel + c );
-    }
-
-    //x-y plane
-    for ( int y = 1; y < ysize; y++ )
-    {
-      for ( int x = 1; x < xsize; x++ )
-      {
-        integralImage ( x, y, 0, firstChannel + c ) = getMeanProb ( x, y, 0, c, nodeIndices )
-                                              + integralImage ( x, y - 1, 0, firstChannel + c )
-                                              + integralImage ( x - 1, y, 0, firstChannel + c )
-                                              - integralImage ( x - 1, y - 1, 0, firstChannel + c );
-      }
-    }
-
-    //y-z plane
-    for ( int z = 1; z < zsize; z++ )
-    {
-      for ( int y = 1; y < ysize; y++ )
-      {
-        integralImage ( 0, y, z, firstChannel + c ) = getMeanProb ( 0, y, z, c, nodeIndices )
-                                              + integralImage ( 0, y - 1, z, firstChannel + c )
-                                              + integralImage ( 0, y, z - 1, firstChannel + c )
-                                              - integralImage ( 0, y - 1, z - 1, firstChannel + c );
-      }
-    }
-
-    //x-z plane
-    for ( int z = 1; z < zsize; z++ )
-    {
-      for ( int x = 1; x < xsize; x++ )
-      {
-        integralImage ( x, 0, z, firstChannel + c ) = getMeanProb ( x, 0, z, c, nodeIndices )
-                                              + integralImage ( x - 1, 0, z, firstChannel + c )
-                                              + integralImage ( x, 0, z - 1, firstChannel + c )
-                                              - integralImage ( x - 1, 0, z - 1, firstChannel + c );
-      }
-    }
-
-    //rest
-    for ( int z = 1; z < zsize; z++ )
+    for ( int z = 0; z < zsize; z++ )
     {
     {
-      for ( int y = 1; y < ysize; y++ )
+      for ( int y = 0; y < ysize; y++ )
       {
       {
-        for ( int x = 1; x < xsize; x++ )
+        for ( int x = 0; x < xsize; x++ )
         {
         {
-          integralImage ( x, y, z, firstChannel + c ) = getMeanProb ( x, y, z, c, nodeIndices )
-                                                + integralImage ( x - 1, y, z, firstChannel + c )
-                                                + integralImage ( x, y - 1, z, firstChannel + c )
-                                                + integralImage ( x, y, z - 1, firstChannel + c )
-                                                + integralImage ( x - 1, y - 1, z - 1, firstChannel + c )
-                                                - integralImage ( x - 1, y - 1, z, firstChannel + c )
-                                                - integralImage ( x - 1, y, z - 1, firstChannel + c )
-                                                - integralImage ( x, y - 1, z - 1, firstChannel + c );
+          double val = getMeanProb ( x, y, z, c, nodeIndices );
+          feats ( x, y, z, firstChannel + c ) = val;
+          feats ( x, y, z, firstChannel + channels + c ) = val;
         }
         }
       }
       }
     }
     }
+    feats.calcIntegral ( firstChannel + c );
   }
   }
 }
 }
 
 
@@ -826,13 +742,13 @@ void SemSegContextTree::train ( const LabeledSet * trainp )
 ////////////////////////// channel type configuration /////////////////////////
 ////////////////////////// channel type configuration /////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
 
 
-  // Type 0: gray value channels
+  // Type 0: single pixel & pixel-comparison features on gray value channels
   for ( int i = 0; i < rawChannels; i++ )
   for ( int i = 0; i < rawChannels; i++ )
   {
   {
     channelType.push_back ( 0 );
     channelType.push_back ( 0 );
   }
   }
 
 
-  // Type 1: region channels
+  // Type 1: region channel with unsupervised segmentation
   int shift = 0;
   int shift = 0;
   if ( useRegionFeature )
   if ( useRegionFeature )
   {
   {
@@ -840,7 +756,7 @@ void SemSegContextTree::train ( const LabeledSet * trainp )
     shift++;
     shift++;
   }
   }
 
 
-  // Type 2: gray value integral channels
+  // Type 2: rectangutar and Haar-like features on gray value integral channels
   integralMap.clear();
   integralMap.clear();
   for ( int i = 0; i < rawChannels; i++ )
   for ( int i = 0; i < rawChannels; i++ )
   {
   {
@@ -848,17 +764,17 @@ void SemSegContextTree::train ( const LabeledSet * trainp )
     integralMap.push_back ( pair<int, int> ( i, i + rawChannels + shift ) );
     integralMap.push_back ( pair<int, int> ( i, i + rawChannels + shift ) );
   }
   }
 
 
-  // Type 3: label integral channels (context)
+  // Type 3: type 2 features on context channels
   for ( int i = 0; i < classes; i++ )
   for ( int i = 0; i < classes; i++ )
   {
   {
     channelType.push_back ( 3 );
     channelType.push_back ( 3 );
   }
   }
 
 
-  // Type 4: label value channels (context) --> INFO: creates bad splits
-//  for ( int i = 0; i < classes; i++ )
-//  {
-//    channelType.push_back ( 4 );
-//  }
+  // Type 4: type 0 features on context channels
+  for ( int i = 0; i < classes; i++ )
+  {
+    channelType.push_back ( 4 );
+  }
 
 
   // configure to include all possible feature types (just a subset
   // configure to include all possible feature types (just a subset
   // defined by ftypes is actually used)
   // defined by ftypes is actually used)
@@ -1215,13 +1131,13 @@ void SemSegContextTree::train ( const LabeledSet * trainp )
     {
     {
       for ( int i = 0; i < imgCounter; i++ )
       for ( int i = 0; i < imgCounter; i++ )
       {
       {
-        allfeats[i].addChannel ( ( int ) ( classes + rawChannels ) );
+        allfeats[i].addChannel ( (2*classes) + rawChannels );
       }
       }
     }
     }
 
 
     for ( int i = 0; i < imgCounter; i++ )
     for ( int i = 0; i < imgCounter; i++ )
     {
     {
-      computeIntegralImage ( nodeIndices[i], allfeats[i], channelType.size() - classes );
+      computeIntegralImage ( nodeIndices[i], allfeats[i], channelType.size() - (2*classes) );
     }
     }
 
 
     if ( firstiteration )
     if ( firstiteration )
@@ -1758,9 +1674,9 @@ void SemSegContextTree::classify (
       //compute integral images
       //compute integral images
       if ( firstiteration )
       if ( firstiteration )
       {
       {
-        feats.addChannel ( classes + rawChannels );
+        feats.addChannel ( (2*classes) + rawChannels );
       }
       }
-      computeIntegralImage ( nodeIndices, feats, channelType.size() - classes );
+      computeIntegralImage ( nodeIndices, feats, channelType.size() - (2*classes) );
       if ( firstiteration )
       if ( firstiteration )
       {
       {
         firstiteration = false;
         firstiteration = false;

+ 1 - 1
semseg/SemanticSegmentation.cpp

@@ -248,7 +248,7 @@ void SemanticSegmentation::make3DImage ( const std::vector<std::string> & fileli
     }
     }
     else
     else
     {
     {
-      NICE::ImageT<int> img;
+      NICE::Image img;
       try
       try
       {
       {
         img.read ( filelist[it] );
         img.read ( filelist[it] );

+ 22 - 48
semseg/operations/Operations.cpp

@@ -10,7 +10,7 @@ Operation::Operation()
   init = false;
   init = false;
 }
 }
 
 
-void Operation::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int ftype )
+void Operation::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _featType )
 {
 {
   x1 = _x1;
   x1 = _x1;
   y1 = _y1;
   y1 = _y1;
@@ -20,7 +20,7 @@ void Operation::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int
 	z2 = _z2;
 	z2 = _z2;
   channel1 = _channel1;
   channel1 = _channel1;
   channel2 = _channel2;
   channel2 = _channel2;
-  setFeatType(ftype);
+  setFeatType(_featType);
   init = true;
   init = true;
 }
 }
 
 
@@ -59,7 +59,7 @@ void Operation::store ( std::ostream & os )
     os << -1 << std::endl;
     os << -1 << std::endl;
   else
   else
   {
   {
-    if (featType == 4)
+    if (featType == 3 || featType == 4)
       os << CONTEXT << std::endl;
       os << CONTEXT << std::endl;
     else
     else
       os << RAWFEAT << std::endl;
       os << RAWFEAT << std::endl;
@@ -127,17 +127,9 @@ double Minus::getVal ( const Features &feats, const int &x, const int &y, const
   int xsize, ysize, zsize;
   int xsize, ysize, zsize;
   getXYZ ( feats, xsize, ysize, zsize );
   getXYZ ( feats, xsize, ysize, zsize );
 
 
-  double v1,v2;
-  if (featType == 4)
-  {
-    v1 = ( *feats.tree ) [feats.nIndices->get ( BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), feats.cTree ) ].dist[channel1];
-    v2 = ( *feats.tree ) [feats.nIndices->get ( BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), BOUND ( z + z2, 0, zsize - 1 ), feats.cTree ) ].dist[channel2];
-  }
-  else
-  {
-    v1 = feats.feats->get ( BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), channel1 );
-    v2 = feats.feats->get ( BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), BOUND ( z + z2, 0, zsize - 1 ), channel2 );
-  }
+  double v1 = feats.feats->get ( BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), channel1 );
+  double v2 = feats.feats->get ( BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), BOUND ( z + z2, 0, zsize - 1 ), channel2 );
+
   return v1-v2;
   return v1-v2;
 }
 }
 
 
@@ -145,17 +137,10 @@ double MinusAbs::getVal ( const Features &feats, const int &x, const int &y, con
 {
 {
   int xsize, ysize, zsize;
   int xsize, ysize, zsize;
   getXYZ ( feats, xsize, ysize, zsize );
   getXYZ ( feats, xsize, ysize, zsize );
-  double v1,v2;
-  if (featType == 4)
-  {
-    v1 = ( *feats.tree ) [feats.nIndices->get ( BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), feats.cTree ) ].dist[channel1];
-    v2 = ( *feats.tree ) [feats.nIndices->get ( BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), BOUND ( z + z2, 0, zsize - 1 ), feats.cTree ) ].dist[channel2];
-  }
-  else
-  {
-    v1 = feats.feats->get ( BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), channel1 );
-    v2 = feats.feats->get ( BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), BOUND ( z + z2, 0, zsize - 1 ), channel2 );
-  }
+
+  double v1 = feats.feats->get ( BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), channel1 );
+  double v2 = feats.feats->get ( BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), BOUND ( z + z2, 0, zsize - 1 ), channel2 );
+
   return abs(v1-v2);
   return abs(v1-v2);
 }
 }
 
 
@@ -163,17 +148,10 @@ double Addition::getVal ( const Features &feats, const int &x, const int &y, con
 {
 {
   int xsize, ysize, zsize;
   int xsize, ysize, zsize;
   getXYZ ( feats, xsize, ysize, zsize );
   getXYZ ( feats, xsize, ysize, zsize );
-  double v1,v2;
-  if (featType == 4)
-  {
-    v1 = ( *feats.tree ) [feats.nIndices->get ( BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), feats.cTree ) ].dist[channel1];
-    v2 = ( *feats.tree ) [feats.nIndices->get ( BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), BOUND ( z + z2, 0, zsize - 1 ), feats.cTree ) ].dist[channel2];
-  }
-  else
-  {
-    v1 = feats.feats->get ( BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), channel1 );
-    v2 = feats.feats->get ( BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), BOUND ( z + z2, 0, zsize - 1 ), channel2 );
-  }
+
+  double v1 = feats.feats->get ( BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), channel1 );
+  double v2 = feats.feats->get ( BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), BOUND ( z + z2, 0, zsize - 1 ), channel2 );
+
   return v1+v2;
   return v1+v2;
 }
 }
 
 
@@ -187,13 +165,8 @@ double Only1::getVal ( const Features &feats, const int &x, const int &y, const
 {
 {
   int xsize, ysize, zsize;
   int xsize, ysize, zsize;
   getXYZ ( feats, xsize, ysize, zsize );
   getXYZ ( feats, xsize, ysize, zsize );
-  double v1;
-  if (featType == 4)
-    v1 = ( *feats.tree ) [feats.nIndices->get ( BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), feats.cTree ) ].dist[channel1];
-  else
-    v1 = feats.feats->get ( BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), channel1 );
 
 
-  return v1;
+  return feats.feats->get ( BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( z + z1, 0, zsize - 1 ), channel1 );
 }
 }
 
 
 
 
@@ -235,10 +208,11 @@ double GlobalFeats::getVal ( const Features &feats, const int &x, const int &y,
 {
 {
   int xsize, ysize, zsize;
   int xsize, ysize, zsize;
   getXYZ ( feats, xsize, ysize, zsize );
   getXYZ ( feats, xsize, ysize, zsize );
+
   return feats.feats->getIntegralValue( 0, 0, 0, xsize - 1, ysize - 1, zsize - 1, channel1 );
   return feats.feats->getIntegralValue( 0, 0, 0, xsize - 1, ysize - 1, zsize - 1, channel1 );
 }
 }
 
 
-void IntegralOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int ftype )
+void IntegralOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _featType )
 {
 {
   x1 = std::min ( _x1, _x2 );
   x1 = std::min ( _x1, _x2 );
   y1 = std::min ( _y1, _y2 );
   y1 = std::min ( _y1, _y2 );
@@ -248,7 +222,7 @@ void IntegralOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, in
   z2 = std::max ( _z1, _z2 );
   z2 = std::max ( _z1, _z2 );
   channel1 = _channel1;
   channel1 = _channel1;
   channel2 = _channel2;
   channel2 = _channel2;
-  setFeatType(ftype);
+  setFeatType(_featType);
 }
 }
 
 
 double IntegralOps::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 double IntegralOps::getVal ( const Features &feats, const int &x, const int &y, const int &z )
@@ -256,7 +230,7 @@ double IntegralOps::getVal ( const Features &feats, const int &x, const int &y,
   return feats.feats->getIntegralValue(x + x1, y + y1, z + z1, x + x2, y + y2, z + z2, channel1);
   return feats.feats->getIntegralValue(x + x1, y + y1, z + z1, x + x2, y + y2, z + z2, channel1);
 }
 }
 
 
-void IntegralCenteredOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int ftype )
+void IntegralCenteredOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _featType )
 {
 {
   x1 = abs ( _x1 );
   x1 = abs ( _x1 );
   y1 = abs ( _y1 );
   y1 = abs ( _y1 );
@@ -266,7 +240,7 @@ void IntegralCenteredOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int
   z2 = abs ( _z2 );
   z2 = abs ( _z2 );
   channel1 = _channel1;
   channel1 = _channel1;
   channel2 = _channel2;
   channel2 = _channel2;
-  setFeatType(ftype);
+  setFeatType(_featType);
 }
 }
 
 
 double IntegralCenteredOps::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 double IntegralCenteredOps::getVal ( const Features &feats, const int &x, const int &y, const int &z )
@@ -274,7 +248,7 @@ double IntegralCenteredOps::getVal ( const Features &feats, const int &x, const
   return feats.feats->getIntegralValue(x - x1, y - y1, z - z1, x + x1, y + y1, z + z1, channel1);
   return feats.feats->getIntegralValue(x - x1, y - y1, z - z1, x + x1, y + y1, z + z1, channel1);
 }
 }
 
 
-void BiIntegralCenteredOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int ftype )
+void BiIntegralCenteredOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _featType )
 {
 {
   x1 = std::min ( abs ( _x1 ), abs ( _x2 ) );
   x1 = std::min ( abs ( _x1 ), abs ( _x2 ) );
   y1 = std::min ( abs ( _y1 ), abs ( _y2 ) );
   y1 = std::min ( abs ( _y1 ), abs ( _y2 ) );
@@ -284,7 +258,7 @@ void BiIntegralCenteredOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, i
   z2 = std::max ( abs ( _z1 ), abs ( _z2 ) );
   z2 = std::max ( abs ( _z1 ), abs ( _z2 ) );
   channel1 = _channel1;
   channel1 = _channel1;
   channel2 = _channel2;
   channel2 = _channel2;
-  setFeatType(ftype);
+  setFeatType(_featType);
 }
 }
 
 
 double BiIntegralCenteredOps::getVal ( const Features &feats, const int &x, const int &y, const int &z )
 double BiIntegralCenteredOps::getVal ( const Features &feats, const int &x, const int &y, const int &z )

+ 4 - 173
semseg/operations/Operations.h

@@ -107,6 +107,8 @@ class TreeNode
     }
     }
 };
 };
 
 
+
+
 /**
 /**
  * @brief holds all necessary information for feature extraction of 3d images
  * @brief holds all necessary information for feature extraction of 3d images
  **/
  **/
@@ -127,169 +129,7 @@ struct Features {
   std::vector<std::vector<double> > *rProbs;
   std::vector<std::vector<double> > *rProbs;
 };
 };
 
 
-#if 0
-/**
- * @brief abstract values access class
- **/
-class ValueAccess
-{
-  public:
-    /**
-     * @brief extract value on specific position x,y 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 &z, const int &channel ) = 0;
-
-    /**
-     * @brief print some infos about feature type
-     *
-     * @return string feature type
-     **/
-    virtual std::string writeInfos() = 0;
-
-    /**
-     * @brief get feature type
-     *
-     * @return feature type
-     **/
-    virtual ValueTypes getType() = 0;
-};
-
-/**
- * @brief simple MultiChannelImageT access
- **/
-class MCImageAccess: public ValueAccess
-{
-
-  public:
-    /**
-     * @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 &z, const int &channel )
-    {
-      return feats.feats->get ( x, y, z, channel );
-    }
-
-    /**
-     * @brief print some infos about feature type
-     *
-     * @return string feature type
-     **/
-    virtual std::string writeInfos()
-    {
-      return "raw";
-    }
-
-    /**
-     * @brief get feature type
-     *
-     * @return feature type
-     **/
-    virtual ValueTypes getType()
-    {
-      return RAWFEAT;
-    }
-};
-
-class ClassificationResultAccess: public ValueAccess
-{
-  public:
-    /**
-     * @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 &z, const int &channel )
-    {
-      return ( *feats.tree ) [feats.nIndices->get ( x,y,z,feats.cTree ) ].dist[channel];
-    }
-
-    /**
-     * @brief print some infos about feature type
-     *
-     * @return string feature type
-     **/
-    virtual std::string writeInfos()
-    {
-      return "context";
-    }
-
-    /**
-     * @brief get feature type
-     *
-     * @return feature type
-     **/
-    virtual ValueTypes getType()
-    {
-      return CONTEXT;
-    }
-};
-
-
-/**
- * @brief not finished yet, do we really need sparse feature representation or ClassificationResultAccess sufficient
- **/
-class SparseImageAccess: public ValueAccess
-{
-  private:
-    double scale;
-
-  public:
-    /**
-     * @brief extract value on specific position x,y and channel;
-     *
-     * @param feats see struct Features
-     * @param x position of feature
-     * @param y 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 )
-    {
-      //MultiChannelImageT<SparseVectorInt> textonMap;
-      //TODO: implement access
-      return -1.0;
-    }
-
-    /**
-     * @brief print some infos about feature type
-     *
-     * @return string feature type
-     **/
-    virtual std::string writeInfos()
-    {
-      return "context";
-    }
 
 
-    /**
-     * @brief get feature type
-     *
-     * @return feature type
-     **/
-    virtual ValueTypes getType()
-    {
-      return CONTEXT;
-    }
-};
-#endif
 
 
 /**
 /**
  * @brief abstract operation class
  * @brief abstract operation class
@@ -325,7 +165,7 @@ class Operation
      * @param _ftype feature type
      * @param _ftype feature type
      * @return void nothing
      * @return void nothing
      **/
      **/
-    virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int ftype );
+    virtual void set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _featType );
 
 
     /**
     /**
      * @brief set whether it is a context feature or not
      * @brief set whether it is a context feature or not
@@ -437,16 +277,7 @@ class RegionFeat: public Operation
      **/
      **/
     virtual std::string writeInfos()
     virtual std::string writeInfos()
     {
     {
-      std::string out = "RegionFeat";
-
-      if (init)
-      {
-        if ( featType == 4 )
-          out += "context";
-        else
-          out += "raw";
-      }
-      return out + Operation::writeInfos();
+      return "RegionFeat" + Operation::writeInfos();
     }
     }
 
 
     /**
     /**