Pārlūkot izejas kodu

added statistical moments as as optional rectangle features for ICF3D

Sven Sickert 9 gadi atpakaļ
vecāks
revīzija
73a0e2141d

+ 16 - 7
semseg/SemSegContextTree3D.cpp

@@ -1163,6 +1163,17 @@ void SemSegContextTree3D::addFeatureMaps (
                     imgData.set( x, y, z, b, 2 );
                 }
     }
+    else
+    // normalize gray values to [0,1]
+    {
+        for ( int z = 0; z < zsize; z++ )
+            for ( int y = 0; y < ysize; y++ )
+                for ( int x = 0; x < xsize; x++ )
+                {
+                    double val = imgData.get( x, y, z, 0 ) / 255.0;
+                    imgData.set( x, y, z, val, 0 );
+                }
+    }
 
     // Gradient layers
     if ( useGradient )
@@ -1309,13 +1320,11 @@ void SemSegContextTree3D::addFeatureMaps (
 
     }
 
-    // intergal images of raw channels
-    if ( useFeat2 )
-    {
+    // convert raw channels to intergal channels
 #pragma omp parallel for
-        for ( int i = 0; i < rawChannels; i++ )
-            imgData.calcIntegral ( i );
-    }
+    for ( int i = 0; i < rawChannels; i++ )
+        imgData.calcIntegral ( i );
+
 
     int classes = classNames->numClasses() - forbidden_classes.size();
 
@@ -1903,7 +1912,7 @@ void SemSegContextTree3D::restore ( std::istream & is, int format )
 
                 assert ( forest[t][n].feat != NULL );
                 forest[t][n].feat->restore ( is );
-
+                forest[t][n].feat->setWSize ( windowSize );
             }
         }
     }

+ 32 - 6
semseg/operations/Operations3D.cpp

@@ -253,21 +253,47 @@ double RelativeZPosition3D::getVal ( const Features &feats, const int &x, const
 }
 
 
+//######################## local statistical moments ###########################
 
 
+double LocalMean3D::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 - w, y - w, z - w, x + w, y + w, z + w, channel1 );
+}
 
-//########################### integral operations #############################
-
-
-
-double GlobalFeats3D::getVal ( const Features &feats, const int &x, const int &y, const int &z )
+double LocalStatMom3D::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 mean = 0.0, var = 0.0;
+    const unsigned short w = (int)floor(wsize/2.0);
+    const unsigned short order = (abs(x1) % 3) + 2;
+    mean = feats.feats->getIntegralValue( x - w, y - w, z - w, x + w, y + w, z + w, channel1 );
+
+    unsigned int count = 0;
+    for ( short int i = -w; i <= w ; i++ )
+        for ( short int j = -w; j <= w ; j++ )
+            for ( short int k = -w; k <= w ; k++, count++ )
+            {
+                double val = intToRaw( feats,
+                                       BOUND( x+i, 0, xsize-1 ),
+                                       BOUND( y+j, 0, ysize-1 ),
+                                       BOUND( z+k, 0, zsize-1 ),
+                                       channel1 );
+                var += pow((val-mean),(double)order);
+            }
+
+    var /= (double)count;
+
+    return var;
 }
 
+
+//########################### rectangle operations #############################
+
+
 void IntegralOps3D::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _channel1, int _channel2, int _featType )
 {
     channel1 = _channel1;

+ 71 - 13
semseg/operations/Operations3D.h

@@ -47,12 +47,12 @@ enum OperationTypes {
     RELATIVEXPOSITION,
     RELATIVEYPOSITION,
     RELATIVEZPOSITION,
-    GLOBALFEATS,
+    LOCALMEAN,
     EQUALITY,
-    RAYDIFF,
-    RAYDIST,
-    RAYORIENT,
-    RAYNORM,
+    LOCALSTATMOM,
+    UNUSED0,
+    UNUSED1,
+    UNUSED2,
     MINUS_C,
     MINUSABS_C,
     ADDITION_C,
@@ -69,9 +69,10 @@ enum OperationTypes {
     HAAR3HORIZ_C,
     HAAR3VERT_C,
     HAAR3STACK_C,
-    GLOBALFEATS_C,
+    LOCALMEAN_C,
     BIINTEGRAL,
     BIINTEGRAL_C,
+    LOCALSTATMOM_C,
     NBOPERATIONS
 };
 
@@ -824,9 +825,9 @@ public:
 };
 
 /**
- * @brief like a global bag of words to model the current appearance of classes in an image without local context
+ * @brief mean of feature values in neighborhood window
  **/
-class GlobalFeats3D: public IntegralOps3D
+class LocalMean3D: public IntegralOps3D
 {
 
 public:
@@ -845,7 +846,7 @@ public:
      **/
     virtual Operation3D* clone()
     {
-        Operation3D* o = new GlobalFeats3D();
+        Operation3D* o = new LocalMean3D();
         o->setContext(context);
         return o;
     }
@@ -856,14 +857,14 @@ public:
      **/
     virtual std::string writeInfos()
     {
-        std::string out = "GlobalFeats";
+        std::string out = "LocalMean";
 
         if ( context )
             out = "(C)" + out;
         else
             out = "(R)" + out;
 
-        return out + "          " + Operation3D::writeInfos();
+        return out + "            " + Operation3D::writeInfos();
     }
 
     /**
@@ -873,12 +874,69 @@ public:
     virtual OperationTypes getOps()
     {
         if ( context )
-            return GLOBALFEATS_C;
+            return LOCALMEAN_C;
         else
-            return GLOBALFEATS;
+            return LOCALMEAN;
     }
 };
 
+/**
+ * @brief variance of feature values in neighborhood window
+ **/
+class LocalStatMom3D: 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()
+    {
+        Operation3D* o = new LocalStatMom3D();
+        o->setContext(context);
+        return o;
+    }
+
+    /**
+     * @brief print some infos about operation extraction type
+     * @return string feature type
+     **/
+    virtual std::string writeInfos()
+    {
+        std::string out = "LocalStatMom";
+
+        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 LOCALSTATMOM_C;
+        else
+            return LOCALSTATMOM;
+    }
+};
+
+
 /**
  * @brief uses mean of Integral image given by x1, y1, z1 with current pixel as center
  **/

+ 12 - 0
semseg/operations/RectangleOperationPool.cpp

@@ -108,4 +108,16 @@ void RectangleOperationPool::getOperations ( std::string confString )
         o->setContext( contextMode );
         pool.push_back ( o );
     }
+    if ( config->gB ( confString, "local_mean", false ) )
+    {
+        Operation3D* o = new LocalMean3D();
+        o->setContext( contextMode );
+        pool.push_back ( o );
+    }
+    if ( config->gB ( confString, "local_stat_mom", false ) )
+    {
+        Operation3D* o = new LocalStatMom3D();
+        o->setContext( contextMode );
+        pool.push_back ( o );
+    }
 }