소스 검색

Operations: added ray features & fixed bugs

Sven Sickert 11 년 전
부모
커밋
b43868edd3
2개의 변경된 파일445개의 추가작업 그리고 62개의 파일을 삭제
  1. 38 5
      semseg/operations/Operations.cpp
  2. 407 57
      semseg/operations/Operations.h

+ 38 - 5
semseg/operations/Operations.cpp

@@ -6,7 +6,6 @@ using namespace NICE;
 
 Operation::Operation()
 {
-  maxtypes = 1000;
   init = false;
 }
 
@@ -20,7 +19,7 @@ void Operation::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int
 	z2 = _z2;
   channel1 = _channel1;
   channel2 = _channel2;
-  setFeatType(_featType);
+  featType = _featType;
   init = true;
 }
 
@@ -222,7 +221,8 @@ void IntegralOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, in
   z2 = std::max ( _z1, _z2 );
   channel1 = _channel1;
   channel2 = _channel2;
-  setFeatType(_featType);
+  featType = _featType;
+  init = true;
 }
 
 double IntegralOps::getVal ( const Features &feats, const int &x, const int &y, const int &z )
@@ -240,7 +240,8 @@ void IntegralCenteredOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, int
   z2 = abs ( _z2 );
   channel1 = _channel1;
   channel2 = _channel2;
-  setFeatType(_featType);
+  featType = _featType;
+  init = true;
 }
 
 double IntegralCenteredOps::getVal ( const Features &feats, const int &x, const int &y, const int &z )
@@ -258,7 +259,8 @@ void BiIntegralCenteredOps::set ( int _x1, int _y1, int _z1, int _x2, int _y2, i
   z2 = std::max ( abs ( _z1 ), abs ( _z2 ) );
   channel1 = _channel1;
   channel2 = _channel2;
-  setFeatType(_featType);
+  featType = _featType;
+  init = true;
 }
 
 double BiIntegralCenteredOps::getVal ( const Features &feats, const int &x, const int &y, const int &z )
@@ -388,3 +390,34 @@ double Haar3Stack::getVal ( const Features &feats, const int &x, const int &y, c
 
   return feats.feats->getIntegralValue(tlx, tly, tlz, lrx, lry, mtlz, channel1) - feats.feats->getIntegralValue(tlx, tly, mtlz, lrx, lry, mlrz, channel1) + feats.feats->getIntegralValue(tlx, tly, mlrz, lrx, lry, lrz, channel1);
 }
+
+
+
+
+//############################### Ray Features ################################
+double RayDiff::getVal( const Features &feats, const int &x, const int &y, const int &z )
+{
+
+  double dist1 = feats.feats->get( x, y, z, feats.feats->channels()-16+z1 );
+  double dist2 = feats.feats->get( x, y, z, feats.feats->channels()-16+z2 );
+
+  if (dist1 != 0)
+    return (dist1-dist2)/dist1;
+  else
+    return 0.0;
+}
+
+double RayDist::getVal( const Features &feats, const int &x, const int &y, const int &z )
+{
+  return feats.feats->get( x, y, z, feats.feats->channels()-16+z1 );
+}
+
+double RayTheta::getVal( const Features &feats, const int &x, const int &y, const int &z )
+{
+  return 0.0;
+}
+
+double RayNorm::getVal( const Features &feats, const int &x, const int &y, const int &z )
+{
+  return feats.feats->get( x, y, z, feats.feats->channels()-8+z1 );
+}

+ 407 - 57
semseg/operations/Operations.h

