Selaa lähdekoodia

added 'global haar-like feature'

Sven Sickert 11 vuotta sitten
vanhempi
commit
13cd771c46

+ 38 - 31
semseg/SemSegContextTree3D.cpp

@@ -1,25 +1,25 @@
 #include "SemSegContextTree3D.h"
 
-#include "core/basics/FileName.h"
-#include "core/basics/numerictools.h"
-#include "core/basics/quadruplet.h"
-#include "core/basics/StringTools.h"
-#include "core/basics/Timer.h"
-#include "core/basics/vectorio.h"
-#include "core/image/Filter.h"
-#include "core/image/FilterT.h"
-#include "core/image/Morph.h"
-#include "core/imagedisplay/ImageDisplay.h"
-
-#include "vislearning/baselib/cc.h"
-#include "vislearning/baselib/Globals.h"
-#include "vislearning/baselib/ICETools.h"
-#include "vislearning/cbaselib/CachedExample.h"
-#include "vislearning/cbaselib/PascalResults.h"
-
-#include "segmentation/RSGraphBased.h"
-#include "segmentation/RSMeanShift.h"
-#include "segmentation/RSSlic.h"
+#include <core/basics/FileName.h>
+#include <core/basics/numerictools.h>
+#include <core/basics/quadruplet.h>
+#include <core/basics/StringTools.h>
+#include <core/basics/Timer.h>
+#include <core/basics/vectorio.h>
+#include <core/image/Filter.h>
+#include <core/image/FilterT.h>
+#include <core/image/Morph.h>
+#include <core/imagedisplay/ImageDisplay.h>
+
+#include <vislearning/baselib/cc.h>
+#include <vislearning/baselib/Globals.h>
+#include <vislearning/baselib/ICETools.h>
+#include <vislearning/cbaselib/CachedExample.h>
+#include <vislearning/cbaselib/PascalResults.h>
+
+#include <segmentation/RSGraphBased.h>
+#include <segmentation/RSMeanShift.h>
+#include <segmentation/RSSlic.h>
 
 #include <omp.h>
 #include <iostream>
