Quellcode durchsuchen

bug beim integralbilderberechnen behoben

Bjoern Froehlich vor 13 Jahren
Ursprung
Commit
812bfe9a73
4 geänderte Dateien mit 363 neuen und 402 gelöschten Zeilen
  1. 295 329
      semseg/SemSegContextTree.cpp
  2. 3 0
      semseg/SemSegContextTree.h
  3. 47 71
      semseg/operations/Operations.cpp
  4. 18 2
      semseg/operations/Operations.h

Datei-Diff unterdrückt, da er zu groß ist
+ 295 - 329
semseg/SemSegContextTree.cpp


+ 3 - 0
semseg/SemSegContextTree.h

@@ -101,6 +101,9 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
     /** use Gradient image or not */
     bool useGradient;
     
+    /** use Color features from van de Weijer or not */
+    bool useWeijer;
+    
     /** use Regions as extra feature channel or not */
     bool useRegionFeature;
 

+ 47 - 71
semseg/operations/Operations.cpp

@@ -31,6 +31,16 @@ bool Operation::getContext()
   return context;
 }
 
+void Operation::setFeatType ( int _featType )
+{
+  featType = _featType;
+}
+
+int Operation::getFeatType()
+{
+  return featType;
+}
+
 void Operation::getXY ( const Features &feats, int &xsize, int &ysize )
 {
   xsize = feats.feats->width();
@@ -40,7 +50,7 @@ void Operation::getXY ( const Features &feats, int &xsize, int &ysize )
 
 void Operation::store ( std::ostream & os )
 {
-  os << x1 << " " << x2 << " " << y1 << " " << y2 << " " << channel1 << " " << channel2 << std::endl;
+  os << x1 << " " << x2 << " " << y1 << " " << y2 << " " << channel1 << " " << channel2 << " " << featType << std::endl;
   if ( values == NULL )
     os << -1 << std::endl;
   else
@@ -55,6 +65,7 @@ void Operation::restore ( std::istream &is )
   is >> y2;
   is >> channel1;
   is >> channel2;
+  is >> featType;
 
   int tmp;
   is >> tmp;
@@ -148,99 +159,78 @@ double RelativeYPosition::getVal ( const Features &feats, const int &x, const in
 
 double IntegralOps::getVal ( const Features &feats, const int &x, const int &y )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
-  return computeMean ( *feats.feats, BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), channel1 );
+  return feats.feats->getIntegralValue(x + x1, y + y1, x + x2, y + y2, channel1);
 }
 
 double GlobalFeats::getVal ( const Features &feats, const int &x, const int &y )
 {
   int xsize, ysize;
   getXY ( feats, xsize, ysize );
-  return computeMean ( *feats.feats, 0, 0, xsize - 1, ysize - 1, channel1 );
+  return feats.feats->getIntegralValue( 0, 0, xsize - 1, ysize - 1, channel1 );
 }
 
 double IntegralCenteredOps::getVal ( const Features &feats, const int &x, const int &y )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
-  return computeMean ( *feats.feats, BOUND ( x - x1, 0, xsize - 1 ), BOUND ( y - y1, 0, ysize - 1 ), BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), channel1 );
+  return feats.feats->getIntegralValue(x - x1, y - y1, x + x1, y + y1, channel1);
 }
 
 double BiIntegralCenteredOps::getVal ( const Features &feats, const int &x, const int &y )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
-  return computeMean ( *feats.feats, BOUND ( x - x1, 0, xsize - 1 ), BOUND ( y - y1, 0, ysize - 1 ), BOUND ( x + x1, 0, xsize - 1 ), BOUND ( y + y1, 0, ysize - 1 ), channel1 ) - computeMean ( *feats.feats, BOUND ( x - x2, 0, xsize - 1 ), BOUND ( y - y2, 0, ysize - 1 ), BOUND ( x + x2, 0, xsize - 1 ), BOUND ( y + y2, 0, ysize - 1 ), channel1 );
+  return feats.feats->getIntegralValue(x - x1, y - y1, x + x1, y + y1, channel1 ) - feats.feats->getIntegralValue(x - x2, y - y2, x + x2, y + y2, channel1);
 }
 
 double HaarHorizontal::getVal ( const Features &feats, const int &x, const int &y )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