@@ -49,6 +49,27 @@ enum OperationTypes {
 	RELATIVEZPOSITION,
   GLOBALFEATS,
   EQUALITY,
+  RAYDIFF,
+  RAYDIST,
+  RAYTHETA,
+  RAYNORM,
+  MINUS_C,
+  MINUSABS_C,
+  ADDITION_C,
+  ONLY1_C,
+  INTEGRAL_C,
+  INTEGRALCENT_C,
+  BIINTEGRALCENT_C,
+  HAARHORIZ_C,
+  HAARVERT_C,
+  HAARSTACK_C,
+  HAARDIAGXY_C,
+  HAARDIAGXZ_C,
+  HAARDIAGYZ_C,
+  HAAR3HORIZ_C,
+  HAAR3VERT_C,
+  HAAR3STACK_C,
+  GLOBALFEATS_C,
   NBOPERATIONS
 };
 
@@ -117,7 +138,7 @@ struct Features {
   NICE::MultiChannelImage3DT<double> *feats;
 
   /** node index for each pixel (width,height,depth) in each tree (channel) */
-  NICE::MultiChannelImage3DT<unsigned short int> *nIndices;
+  //NICE::MultiChannelImage3DT<unsigned short int> *nIndices;
 
   /** current tree index */
   int cTree;
@@ -138,7 +159,7 @@ class Operation
 {
   protected:
     /** two different points (e.g. for an rectangle or two positions), channels and size  */
-    int x1, y1, z1, x2, y2, z2, channel1, channel2, maxtypes;
+    int x1, y1, z1, x2, y2, z2, channel1, channel2;
     
     /** type of feature */
     int featType;
@@ -277,7 +298,7 @@ class RegionFeat: public Operation
      **/
     virtual std::string writeInfos()
     {
-      return "RegionFeat" + Operation::writeInfos();
+      return "(-)RegionFeat           " + Operation::writeInfos();
     }
 
     /**
@@ -322,14 +343,12 @@ class Minus: public Operation
     {
       std::string out = "Minus";
 
-      if (init)
-      {
-        if ( featType == 4 )
-          out += "context";
-        else
-          out += "raw";
-      }
-      return out + Operation::writeInfos();
+      if ( context )
+        out = "(C)" + out;
+      else
+        out = "(R)" + out;
+
+      return out + "                " +Operation::writeInfos();
     }
 
     /**
@@ -338,6 +357,9 @@ class Minus: public Operation
      **/
     virtual OperationTypes getOps()
     {
+    if (context)
+      return MINUS_C;
+    else
       return MINUS;
     }
 };
@@ -375,14 +397,12 @@ class MinusAbs: public Operation
     {
       std::string out = "MinusAbs";
 
-      if (init)
-      {
-        if ( featType == 4 )
-          out += "context";
+        if ( context )
+          out = "(C)" + out;
         else
-          out += "raw";
-      }
-      return out;
+          out = "(R)" + out;
+
+      return out + "             " + Operation::writeInfos();
     }
 
     /**
@@ -391,7 +411,10 @@ class MinusAbs: public Operation
      **/
     virtual OperationTypes getOps()
     {
-      return MINUSABS;
+      if (context)
+        return MINUSABS_C;
+      else
+        return MINUSABS;
     }
 };
 
@@ -428,14 +451,12 @@ class Addition: public Operation
     {
       std::string out = "Addition";
 
-      if (init)
-      {
-        if ( featType == 4 )
-          out += "context";
+        if ( context )
+          out = "(C)" + out;
         else
-          out += "raw";
-      }
-      return out + Operation::writeInfos();
+          out = "(R)" + out;
+
+      return out + "             " + Operation::writeInfos();
     }
 
     /**
@@ -444,7 +465,10 @@ class Addition: public Operation
      **/
     virtual OperationTypes getOps()
     {
-      return ADDITION;
+      if (context)
+        return ADDITION_C;
+      else
+        return ADDITION;
     }
 };
 