@@ -74,8 +74,8 @@ SemSegContextTree3D::SemSegContextTree3D () : SemanticSegmentation ()
 
 SemSegContextTree3D::SemSegContextTree3D (
     const Config *conf,
-    const MultiDataset *md )
-    : SemanticSegmentation ( conf, & ( md->getClassNames ( "train" ) ) )
+    const ClassNames *classNames )
+    : SemanticSegmentation ( conf, classNames )
 {
   this->conf = conf;
 
@@ -117,7 +117,7 @@ SemSegContextTree3D::SemSegContextTree3D (
   if ( useWeijer )
     this->lfcw    = new LocalFeatureColorWeijer ( conf );
 
-  this->classnames = md->getClassNames ( "train" );
+  this->classnames = (*classNames);
 
   // feature types
   this->useFeat0 = conf->gB ( section, "use_feat_0", true);     // pixel pair features
@@ -185,6 +185,13 @@ void SemSegContextTree3D::initOperations()
     o->setContext(true);
     tops3.push_back ( o );
   }
+  if ( conf->gB ( featsec, "bi_int", true ) )
+  {
+    tops2.push_back ( new BiIntegralOps3D() );
+    Operation3D* o = new BiIntegralOps3D();
+    o->setContext(true);
+    tops3.push_back ( o );
+  }
   if ( conf->gB ( featsec, "bi_int_cent", true ) )
   {
     tops2.push_back ( new BiIntegralCenteredOps3D() );
@@ -452,11 +459,11 @@ double SemSegContextTree3D::getBestSplit (
       z2 = ( int ) ( rand() % 8 );
     }
 
-//    if (conf->gB ( "SSContextTree", "z_negative_only", false ))
-//    {
-//      z1 = -abs(z1);
-//      z2 = -abs(z2);
-//    }
+    if (conf->gB ( "SSContextTree", "z_negative_only", false ))
+    {
+      z1 = abs(z1);
+      z2 = abs(z2);
+    }
 
     /* random feature maps (channels) */
     int f1, f2;
@@ -479,6 +486,7 @@ double SemSegContextTree3D::getBestSplit (
 
     Operation3D *op = ops[ft][o]->clone();
     op->set ( x1, y1, z1, x2, y2, z2, f1, f2, ft );
+    op->setWSize(windowSize);
 
     if ( ft == 3 || ft == 4 )
       op->setContext ( true );
@@ -761,9 +769,8 @@ inline double computeWeight ( const int &d, const int &dim )
 
 void SemSegContextTree3D::train ( const MultiDataset *md )
 {
-  const LabeledSet trainSet = * ( *md ) ["train"];
-  const LabeledSet *trainp = &trainSet;
-  
+  const LabeledSet *trainp = ( *md ) ["train"];
+
   if ( saveLoadData )
   {
     if ( FileMgt::fileExists ( fileLocation ) )

+ 9 - 8
semseg/SemSegContextTree3D.h

@@ -22,7 +22,7 @@
 
 // nice-semseg includes
 #include "SemanticSegmentation.h"
-#include "semseg/semseg/operations/Operations3D.h"
+#include "operations/Operations3D.h"
 
 namespace OBJREC
 {
@@ -163,12 +163,6 @@ private:
    */
   void initOperations();
 
-  /**
-   * @brief train the actual training method
-   * @param trainp pointer to training data
-   */
-  void train ( const LabeledSet * trainp );
-
   /**
    * @brief updateProbabilityMaps computes probability maps for context features
    * @param nodeIndices matrix with current node for each feature
@@ -220,7 +214,8 @@ public:
   SemSegContextTree3D ();
 
   /** constructor */
-  SemSegContextTree3D ( const NICE::Config *conf, const MultiDataset *md );
+  SemSegContextTree3D ( const NICE::Config *conf,
+                        const ClassNames *classNames );
 
   /** simple destructor */
   virtual ~SemSegContextTree3D();
@@ -235,6 +230,12 @@ public:
                   NICE::MultiChannelImageT<double> & segresult,
                   NICE::MultiChannelImage3DT<double> & probabilities );
 
+  /**
+   * @brief train the actual training method
+   * @param trainp pointer to training data
+   */
+  void train ( const LabeledSet * trainp );
+
   /**
    * the training method with checking for already existing trained classifier from file
    * @param md training data

+ 8 - 2
semseg/operations/Operations3D.cpp

@@ -34,9 +34,9 @@ bool Operation3D::getContext()
   return context;
 }
 
-void Operation3D::setFeatType ( int _featType )
+void Operation3D::setWSize ( int _wsize )
 {
-  featType = _featType;
+  wsize = _wsize;
 }
 
 int Operation3D::getFeatType()
@@ -231,6 +231,12 @@ double IntegralOps3D::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);
 }
 
+double BiIntegralOps3D::getVal ( const Features &feats, const int &x, const int &y, const int &z )
+{
+  int w = (int)floor(wsize/2.0);
+  return feats.feats->getIntegralValue(x + x1, y + y1, z + z1, x + x2, y + y2, z + z2, channel1) - feats.feats->getIntegralValue( x-w, y-w, z-w, x+w, y+w, z+w, channel1 );
+}
+
 void IntegralCenteredOps3D::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _featType )
 {
   x1 = abs ( _x1 );

+ 61 - 6
semseg/operations/Operations3D.h

@@ -6,8 +6,8 @@
 
 */
 
-#include "core/image/MultiChannelImageT.h"
-#include "core/image/MultiChannelImage3DT.h"
+#include <core/image/MultiChannelImageT.h>
+#include <core/image/MultiChannelImage3DT.h>
 
 #define BOUND(x,min,max) (((x)<(min))?(min):((x)>(max)?(max):(x)))
 
@@ -70,6 +70,8 @@ enum OperationTypes {
   HAAR3VERT_C,
   HAAR3STACK_C,
   GLOBALFEATS_C,
+  BIINTEGRAL,
+  BIINTEGRAL_C,
   NBOPERATIONS
 };
 
@@ -150,7 +152,7 @@ class Operation3D
 {
   protected:
     /** two different points (e.g. for an rectangle or two positions), channels and size  */
-    int x1, y1, z1, x2, y2, z2, channel1, channel2;
+    int x1, y1, z1, x2, y2, z2, channel1, channel2, wsize;
     
     /** type of feature */
     int featType;
@@ -194,11 +196,11 @@ class Operation3D
     bool getContext();
     
     /**
-     * @brief set type of feature
-     * @param _featType type of feature
+     * @brief set size of feature window
+     * @param _wsize window size
      * @return void nothing
      **/
-    void setFeatType ( int _featType );
+    void setWSize ( int _wsize );
 
     /**
      * @brief return context information (set by setContext(bool)
@@ -734,6 +736,59 @@ class IntegralOps3D: public Operation3D
     }
 };
 
+/**
+ * @brief uses mean in a window given by (x1,y1,z1) (x2,y2,z2) and full window
+ **/
+class BiIntegralOps3D: public IntegralOps3D
+{
+  public:
+    /**
+     * @brief interface for feature computation
+     * @param feats features
+     * @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 Operation3D* clone()
+    {
+      return new BiIntegralOps3D();
+    }
+
+    /**
+     * @brief print some infos about operation extraction type
+     * @return string feature type
+     **/
+    virtual std::string writeInfos()
+    {
+      std::string out = "BiIntegralOps";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "    " + Operation3D::writeInfos();
+    }
+
+    /**
+     * @brief return operation type (for store and restore)
+     * @return OperationTypes
+     **/
+    virtual OperationTypes getOps()
+    {
+      if (context)
+        return BIINTEGRAL_C;
+      else
+        return BIINTEGRAL;
+    }
+
+};
 
 /**
  * @brief like a global bag of words to model the current appearance of classes in an image without local context