-
-  int tlx = BOUND ( x - x1, 0, xsize - 1 );
-  int tly = BOUND ( y - y1, 0, ysize - 1 );
-  int lrx = BOUND ( x + x1, 0, xsize - 1 );
-  int lry = BOUND ( y + y1, 0, ysize - 1 );
+  int tlx = x - x1;
+  int tly = y - y1;
+  int lrx = x + x1;
+  int lry = y + y1;
 
-  return computeMean ( *feats.feats, tlx, tly, lrx, y, channel1 ) - computeMean ( *feats.feats, tlx, y, lrx, lry, channel1 );
+  return feats.feats->getIntegralValue(tlx, tly, lrx, y, channel1 ) - feats.feats->getIntegralValue(tlx, y, lrx, lry, channel1);
 }
 
 double HaarVertical::getVal ( const Features &feats, const int &x, const int &y )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
+  int tlx = x - x1;
+  int tly = y - y1;
+  int lrx = x + x1;
+  int lry = y + y1;
 
-  int tlx = BOUND ( x - x1, 0, xsize - 1 );
-  int tly = BOUND ( y - y1, 0, ysize - 1 );
-  int lrx = BOUND ( x + x1, 0, xsize - 1 );
-  int lry = BOUND ( y + y1, 0, ysize - 1 );
-
-  return computeMean ( *feats.feats, tlx, tly, x, lry, channel1 ) - computeMean ( *feats.feats, x, tly, lrx, lry, channel1 );
+  return feats.feats->getIntegralValue(tlx, tly, x, lry, channel1) - feats.feats->getIntegralValue(x, tly, lrx, lry, channel1);
 }
 
 double HaarDiag::getVal ( const Features &feats, const int &x, const int &y )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
+  int tlx = x - x1;
+  int tly = y - y1;
+  int lrx = x + x1;
+  int lry = y + y1;
 
-  int tlx = BOUND ( x - x1, 0, xsize - 1 );
-  int tly = BOUND ( y - y1, 0, ysize - 1 );
-  int lrx = BOUND ( x + x1, 0, xsize - 1 );
-  int lry = BOUND ( y + y1, 0, ysize - 1 );
-
-  return computeMean ( *feats.feats, tlx, tly, x, y, channel1 ) + computeMean ( *feats.feats, x, y, lrx, lry, channel1 ) - computeMean ( *feats.feats, tlx, y, x, lry, channel1 ) - computeMean ( *feats.feats, x, tly, lrx, y, channel1 );
+  return feats.feats->getIntegralValue(tlx, tly, x, y, channel1) + feats.feats->getIntegralValue(x, y, lrx, lry, channel1) - feats.feats->getIntegralValue(tlx, y, x, lry, channel1) - feats.feats->getIntegralValue(x, tly, lrx, y, channel1);
 }
 
 double Haar3Horiz::getVal ( const Features &feats, const int &x, const int &y )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