@@ -480,14 +504,12 @@ class Only1: public Operation
     {
       std::string out = "Only1";
 
-      if (init)
-      {
-        if ( featType == 4 )
-          out += "context";
+        if ( context )
+          out = "(C)" + out;
         else
-          out += "raw";
-      }
-      return out + Operation::writeInfos();
+          out = "(R)" + out;
+
+      return out + "                " + Operation::writeInfos();
     }
 
     /**
@@ -496,7 +518,10 @@ class Only1: public Operation
      **/
     virtual OperationTypes getOps()
     {
-      return ONLY1;
+      if (context)
+        return ONLY1_C;
+      else
+        return ONLY1;
     }
 };
 
@@ -530,7 +555,14 @@ class RelativeXPosition: public Operation
      **/
     virtual std::string writeInfos()
     {
-      return "RelativeXPosition" + Operation::writeInfos();
+      std::string out = "RelXPos";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "              " + Operation::writeInfos();
     }
 
     /**
@@ -573,7 +605,14 @@ class RelativeYPosition: public Operation
      **/
     virtual std::string writeInfos()
     {
-      return "RelativeYPosition" + Operation::writeInfos();
+      std::string out = "RelYPos";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "              " + Operation::writeInfos();
     }
 
     /**
@@ -616,7 +655,14 @@ class RelativeZPosition: public Operation
      **/
     virtual std::string writeInfos()
     {
-      return "RelativeZPosition" + Operation::writeInfos();
+      std::string out = "RelZPos";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "              " + Operation::writeInfos();
     }
 
     /**
@@ -674,7 +720,14 @@ class IntegralOps: public Operation
      **/
     virtual std::string writeInfos()
     {
-      return "IntegralOps" + Operation::writeInfos();
+      std::string out = "IntegralOps";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "          " + Operation::writeInfos();
     }
 
     /**
@@ -683,7 +736,10 @@ class IntegralOps: public Operation
      **/
     virtual OperationTypes getOps()
     {
-      return INTEGRAL;
+      if (context)
+        return INTEGRAL_C;
+      else
+        return INTEGRAL;
     }
 };
 
@@ -719,7 +775,14 @@ class GlobalFeats: public IntegralOps
      **/
     virtual std::string writeInfos()
     {
-      return "GlobalFeats" + Operation::writeInfos();
+      std::string out = "GlobalFeats";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "          " + Operation::writeInfos();
     }
 
     /**
@@ -728,7 +791,10 @@ class GlobalFeats: public IntegralOps
      **/
     virtual OperationTypes getOps()
     {
-      return GLOBALFEATS;
+      if ( context )
+        return GLOBALFEATS_C;
+      else
+        return GLOBALFEATS;
     }
 };
 
@@ -777,7 +843,14 @@ class IntegralCenteredOps: public IntegralOps
      **/
     virtual std::string writeInfos()
     {
-      return "IntegralCenteredOps" + Operation::writeInfos();
+      std::string out = "IntegralCenteredOps";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "  " + Operation::writeInfos();
     }
 
     /**
@@ -786,7 +859,10 @@ class IntegralCenteredOps: public IntegralOps
      **/
     virtual OperationTypes getOps()
     {
-      return INTEGRALCENT;
+      if ( context )
+        return INTEGRALCENT_C;
+      else
+        return INTEGRALCENT;
     }
 };
 
@@ -835,7 +911,14 @@ class BiIntegralCenteredOps: public IntegralCenteredOps
      **/
     virtual std::string writeInfos()
     {
-      return "BiIntegralCenteredOps" + Operation::writeInfos();
+      std::string out = "BiIntegralCenteredOps";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + Operation::writeInfos();
     }
 
     /**
@@ -844,7 +927,10 @@ class BiIntegralCenteredOps: public IntegralCenteredOps
      **/
     virtual OperationTypes getOps()
     {
-      return BIINTEGRALCENT;
+      if ( context )
+        return BIINTEGRALCENT_C;
+      else
+        return BIINTEGRALCENT;
     }
 };
 