-
-  int tlx = BOUND ( x - x2, 0, xsize - 1 );
-  int tly = BOUND ( y - y2, 0, ysize - 1 );
-  int mtly = BOUND ( y - y1, 0, ysize - 1 );
-  int mlry = BOUND ( y + y1, 0, ysize - 1 );
-  int lrx = BOUND ( x + x2, 0, xsize - 1 );
-  int lry = BOUND ( y + y2, 0, ysize - 1 );
-
-  return computeMean ( *feats.feats, tlx, tly, lrx, mtly, channel1 ) - computeMean ( *feats.feats, tlx, mtly, lrx, mlry, channel1 ) + computeMean ( *feats.feats, tlx, mlry, lrx, lry, channel1 );
+  int tlx = x - x2;
+  int tly = y - y2;
+  int mtly = y - y1;
+  int mlry = y + y1;
+  int lrx = x + x2;
+  int lry = y + y2;
+
+  return feats.feats->getIntegralValue(tlx, tly, lrx, mtly, channel1) - feats.feats->getIntegralValue(tlx, mtly, lrx, mlry, channel1) + feats.feats->getIntegralValue(tlx, mlry, lrx, lry, channel1);
 }
 
 double Haar3Vert::getVal ( const Features &feats, const int &x, const int &y )
 {
-  int xsize, ysize;
-  getXY ( feats, xsize, ysize );
-
-  int tlx = BOUND ( x - x2, 0, xsize - 1 );
-  int tly = BOUND ( y - y2, 0, ysize - 1 );
-  int mtlx = BOUND ( x - x1, 0, xsize - 1 );
-  int mlrx = BOUND ( x + x1, 0, xsize - 1 );
-  int lrx = BOUND ( x + x2, 0, xsize - 1 );
-  int lry = BOUND ( y + y2, 0, ysize - 1 );
-
-  return computeMean ( *feats.feats, tlx, tly, mtlx, lry, channel1 ) - computeMean ( *feats.feats, mtlx, tly, mlrx, lry, channel1 ) + computeMean ( *feats.feats, mlrx, tly, lrx, lry, channel1 );
+  int tlx = x - x2;
+  int tly = y - y2;
+  int mtlx = x - x1;
+  int mlrx = x + x1;
+  int lrx = x + x2;
+  int lry = y + y2;
+
+  return feats.feats->getIntegralValue(tlx, tly, mtlx, lry, channel1) - feats.feats->getIntegralValue(mtlx, tly, mlrx, lry, channel1) + feats.feats->getIntegralValue(mlrx, tly, lrx, lry, channel1);
 }
 
 void IntegralOps::set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values )
@@ -254,20 +244,6 @@ void IntegralOps::set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _
   values = _values;
 }
 
-double IntegralOps::computeMean ( const NICE::MultiChannelImageT<double> &intImg, const int &uLx, const int &uLy, const int &lRx, const int &lRy, const int &chan )
-{
-  double val1 = intImg.get ( uLx, uLy, chan );
-  double val2 = intImg.get ( lRx, uLy, chan );
-  double val3 = intImg.get ( uLx, lRy, chan );
-  double val4 = intImg.get ( lRx, lRy, chan );
-  double area = ( lRx - uLx ) * ( lRy - uLy );
-
-  if ( area == 0 )
-    return 0.0;
-
-  return ( val1 + val4 - val2 - val3 ) / area;
-}
-
 void IntegralCenteredOps::set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values )
 {
   x1 = abs ( _x1 );

+ 18 - 2
semseg/operations/Operations.h

@@ -274,6 +274,10 @@ class Operation
   protected:
     /** two different points (e.g. for an rectangle or two positions), channels and size  */
     int x1, y1, x2, y2, channel1, channel2, maxtypes;
+    
+    /** type of feature */
+    int featType;
+    
     ValueAccess *values;
 
     bool context;
@@ -309,6 +313,20 @@ class Operation
      * @return bool whether context is used or not
      **/
     bool getContext();
+    
+    /**
+     * @brief set type of feature
+     * @param _featType type of feature
+     * @return void nothing
+     **/
+    void setFeatType ( int _featType );
+
+    /**
+     * @brief return context information (set by setContext(bool)
+     *
+     * @return int get feature type
+     **/
+    int getFeatType();   
 
     /**
      * @brief abstract interface for feature computation
@@ -728,8 +746,6 @@ class IntegralOps: public Operation
      **/
     virtual double getVal ( const Features &feats, const int &x, const int &y );
 
-    inline double computeMean ( const NICE::MultiChannelImageT<double> &intImg, const int &uLx, const int &uLy, const int &lRx, const int &lRy, const int &chan );
-
     /**
      * @brief clone operation instead of copy constructor (copy constructor does not work)
      **/

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.