@@ -880,7 +966,14 @@ class HaarHorizontal: public IntegralCenteredOps
      **/
     virtual std::string writeInfos()
     {
-      return "HaarHorizontal" + Operation::writeInfos();
+      std::string out = "HaarHorizontal";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "       " + Operation::writeInfos();
     }
 
     /**
@@ -889,7 +982,10 @@ class HaarHorizontal: public IntegralCenteredOps
      **/
     virtual OperationTypes getOps()
     {
-      return HAARHORIZ;
+      if ( context )
+        return HAARHORIZ_C;
+      else
+        return HAARHORIZ;
     }
 };
 
@@ -925,7 +1021,14 @@ class HaarVertical: public IntegralCenteredOps
      **/
     virtual std::string writeInfos()
     {
-      return "HaarVertical" + Operation::writeInfos();
+      std::string out = "HaarVertical";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "         " + Operation::writeInfos();
     }
 
     /**
@@ -934,6 +1037,9 @@ class HaarVertical: public IntegralCenteredOps
      **/
     virtual OperationTypes getOps()
     {
+    if ( context )
+      return HAARVERT_C;
+    else
       return HAARVERT;
     }
 };
@@ -970,7 +1076,14 @@ class HaarStacked: public IntegralCenteredOps
      **/
     virtual std::string writeInfos()
     {
-      return "HaarStacked" + Operation::writeInfos();
+      std::string out = "HaarStacked";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "          " + Operation::writeInfos();
     }
 
     /**
@@ -979,6 +1092,9 @@ class HaarStacked: public IntegralCenteredOps
      **/
     virtual OperationTypes getOps()
     {
+    if ( context )
+      return HAARSTACK_C;
+    else
       return HAARSTACK;
     }
 };
@@ -1015,7 +1131,14 @@ class HaarDiagXY: public IntegralCenteredOps
      **/
     virtual std::string writeInfos()
     {
-      return "HaarDiagXY" + Operation::writeInfos();
+      std::string out = "HaarDiagXY";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "           " + Operation::writeInfos();
     }
 
     /**
@@ -1024,6 +1147,9 @@ class HaarDiagXY: public IntegralCenteredOps
      **/
     virtual OperationTypes getOps()
     {
+    if ( context )
+      return HAARDIAGXY_C;
+    else
       return HAARDIAGXY;
     }
 };
@@ -1060,7 +1186,14 @@ class HaarDiagXZ: public IntegralCenteredOps
      **/
     virtual std::string writeInfos()
     {
-      return "HaarDiagXZ" + Operation::writeInfos();
+      std::string out = "HaarDiagXZ";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "           " + Operation::writeInfos();
     }
 
     /**
@@ -1069,6 +1202,9 @@ class HaarDiagXZ: public IntegralCenteredOps
      **/
     virtual OperationTypes getOps()
     {
+    if ( context )
+      return HAARDIAGXZ_C;
+    else
       return HAARDIAGXZ;
     }
 };
@@ -1105,7 +1241,14 @@ class HaarDiagYZ: public IntegralCenteredOps
      **/
     virtual std::string writeInfos()
     {
-      return "HaarDiagYZ" + Operation::writeInfos();
+      std::string out = "HaarDiagYZ";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "           " + Operation::writeInfos();
     }
 
     /**
@@ -1114,6 +1257,9 @@ class HaarDiagYZ: public IntegralCenteredOps
      **/
     virtual OperationTypes getOps()
     {
+    if ( context )
+      return HAARDIAGYZ_C;
+    else
       return HAARDIAGYZ;
     }
 };
@@ -1152,7 +1298,14 @@ class Haar3Horiz: public BiIntegralCenteredOps
      **/
     virtual std::string writeInfos()
     {
-      return "Haar3Horiz" + Operation::writeInfos();
+      std::string out = "Haar3Horiz";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "           " + Operation::writeInfos();
     }
 
     /**
@@ -1161,6 +1314,9 @@ class Haar3Horiz: public BiIntegralCenteredOps
      **/
     virtual OperationTypes getOps()
     {
+    if ( context )
+      return HAAR3HORIZ_C;
+    else
       return HAAR3HORIZ;
     }
 };
@@ -1198,7 +1354,14 @@ class Haar3Vert: public BiIntegralCenteredOps
      **/
     virtual std::string writeInfos()
     {
-      return "Haar3Vert" + Operation::writeInfos();
+      std::string out = "Haar3Vert";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "            " + Operation::writeInfos();
     }
 
     /**
@@ -1207,6 +1370,9 @@ class Haar3Vert: public BiIntegralCenteredOps
      **/
     virtual OperationTypes getOps()
     {
+    if ( context )
+      return HAAR3VERT_C;
+    else
       return HAAR3VERT;
     }
 };
@@ -1244,7 +1410,14 @@ class Haar3Stack: public BiIntegralCenteredOps
      **/
     virtual std::string writeInfos()
     {
-      return "Haar3Stack" + Operation::writeInfos();
+      std::string out = "Haar3Stack";
+
+        if ( context )
+          out = "(C)" + out;
+        else
+          out = "(R)" + out;
+
+      return out + "           " + Operation::writeInfos();
     }
 
     /**
@@ -1253,9 +1426,186 @@ class Haar3Stack: public BiIntegralCenteredOps
      **/
     virtual OperationTypes getOps()
     {
+    if ( context )
+      return HAAR3STACK_C;
+    else
       return HAAR3STACK;
     }
 };
 
-} //end namespace
+/**
+ * @brief Ray features
+ */
+/**
+ * @brief Ray Distance-Difference features
+ */
+class RayDiff: public Operation
+{
+  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 Operation* clone()
+    {
+      return new RayDiff();
+    }
+
+    /**
+     * @brief print some infos about operation extraction type
+     * @return string feature type
+     **/
+    virtual std::string writeInfos()
+    {
+      return "(-)RayDiff              " + Operation::writeInfos();
+    }
+
+    /**
+     * @brief return operation type (for store and restore)
+     * @return OperationTypes
+     **/
+    virtual OperationTypes getOps()
+    {
+      return RAYDIFF;
+    }
+};
+
+/**
+ * @brief Ray Distance features
+ */
+class RayDist: public Operation
+{
+  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 Operation* clone()
+    {
+      return new RayDist();
+    }
+
+    /**
+     * @brief print some infos about operation extraction type
+     * @return string feature type
+     **/
+    virtual std::string writeInfos()
+    {
+      return "(-)RayDist              " + Operation::writeInfos();
+    }
+
+    /**
+     * @brief return operation type (for store and restore)
+     * @return OperationTypes
+     **/
+    virtual OperationTypes getOps()
+    {
+      return RAYDIST;
+    }
+};
+
+/**
+ * @brief Ray Orientation features
+ */
+class RayTheta: public Operation
+{
+  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 Operation* clone()
+    {
+      return new RayTheta();
+    }
+
+    /**
+     * @brief print some infos about operation extraction type
+     * @return string feature type
+     **/
+    virtual std::string writeInfos()
+    {
+      return "(-)RayTheta             " + Operation::writeInfos();
+    }
+
+    /**
+     * @brief return operation type (for store and restore)
+     * @return OperationTypes
+     **/
+    virtual OperationTypes getOps()
+    {
+      return RAYTHETA;
+    }
+};
+
+/**
+ * @brief Ray Norm features
+ */
+class RayNorm: public Operation
+{
+  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 Operation* clone()
+    {
+      return new RayNorm();
+    }
+
+    /**
+     * @brief print some infos about operation extraction type
+     * @return string feature type
+     **/
+    virtual std::string writeInfos()
+    {
+      return "(-)RayNorm              " + Operation::writeInfos();
+    }
 
+    /**
+     * @brief return operation type (for store and restore)
+     * @return OperationTypes
+     **/
+    virtual OperationTypes getOps()
+    {
+      return RAYNORM;
+    }
+};
+
+} //end namespace