Переглянути джерело

Merge branch 'master' of /home/dbv/git/nice/vislearning

Erik Rodner 13 роки тому
батько
коміт
9d3f779306

+ 132 - 133
baselib/ColorSpace.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
  * @file ColorSpace.cpp
  * @brief __DESC__
  * @author Michael Koch
@@ -20,153 +20,152 @@ using namespace std;
 using namespace NICE;
 
 //bad position for this function
-void ColorSpace::ColorImagetoMultiChannelImage(const NICE::ColorImage &imgrgb,NICE::MultiChannelImageT<double> &genimg)
+void ColorSpace::ColorImagetoMultiChannelImage(  const NICE::ColorImage &imgrgb, NICE::MultiChannelImageT<double> &genimg )
 {
-     genimg.reInit(imgrgb.width(),imgrgb.height(),3,true);
-     for(int y=0;y<imgrgb.height();y++)
-     {
-          for(int x=0;x<imgrgb.width();x++)
-          {
-               double r,g,b;
-               r=imgrgb.getPixelQuick(x,y,0);
-               g=imgrgb.getPixelQuick(x,y,1);
-               b=imgrgb.getPixelQuick(x,y,2);
-               genimg.set(x,y,r,0);
-               genimg.set(x,y,g,1);
-               genimg.set(x,y,b,2);
-          }
-     }
+  genimg.reInit( imgrgb.width(), imgrgb.height(), 3, true );
+  for ( int y = 0;y < imgrgb.height();y++ )
+  {
+    for ( int x = 0;x < imgrgb.width();x++ )
+    {
+      double r, g, b;
+      r = imgrgb.getPixelQuick( x, y, 0 );
+      g = imgrgb.getPixelQuick( x, y, 1 );
+      b = imgrgb.getPixelQuick( x, y, 2 );
+      genimg.set( x, y, r, 0 );
+      genimg.set( x, y, g, 1 );
+      genimg.set( x, y, b, 2 );
+    }
+  }
 }
 
-/*
+
 //TODO test it
-int checkRange(int in,int min=0,int max=255)
+int checkRange( int in, int min = 0, int max = 255 )
 {
-     int out=in;
-     
-     if(in<min)
-     {
-          out=min;
-     }
-     if(in>max)
-     {
-          out=max;
-     }
-     return out;
+  int out = in;
+
+  if ( in < min )
+  {
+    out = min;
+  }
+  if ( in > max )
+  {
+    out = max;
+  }
+  return out;
 }
 
-NICE::ColorImage ColorSpace::rgbtohsl(const NICE::ColorImage &imgrgb)
+NICE::MultiChannelImageT<double> ColorSpace::rgbtohsl( const NICE::MultiChannelImageT<double> &imgrgb )
 {
-     NICE::ColorImage imghsl (imgrgb.width(), imgrgb.height());
-
-     for(int x=0;x<imgrgb.width();x++)
-     {
-          for(int y=0;y<imgrgb.height();y++)
-          {
-               double R,G,B,H,S,L;
-
-               R=(double)imgrgb.getPixel(x,y,0)/255.0;
-               G=(double)imgrgb.getPixel(x,y,1)/255.0;
-               B=(double)imgrgb.getPixel(x,y,2)/255.0;
-               ColorConversion::ccRGBtoHSL(R,G,B,&H,&S,&L);
-               imghsl.setPixel(x,y,0,(int)round(H*255.0));
-               imghsl.setPixel(x,y,1,(int)round(S*255.0));
-               imghsl.setPixel(x,y,2,(int)round(L*255.0));
-          }
-     }     
-     return imghsl;
+  NICE::MultiChannelImageT<double> imghsl( imgrgb.width(), imgrgb.height(), 3 );
+
+  for ( int x = 0;x < imgrgb.width();x++ )
+  {
+    for ( int y = 0;y < imgrgb.height();y++ )
+    {
+      double R, G, B, H, S, L;
+
+      R = ( double )imgrgb.get( x, y, 0 );
+      G = ( double )imgrgb.get( x, y, 1 );
+      B = ( double )imgrgb.get( x, y, 2 );
+      ColorConversion::ccRGBtoHSL( R, G, B, &H, &S, &L );
+      imghsl.set( x, y, H, 0 );
+      imghsl.set( x, y, S, 1 );
+      imghsl.set( x, y, L, 2 );
+    }
+  }
+  return imghsl;
 }
 
-NICE::ColorImage ColorSpace::hsltorgb(const NICE::ColorImage &imghsl)
+NICE::MultiChannelImageT<double> ColorSpace::hsltorgb( const NICE::MultiChannelImageT<double> &imghsl )
 {
-     NICE::ColorImage imgrgb (imghsl.width(), imghsl.height());
-
-     for(int x=0;x<imghsl.width();x++)
-     {
-          for(int y=0;y<imghsl.height();y++)
-          {
-               double R,G,B,H,S,L;
-               H=(double)imghsl.getPixel(x,y,0)/255.0;
-               S=(double)imghsl.getPixel(x,y,1)/255.0;
-               L=(double)imghsl.getPixel(x,y,2)/255.0;
-             
-               ColorConversion::ccHSLtoRGB(H,S,L,&R,&G,&B);
-
-               imgrgb.setPixel(x,y,0,(int)round(R*255.0));
-
-               imgrgb.setPixel(x,y,1,(int)round(G*255.0));
-
-               imgrgb.setPixel(x,y,2,(int)round(B*255.0));
-          }
-     }     
-     return imgrgb;
+  NICE::MultiChannelImageT<double> imgrgb( imghsl.width(), imghsl.height(), 3 );
+
+  for ( int x = 0;x < imghsl.width();x++ )
+  {
+    for ( int y = 0;y < imghsl.height();y++ )
+    {
+      double R, G, B, H, S, L;
+      H = ( double )imghsl.get( x, y, 0 );
+      S = ( double )imghsl.get( x, y, 1 );
+      L = ( double )imghsl.get( x, y, 2 );
+
+      ColorConversion::ccHSLtoRGB( H, S, L, &R, &G, &B );
+
+      imgrgb.set( x, y, ( int )round( R*255.0 ), 0 );
+      imgrgb.set( x, y, ( int )round( G*255.0 ), 1 );
+      imgrgb.set( x, y, ( int )round( B*255.0 ), 2 );
+    }
+  }
+  return imgrgb;
 }
-        
-NICE::ColorImage ColorSpace::rgbtolab(const NICE::ColorImage &imgrgb)
+
+NICE::MultiChannelImageT<double> ColorSpace::rgbtolab( const NICE::MultiChannelImageT<double> &imgrgb )
 {
-     NICE::ColorImage imglab (imgrgb.width(), imgrgb.height());
-     //preprocessing RGB to XYZ
-     for(int x=0;x<imgrgb.width();x++)
-     {
-          for(int y=0;y<imgrgb.height();y++)
-          {
-               double R,G,B,X,Y,Z,L,a,b;
-               R=(double)imgrgb.getPixel(x,y,0)/255.0;
-               G=(double)imgrgb.getPixel(x,y,1)/255.0;
-               B=(double)imgrgb.getPixel(x,y,2)/255.0;
-               ColorConversion::ccRGBtoXYZ(R,G,B,&X,&Y,&Z,0);
-               ColorConversion::ccXYZtoCIE_Lab(X,Y,Z,&L,&a,&b,0);
-               imglab.setPixel(x,y,0,(int)round(L*255.0));
-               imglab.setPixel(x,y,1,(int)round(a*255.0));
-               imglab.setPixel(x,y,2,(int)round(b*255.0));
-          }
-     }     
-	 showImage ( *imglab.getChannel(0), "L" );
-     return imglab;
+  NICE::MultiChannelImageT<double> imglab( imgrgb.width(), imgrgb.height(), 3 );
+  //preprocessing RGB to XYZ
+  for ( int x = 0;x < imgrgb.width();x++ )
+  {
+    for ( int y = 0;y < imgrgb.height();y++ )
+    {
+      double R, G, B, X, Y, Z, L, a, b;
+      R = ( double )imgrgb.get( x, y, 0 ) / 255.0;
+      G = ( double )imgrgb.get( x, y, 1 ) / 255.0;
+      B = ( double )imgrgb.get( x, y, 2 ) / 255.0;
+      
+      ColorConversion::ccRGBtoXYZ( R, G, B, &X, &Y, &Z, 0 );
+      ColorConversion::ccXYZtoCIE_Lab( X, Y, Z, &L, &a, &b, 0 );
+      
+      imglab.set( x, y, L, 0 );
+      imglab.set( x, y, a, 1 );
+      imglab.set( x, y, b, 2 );
+    }
+  }
+  return imglab;
 }
 
-NICE::ColorImage ColorSpace::labtorgb(const NICE::ColorImage &imglab)
+NICE::MultiChannelImageT<double> ColorSpace::labtorgb( const NICE::MultiChannelImageT<double> &imglab )
 {
-     NICE::ColorImage imgrgb (imglab.width(), imglab.height());
-     //preprocessing RGB to XYZ
-     for(int x=0;x<imglab.width();x++)
-     {
-          for(int y=0;y<imglab.height();y++)
-          {
-               double R,G,B,X,Y,Z,L,a,b;
-               L=(double)imglab.getPixel(x,y,0)/255.0;
-               a=(double)imglab.getPixel(x,y,1)/255.0;
-               b=(double)imglab.getPixel(x,y,2)/255.0;
-               
-               ColorConversion::ccCIE_LabtoXYZ(L,a,b,&X,&Y,&Z,0);
-               ColorConversion::ccXYZtoRGB(X,Y,Z,&R,&G,&B,0);
-               imgrgb.setPixel(x,y,0,(int)round(R*255.0));
-               imgrgb.setPixel(x,y,1,(int)round(G*255.0));
-               imgrgb.setPixel(x,y,2,(int)round(B*255.0));
-          }
-     }     
-     return imgrgb;
+  NICE::MultiChannelImageT<double> imgrgb( imglab.width(), imglab.height(), 3 );
+  //preprocessing RGB to XYZ
+  for ( int x = 0;x < imglab.width();x++ )
+  {
+    for ( int y = 0;y < imglab.height();y++ )
+    {
+      double R, G, B, X, Y, Z, L, a, b;
+      L = imglab.get( x, y, 0 );
+      a = imglab.get( x, y, 1 );
+      b = imglab.get( x, y, 2 );
+
+      ColorConversion::ccCIE_LabtoXYZ( L, a, b, &X, &Y, &Z, 0 );
+      ColorConversion::ccXYZtoRGB( X, Y, Z, &R, &G, &B, 0 );
+      imgrgb.set( x, y, round( R*255.0 ), 0 );
+      imgrgb.set( x, y, round( G*255.0 ), 1 );
+      imgrgb.set( x, y, round( B*255.0 ), 2 );
+    }
+  }
+  return imgrgb;
 }
-NICE::ColorImage ColorSpace::rgbtolms(const NICE::ColorImage &imgrgb)
-{
-     NICE::ColorImage imglms=NICE::ColorImage(imgrgb.width(),imgrgb.height());
-     //preprocessing RGB to XYZ
-     for(int x=0;x<imgrgb.width();x++)
-     {
-          for(int y=0;y<imgrgb.height();y++)
-          {
-               double R,G,B,X,Y,Z,L,M,S;
-               R=(double)imgrgb.getPixelQuick(x,y,0)/255.0;
-               G=(double)imgrgb.getPixelQuick(x,y,1)/255.0;
-               B=(double)imgrgb.getPixelQuick(x,y,2)/255.0;
-               
-               ColorConversion::ccRGBtoXYZ(R,G,B,&X,&Y,&Z,0);
-               ColorConversion::ccXYZtoLMS(X,Y,Z,&L,&M,&S);
-               imglms.setPixelQuick(x,y,0,checkRange((int)round(L*255.0)));
-               imglms.setPixelQuick(x,y,1,checkRange((int)round(M*255.0)));
-               imglms.setPixelQuick(x,y,2,checkRange((int)round(S*255.0)));
-          }
-     }     
-     return imglms;
-}*/
 
+NICE::MultiChannelImageT<double> ColorSpace::rgbtolms( const NICE::MultiChannelImageT<double> &imgrgb )
+{
+  NICE::MultiChannelImageT<double> imglms = NICE::MultiChannelImageT<double>( imgrgb.width(), imgrgb.height() );
+  //preprocessing RGB to XYZ
+  for ( int x = 0;x < imgrgb.width();x++ )
+  {
+    for ( int y = 0;y < imgrgb.height();y++ )
+    {
+      double R, G, B, X, Y, Z, L, M, S;
+      R = imgrgb.get( x, y, 0 ) / 255.0;
+      G = imgrgb.get( x, y, 1 ) / 255.0;
+      B = imgrgb.get( x, y, 2 ) / 255.0;
+
+      ColorConversion::ccRGBtoXYZ( R, G, B, &X, &Y, &Z, 0 );
+      ColorConversion::ccXYZtoLMS( X, Y, Z, &L, &M, &S );
+      imglms.set( x, y, L, 0 );
+      imglms.set( x, y, M, 1 );
+      imglms.set( x, y, S, 2 );
+    }
+  }
+  return imglms;
+}

+ 34 - 37
baselib/ColorSpace.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file ColorSpace.h
 * @brief color space conversion routines
 * @author Michael Koch
@@ -22,44 +22,41 @@ namespace OBJREC {
 class ColorSpace
 {
 
-    protected:
-
-    public:
-	enum {
-	    COLORSPACE_RGB = 0,
-	    COLORSPACE_HSL,
-	    COLORSPACE_LAB,
-        COLORSPACE_LMS,
-        COLORSPACE_OPP,
-	    NUM_COLORSPACES
-	};
+protected:
+
+public:
+  enum {
+    COLORSPACE_RGB = 0,
+    COLORSPACE_HSL,
+    COLORSPACE_LAB,
+    COLORSPACE_LMS,
+    COLORSPACE_OPP,
+    NUM_COLORSPACES
+  };
 //bad position choose better one
-    static void ColorImagetoMultiChannelImage(const NICE::ColorImage &imgrgb,NICE::MultiChannelImageT<double> &genimg);
-    
-#if 0	//entfernt, da Probleme mit Wertebereich, bitte GenericImage und generisches convert benutzen
-         /** convert RGB to hsl*/
-        static NICE::ColorImage rgbtohsl(const NICE::ColorImage &imgrgb);
-        /** convert hsl to RGB*/
-        static NICE::ColorImage hsltorgb(const NICE::ColorImage &imghsl);
-        
-        /** convert RGB to LAB*/
-        static NICE::ColorImage rgbtolab(const NICE::ColorImage &imgrgb);
-        
-        /** convert LAB to RGB*/
-        static NICE::ColorImage labtorgb(const NICE::ColorImage &imglab);
-        
-        /** convert RGB to LMS*/
-        
-        static NICE::ColorImage rgbtolms(const NICE::ColorImage &imgrgb);*/
-#endif
+  static void ColorImagetoMultiChannelImage( const NICE::ColorImage &imgrgb, NICE::MultiChannelImageT<double> &genimg );
+
+  /** convert RGB to hsl*/
+  static NICE::MultiChannelImageT<double> rgbtohsl( const NICE::MultiChannelImageT<double> &imgrgb );
+  /** convert hsl to RGB*/
+  static NICE::MultiChannelImageT<double> hsltorgb( const NICE::MultiChannelImageT<double> &imghsl );
+
+  /** convert RGB to LAB*/
+  static NICE::MultiChannelImageT<double> rgbtolab( const NICE::MultiChannelImageT<double> &imgrgb );
+
+  /** convert LAB to RGB*/
+  static NICE::MultiChannelImageT<double> labtorgb( const NICE::MultiChannelImageT<double> &imglab );
+
+  /** convert RGB to LMS*/
+  static NICE::MultiChannelImageT<double> rgbtolms( const NICE::MultiChannelImageT<double> &imgrgb );
 
-	template<class SrcPixelType,class DstPixelType>
-	static void convert ( NICE::MultiChannelImageT<DstPixelType> & dst, 
-			      const NICE::MultiChannelImageT<SrcPixelType> & src,
-			      int dstColorSpace = COLORSPACE_HSL, 
-			      int srcColorSpace = COLORSPACE_RGB,
-			      double dstM = 255.0,
-			      double srcM = 255.0);
+  template<class SrcPixelType, class DstPixelType>
+  static void convert( NICE::MultiChannelImageT<DstPixelType> & dst,
+                       const NICE::MultiChannelImageT<SrcPixelType> & src,
+                       int dstColorSpace = COLORSPACE_HSL,
+                       int srcColorSpace = COLORSPACE_RGB,
+                       double dstM = 255.0,
+                       double srcM = 255.0 );
 };
 
 } // namespace

+ 60 - 57
baselib/ICETools.cpp

@@ -17,6 +17,8 @@
 
 #include "vislearning/baselib/ICETools.h"
 
+#include "core/basics/Exception.h"
+
 using namespace OBJREC;
 
 using namespace std;
@@ -33,67 +35,68 @@ ICETools::~ICETools()
 
 void ICETools::selectRectangles ( const NICE::Image & panel, NICE::Image & overlay, vector<Vector> & x, int color )
 {
-#ifndef NOVISUAL
-    // new NICE code
-    vector<RectT<double> > rectangles;
-	 //TODO check this!
-//     NICE::selectRectangles ( panel, rectangles, "select rectangles" );
-// 	 selectRectangles ( panel, rectangles, "select rectangles" );
-
-    for ( vector<RectT<double> >::const_iterator i = rectangles.begin();
-	i != rectangles.end(); i++ )
-    {
-	Vector vec (4);
-	vec[0] = i->left;
-	vec[1] = i->top;
-	vec[2] = i->right();
-	vec[3] = i->bottom();
-
-	x.push_back ( vec ); 
-    }
-#else
-    fprintf (stderr, "ICETools::selectRectangles: visualization disabled !\n");
-#endif
-
+	fthrow(Exception, "ICETools::selectRectangles -- not yet implemented due to old ICE version.");
+// #ifndef NOVISUAL
+//     // new NICE code
+//     vector<RectT<double> > rectangles;
+// 	 //TODO check this!
+// //     NICE::selectRectangles ( panel, rectangles, "select rectangles" );
+// // 	 selectRectangles ( panel, rectangles, "select rectangles" );
+// 
+//     for ( vector<RectT<double> >::const_iterator i = rectangles.begin();
+// 	i != rectangles.end(); i++ )
+//     {
+// 	Vector vec (4);
+// 	vec[0] = i->left;
+// 	vec[1] = i->top;
+// 	vec[2] = i->right();
+// 	vec[3] = i->bottom();
+// 
+// 	x.push_back ( vec ); 
+//     }
+// #else
+//     fprintf (stderr, "ICETools::selectRectangles: visualization disabled !\n");
+// #endif
 }
 
 void ICETools::selectPoints ( const NICE::Image & panel, NICE::Image & overlay, vector<Vector> & x, int color )
 {
-#ifndef NOVISUAL
-    vector<CoordT<double> > points;
-	 //TODO check this!
-//     NICE::selectPoints ( panel, points, "select points" );
-// 	selectPoints ( panel, points, "select points" );
-
-    for ( vector<CoordT<double> >::const_iterator i = points.begin();
-	i != points.end(); i++ )
-    {
-	Vector vec (2);
-	vec[0] = i->x;
-	vec[1] = i->y;
-
-	x.push_back ( vec ); 
-    }
-   
-    /** OLD ICE Code
-    int p[2];
-    int rc = -1;
-
-    while ( (rc = SelPoint ( DEFAULT, panel, p )) != -1 )
-    {
-        int x1, y1;
-        x1 = p[0]; y1 = p[1];
-        // refactor-nice.pl: check this substitution
-        // old: Marker ( DEFAULT, p[0], p[1], color, 5, overlay );
-        // REFACTOR-FIXME Unable to map this statement
-        // refactor-nice.pl: check this substitution
-        // old: x.push_back ( Vector(x1, y1) );
-        // REFACTOR-FIXME Unable to std::map this statement
-    }
-    */
-#else
-    fprintf (stderr, "ICETools::selectPoints: visualization disabled !\n");
-#endif
+	fthrow(Exception, "ICETools::selectPoints -- not yet implemented due to old ICE version.");
+// #ifndef NOVISUAL
+//     vector<CoordT<double> > points;
+// 	 //TODO check this!
+// //     NICE::selectPoints ( panel, points, "select points" );
+// // 	selectPoints ( panel, points, "select points" );
+// 
+//     for ( vector<CoordT<double> >::const_iterator i = points.begin();
+// 	i != points.end(); i++ )
+//     {
+// 	Vector vec (2);
+// 	vec[0] = i->x;
+// 	vec[1] = i->y;
+// 
+// 	x.push_back ( vec ); 
+//     }
+//    
+//     /** OLD ICE Code
+//     int p[2];
+//     int rc = -1;
+// 
+//     while ( (rc = SelPoint ( DEFAULT, panel, p )) != -1 )
+//     {
+//         int x1, y1;
+//         x1 = p[0]; y1 = p[1];
+//         // refactor-nice.pl: check this substitution
+//         // old: Marker ( DEFAULT, p[0], p[1], color, 5, overlay );
+//         // REFACTOR-FIXME Unable to map this statement
+//         // refactor-nice.pl: check this substitution
+//         // old: x.push_back ( Vector(x1, y1) );
+//         // REFACTOR-FIXME Unable to std::map this statement
+//     }
+//     */
+// #else
+//     fprintf (stderr, "ICETools::selectPoints: visualization disabled !\n");
+// #endif
 
 }
 

+ 170 - 173
features/fpfeatures/HaarFeature.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file HaarFeature.cpp
 * @brief simple haar like feature
 * @author Erik Rodner
@@ -12,76 +12,73 @@
 #include "vislearning/cbaselib/FeaturePool.h"
 
 using namespace OBJREC;
-
 using namespace std;
-// refactor-nice.pl: check this substitution
-// old: using namespace ice;
 using namespace NICE;
 
 
-void HaarFeature::explode ( FeaturePool & featurePool, bool variableWindow ) const
+void HaarFeature::explode( FeaturePool & featurePool, bool variableWindow ) const
 {
-    HaarFeature *hf = new HaarFeature ( *this );
-
-    hf->pos1 = 0;
-    hf->pos2 = 0;
-    hf->type = HAARTYPE_HORIZONTAL;  
-    for ( hf->pos1 = 0 ; hf->pos1 < hf->window_size_y - 1 ; hf->pos1 += hf->step_y )
-	featurePool.addFeature ( hf->clone(), hf->step_y / (double)( HAARTYPE_NUMTYPES * hf->window_size_y ) );
-
-    hf->pos1 = 0;
-    hf->pos2 = 0;
-    hf->type = HAARTYPE_VERTICAL;
-    for ( hf->pos1 = 0 ; hf->pos1 < hf->window_size_x - 1; hf->pos1 += hf->step_x )
-	featurePool.addFeature ( hf->clone(), hf->step_x / (double)( HAARTYPE_NUMTYPES * hf->window_size_x ) );
-
-    hf->type = HAARTYPE_DIAGONAL;
-    hf->pos1 = 0;
-    hf->pos2 = 0;
-    for ( hf->pos1 = 0 ; hf->pos1 < hf->window_size_x - 1; hf->pos1 += hf->step_x )
-	for ( hf->pos2 = 0 ; hf->pos2 < hf->window_size_y - 1 ; hf->pos2 += hf->step_y )
-	    featurePool.addFeature ( hf->clone(), 
-		hf->step_x * hf->step_y / (double)( HAARTYPE_NUMTYPES * hf->window_size_x * hf->window_size_y ) );
-
-    hf->pos1 = 0;
-    hf->pos2 = 0;
-    hf->type = HAARTYPE_3BLOCKS;
-    for ( hf->pos1 = 0 ; hf->pos1 < hf->window_size_x - 2*hf->step_x ; hf->pos1 += hf->step_x )
-	for ( hf->pos2 = hf->pos1 + hf->step_x; hf->pos2 < hf->window_size_x - hf->step_x ; hf->pos2 += hf->step_x )
-	    featurePool.addFeature ( hf->clone(), 
-		(2.0 * hf->step_x) / ( HAARTYPE_NUMTYPES * (hf->window_size_x - hf->step_x) ) 	);
-
-    delete hf;
+  HaarFeature *hf = new HaarFeature( *this );
+
+  hf->pos1 = 0;
+  hf->pos2 = 0;
+  hf->type = HAARTYPE_HORIZONTAL;
+  for ( hf->pos1 = 0 ; hf->pos1 < hf->window_size_y - 1 ; hf->pos1 += hf->step_y )
+    featurePool.addFeature( hf->clone(), hf->step_y / ( double )( HAARTYPE_NUMTYPES * hf->window_size_y ) );
+
+  hf->pos1 = 0;
+  hf->pos2 = 0;
+  hf->type = HAARTYPE_VERTICAL;
+  for ( hf->pos1 = 0 ; hf->pos1 < hf->window_size_x - 1; hf->pos1 += hf->step_x )
+    featurePool.addFeature( hf->clone(), hf->step_x / ( double )( HAARTYPE_NUMTYPES * hf->window_size_x ) );
+
+  hf->type = HAARTYPE_DIAGONAL;
+  hf->pos1 = 0;
+  hf->pos2 = 0;
+  for ( hf->pos1 = 0 ; hf->pos1 < hf->window_size_x - 1; hf->pos1 += hf->step_x )
+    for ( hf->pos2 = 0 ; hf->pos2 < hf->window_size_y - 1 ; hf->pos2 += hf->step_y )
+      featurePool.addFeature( hf->clone(),
+                              hf->step_x * hf->step_y / ( double )( HAARTYPE_NUMTYPES * hf->window_size_x * hf->window_size_y ) );
+
+  hf->pos1 = 0;
+  hf->pos2 = 0;
+  hf->type = HAARTYPE_3BLOCKS;
+  for ( hf->pos1 = 0 ; hf->pos1 < hf->window_size_x - 2*hf->step_x ; hf->pos1 += hf->step_x )
+    for ( hf->pos2 = hf->pos1 + hf->step_x; hf->pos2 < hf->window_size_x - hf->step_x ; hf->pos2 += hf->step_x )
+      featurePool.addFeature( hf->clone(),
+                              ( 2.0 * hf->step_x ) / ( HAARTYPE_NUMTYPES * ( hf->window_size_x - hf->step_x ) ) );
+
+  delete hf;
 }
 
 Feature *HaarFeature::clone() const
 {
-    HaarFeature *fp =  new HaarFeature(*this);
-    return fp;
+  HaarFeature *fp =  new HaarFeature( *this );
+  return fp;
 }
 
 
 /************* HaarFeature **************/
 HaarFeature::HaarFeature( const Config *conf )
 {
-    window_size_x = conf->gI("HaarFeature", "window_size_x", 24 );
-    window_size_y = conf->gI("HaarFeature", "window_size_y", 24 );
-    step_x = conf->gI("HaarFeature", "step_x", 1 );
-    step_y = conf->gI("HaarFeature", "step_y", 1 );
+  window_size_x = conf->gI( "HaarFeature", "window_size_x", 24 );
+  window_size_y = conf->gI( "HaarFeature", "window_size_y", 24 );
+  step_x = conf->gI( "HaarFeature", "step_x", 1 );
+  step_y = conf->gI( "HaarFeature", "step_y", 1 );
 }
 
-HaarFeature::HaarFeature ( int _window_size_x,	
-			   int _window_size_y,
-			   int _step_x,
-			   int _step_y )
+HaarFeature::HaarFeature( int _window_size_x,
+                          int _window_size_y,
+                          int _step_x,
+                          int _step_y )
 {
-    window_size_x = _window_size_x;
-    window_size_y = _window_size_y;
-    pos1 = 1;
-    pos2 = 0;
-    step_x = _step_x;
-    step_y = _step_y;
-    type = HaarFeature::HAARTYPE_HORIZONTAL;
+  window_size_x = _window_size_x;
+  window_size_y = _window_size_y;
+  pos1 = 1;
+  pos2 = 0;
+  step_x = _step_x;
+  step_y = _step_y;
+  type = HaarFeature::HAARTYPE_HORIZONTAL;
 }
 
 HaarFeature::~HaarFeature()
@@ -90,134 +87,134 @@ HaarFeature::~HaarFeature()
 
 double HaarFeature::val( const Example *example ) const
 {
-    const NICE::MultiChannelImageT<long> & img = example->ce->getLChannel ( CachedExample::L_INTEGRALIMAGE ); 
-
-    const long *integralImage = img.data[0];
-    int xsize = img.xsize;
-    int ysize = img.ysize;
-
-    int x = example->x;
-    int y = example->y;
-    long tl, tr, bl, br;
-
-    int exwidth = example->width;
-    if ( exwidth != 0 ) 
-    {
-	int exheight = example->height;
-	tl = (x - exwidth/2) + (y - exheight/2)*xsize;
-	tr = tl + exwidth - 1;
-	bl = tl + (exheight - 1)*xsize;
-	br = bl + exwidth - 1;
-    } else {
-	tl = (x - window_size_x/2) + (y - window_size_y/2)*xsize;
-	tr = tl + window_size_x - 1;
-	bl = tl + (window_size_y - 1)*xsize;
-	br = bl + (window_size_x - 1);
-    }
-
-    assert ( tl < xsize*ysize );
-    assert ( tr < xsize*ysize );
-    if ( br >= xsize*ysize ) 
-    {
-	fprintf (stderr, "xsize=%d, ysize=%d, x=%d, y=%d, wsy=%d, wsx=%d\n",
-		xsize, ysize, x, y, window_size_x, window_size_y );
-	fprintf (stderr, "example: %d x %d\n",
-		example->width, example->height );
-
-    }
-    assert ( bl < xsize*ysize );
-    assert ( br < xsize*ysize );
-    assert ( pos1 >= 0 );
-    assert ( pos2 >= 0 );
-
-    double value;
-    if ( type == HaarFeature::HAARTYPE_HORIZONTAL )
-    {
-	long ml = tl + xsize*pos1;
-	long mr = tr + xsize*pos1;
-	assert ( (ml >= 0) && (ml < xsize*ysize) );
-	assert ( (mr >= 0) && (mr < xsize*ysize) );
-	value = 2*integralImage[mr];
-	value -= 2*integralImage[ml];
-	value +=   integralImage[tl];
-	value +=   integralImage[tr];
-	value -=   integralImage[bl];
-	value -=   integralImage[br];
-    } else if ( type == HaarFeature::HAARTYPE_VERTICAL ) {
-	long mt = tl + pos1;
-	long mb = bl + pos1;
-	assert ( (mt >= 0) && (mt < xsize*ysize) );
-	assert ( (mb >= 0) && (mb < xsize*ysize) );
-
-	value = 2*integralImage[mb];
-	value -= 2*integralImage[mt];
-	value +=   integralImage[tl];
-	value +=   integralImage[tr];
-	value -=   integralImage[bl];
-	value -=   integralImage[br];
-    } else if ( type == HaarFeature::HAARTYPE_DIAGONAL ) {
-	int p2o = pos2*xsize;
-	assert ( (p2o >= 0) && (p2o < xsize*ysize) );
-	assert ( (tl+pos1 >= 0) && (tl+pos1 < xsize*ysize) );
-	assert ( (tl+p2o >= 0) && (tl+p2o < xsize*ysize) );
-	assert ( (bl+pos1 >= 0) && (bl+pos1 < xsize*ysize) );
-	assert ( (tr+p2o >= 0) && (tr+p2o < xsize*ysize) );
-	assert ( (tl+pos1+p2o >= 0) && (tl+pos1+p2o < xsize*ysize) );
-
-	value = integralImage[tl];
-	value += integralImage[bl];
-	value += integralImage[br];
-	value += integralImage[tr];
-	value -= 2 * ( 
-		  integralImage[tl+pos1]
-		+ integralImage[tl+p2o]
-		+ integralImage[bl+pos1]
-		+ integralImage[tr+p2o]
-	     );
-	value += 4 * integralImage[tl + pos1 + p2o];
-
-    } else if ( type == HaarFeature::HAARTYPE_3BLOCKS ) {
-	assert ( (tl+pos1 >= 0) && (tl+pos1 < xsize*ysize) );
-	assert ( (bl+pos2 >= 0) && (bl+pos2 < xsize*ysize) );
-	assert ( (tl+pos2 >= 0) && (tl+pos2 < xsize*ysize) );
-	assert ( (bl+pos1 >= 0) && (bl+pos1 < xsize*ysize) );
-	value = integralImage[tl];
-	value +=  integralImage[br];
-	value -=  integralImage[bl];
-	value -=  integralImage[tr];
-	value += 2 * (
-		- integralImage[tl+pos1]
-		- integralImage[bl+pos2]
-		+ integralImage[tl+pos2]
-		+ integralImage[bl+pos1]
-	    );
-    } else {
-	return -1;
-    }
-
-    assert ( finite(value) );
-
-    return value;
+  const NICE::MultiChannelImageT<long> & img = example->ce->getLChannel( CachedExample::L_INTEGRALIMAGE );
+
+  const long *integralImage = img.data[0];
+  int xsize = img.xsize;
+  int ysize = img.ysize;
+
+  int x = example->x;
+  int y = example->y;
+  long tl, tr, bl, br;
+
+  int exwidth = example->width;
+  if ( exwidth != 0 )
+  {
+    int exheight = example->height;
+    tl = ( x - exwidth / 2 ) + ( y - exheight / 2 ) * xsize;
+    tr = tl + exwidth - 1;
+    bl = tl + ( exheight - 1 ) * xsize;
+    br = bl + exwidth - 1;
+  } else {
+    tl = ( x - window_size_x / 2 ) + ( y - window_size_y / 2 ) * xsize;
+    tr = tl + window_size_x - 1;
+    bl = tl + ( window_size_y - 1 ) * xsize;
+    br = bl + ( window_size_x - 1 );
+  }
+
+  assert( tl < xsize*ysize );
+  assert( tr < xsize*ysize );
+  if ( br >= xsize*ysize )
+  {
+    fprintf( stderr, "xsize=%d, ysize=%d, x=%d, y=%d, wsy=%d, wsx=%d\n",
+             xsize, ysize, x, y, window_size_x, window_size_y );
+    fprintf( stderr, "example: %d x %d\n",
+             example->width, example->height );
+
+  }
+  assert( bl < xsize*ysize );
+  assert( br < xsize*ysize );
+  assert( pos1 >= 0 );
+  assert( pos2 >= 0 );
+
+  double value;
+  if ( type == HaarFeature::HAARTYPE_HORIZONTAL )
+  {
+    long ml = tl + xsize * pos1;
+    long mr = tr + xsize * pos1;
+    assert(( ml >= 0 ) && ( ml < xsize*ysize ) );
+    assert(( mr >= 0 ) && ( mr < xsize*ysize ) );
+    value = 2 * integralImage[mr];
+    value -= 2 * integralImage[ml];
+    value +=   integralImage[tl];
+    value +=   integralImage[tr];
+    value -=   integralImage[bl];
+    value -=   integralImage[br];
+  } else if ( type == HaarFeature::HAARTYPE_VERTICAL ) {
+    long mt = tl + pos1;
+    long mb = bl + pos1;
+    assert(( mt >= 0 ) && ( mt < xsize*ysize ) );
+    assert(( mb >= 0 ) && ( mb < xsize*ysize ) );
+
+    value = 2 * integralImage[mb];
+    value -= 2 * integralImage[mt];
+    value +=   integralImage[tl];
+    value +=   integralImage[tr];
+    value -=   integralImage[bl];
+    value -=   integralImage[br];
+  } else if ( type == HaarFeature::HAARTYPE_DIAGONAL ) {
+    int p2o = pos2 * xsize;
+    assert(( p2o >= 0 ) && ( p2o < xsize*ysize ) );
+    assert(( tl + pos1 >= 0 ) && ( tl + pos1 < xsize*ysize ) );
+    assert(( tl + p2o >= 0 ) && ( tl + p2o < xsize*ysize ) );
+    assert(( bl + pos1 >= 0 ) && ( bl + pos1 < xsize*ysize ) );
+    assert(( tr + p2o >= 0 ) && ( tr + p2o < xsize*ysize ) );
+    assert(( tl + pos1 + p2o >= 0 ) && ( tl + pos1 + p2o < xsize*ysize ) );
+
+    value = integralImage[tl];
+    value += integralImage[bl];
+    value += integralImage[br];
+    value += integralImage[tr];
+    value -= 2 * (
+               integralImage[tl+pos1]
+               + integralImage[tl+p2o]
+               + integralImage[bl+pos1]
+               + integralImage[tr+p2o]
+             );
+    value += 4 * integralImage[tl + pos1 + p2o];
+
+  } else if ( type == HaarFeature::HAARTYPE_3BLOCKS ) {
+    assert(( tl + pos1 >= 0 ) && ( tl + pos1 < xsize*ysize ) );
+    assert(( bl + pos2 >= 0 ) && ( bl + pos2 < xsize*ysize ) );
+    assert(( tl + pos2 >= 0 ) && ( tl + pos2 < xsize*ysize ) );
+    assert(( bl + pos1 >= 0 ) && ( bl + pos1 < xsize*ysize ) );
+    value = integralImage[tl];
+    value +=  integralImage[br];
+    value -=  integralImage[bl];
+    value -=  integralImage[tr];
+    value += 2 * (
+               - integralImage[tl+pos1]
+               - integralImage[bl+pos2]
+               + integralImage[tl+pos2]
+               + integralImage[bl+pos1]
+             );
+  } else {
+    return -1;
+  }
+
+  assert( finite( value ) );
+
+  return value;
 }
 
-void HaarFeature::restore (istream & is, int format)
+void HaarFeature::restore( istream & is, int format )
 {
-    is >> type;
-    is >> window_size_x;
-    is >> window_size_y;
-    is >> pos1;
-    is >> pos2;
+  is >> type;
+  is >> window_size_x;
+  is >> window_size_y;
+  is >> pos1;
+  is >> pos2;
 }
 
-void HaarFeature::store (ostream & os, int format) const
+void HaarFeature::store( ostream & os, int format ) const
 {
-    os << "HAARFEATURE" << " " << type << " " 
-       << window_size_x << " " << window_size_y 
-       << " " << pos1 << " " << pos2;
+  os << "HAARFEATURE" << " " << type << " "
+  << window_size_x << " " << window_size_y
+  << " " << pos1 << " " << pos2;
 }
 
-void HaarFeature::clear ()
+void HaarFeature::clear()
 {
-    // nothing to do in my opinion
+  // nothing to do in my opinion
 }
 

+ 0 - 847
features/gradientfeatures/PHOGFeature.cpp~

@@ -1,847 +0,0 @@
-/** 
-* @file PHOGFeature.cpp
-* @brief Implementation of the PHOG-Features and corresponding Kernel as done by Anna Bosch et al.
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-
-#include "PHOGFeature.h"
-
-using namespace std;
-using namespace OBJREC;
-using namespace NICE;
-
-/** protected things*/
-/**
-* @brief Calculates the PHOG-Pyramide for given gradient images (idea of Anna Bosch and Andrew Zisserman)
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-void PHOGFeature::calculate_PHOG_Pyramide(const NICE::Image & gradient_orientations, const NICE::ImageT<float> & gradient_magnitudes, std::vector< std::vector<float> > & PHOG_descriptor)
-{
-	float sum_of_all = 0.0;
-	float sum_of_level = 0.0;
-
-	std::vector<float> one_collecting_vector;
-	one_collecting_vector.clear();
-	std::vector<float> HoG (number_Of_Bins);
-	for (int j = 0; j < gradient_orientations.height(); j++)
-		for (int i = 0; i < gradient_orientations.width(); i++)
-		{
-			int orientation (gradient_orientations(i,j));
-			if (( (orientation<0) || ((uint)orientation>=HoG.size())) && verbose)
-			{
-				cerr << "orientation is " << orientation << " and does not fit to HoG.size(): " << HoG.size() << endl;
-				cerr << "i: " << i << " j: " << j << " gradient_orientations.width() : " <<  gradient_orientations.width() << " gradient_orientations.height() : " << gradient_orientations.height() << endl;
-			}
-			HoG[gradient_orientations(i,j)] += gradient_magnitudes(i,j);
-			sum_of_all += gradient_magnitudes(i,j);
-			sum_of_level += gradient_magnitudes(i,j);
-		}
-		
-	switch(histrogram_concatenation)
-	{
-		case 0:
-		{
-			if (sum_of_level != 0.0)  //normalize the descriptor-entries
-			{
-				for (std::vector<float>::iterator HoG_it = HoG.begin(); HoG_it != HoG.end(); HoG_it++)
-				{
-					*HoG_it /= sum_of_level;
-				}
-			}
-			PHOG_descriptor.push_back(HoG);
-			break;
-		}
-		case 1:
-		{
-			if (sum_of_level != 0.0)  //normalize the descriptor-entries
-			{
-				for (std::vector<float>::iterator HoG_it = HoG.begin(); HoG_it != HoG.end(); HoG_it++)
-				{
-					*HoG_it /= sum_of_level;
-				}
-			}
-			PHOG_descriptor.push_back(HoG);
-			break;
-		}
-		case 2:
-		{
-			one_collecting_vector.insert(one_collecting_vector.begin()+one_collecting_vector.size(), HoG.begin(), HoG.end());
-			break;
-		}
-	}
-	sum_of_all += sum_of_level;
-
-	if (verbose) cerr << "PHOGFeature::calculate_PHOG_Pyramide -- Level 0 calculated, working on finer levels" << endl;
-	if (verbose) cerr << "gradient_orientations.width(): " << gradient_orientations.width() << " gradient_orientations.height(): " << gradient_orientations.height() << endl;
-
-	//further levels
-	for (int level = 1; level < number_of_Levels; level++) 
-	{
-		if (verbose) cerr << "PHOGFeature::calculate_PHOG_Pyramide -- working on level "<< level << endl;
-		if (like_AnnaBosch)
-		{
-			int step_x = (int) floor(gradient_orientations.width() / pow(2,level) );
-			int step_y = (int) floor(gradient_orientations.height() / pow(2,level) );
-
-			vector<float> PHoG_level;
-
-			int run_y = 0;
-			for (int y_counter = 0; y_counter < pow(2.0,level) ; y_counter++) 
-			{
-				int run_x = 0;
-				for (int x_counter = 0; x_counter < pow(2.0,level) ; x_counter++)
-				{
-					vector<float> HoG_local (number_Of_Bins);
-					float sum_of_hog(0.0);
-	
-					//check, wether rectangle lies on the boundary, if so, then correct the max-step
-					int y_max = (run_y + step_y);
-					if (gradient_orientations.height() < y_max)
-						y_max = gradient_orientations.height();
-	
-					int x_max = (run_x + step_x);
-					if (gradient_orientations.width() < x_max)
-						x_max = gradient_orientations.width();
-	
-					for (int j = run_y; j < y_max; j++)
-						for (int i = run_x; i < x_max; i++)
-						{
-							int orientation = 0;
-							try{	orientation = gradient_orientations(i,j);
-							}
-							catch( ... )
-							{
-								cerr << "WARNING: PHOGFeature::calculate_PHOG_Pyramide gradient_orientations(i,j) not possible. (i,j): " << i << " " << j << endl;
-							}
-							float magnitude = 0.0;
-							try{	magnitude = gradient_magnitudes(i,j);
-							}
-							catch( ... )
-							{
-								cerr << "WARNING: PHOGFeature::calculate_PHOG_Pyramide radient_magnitudes(i,j) not possible. (i,j): " << i << " " << j << endl;
-							}
- 							HoG_local[orientation] += magnitude;
-							sum_of_hog += magnitude;
-						}
-
-					sum_of_level += sum_of_hog;
-					
-					switch(histrogram_concatenation)
-					{
-						case 0:
-						{
-							if (sum_of_hog != 0.0)  //normalize the descriptor-entries
-							{
-								for (std::vector<float>::iterator hog_it = HoG_local.begin(); hog_it != HoG_local.end(); hog_it++)
-								{
-									*hog_it /= sum_of_hog;
-								}
-							}
-							PHOG_descriptor.push_back(HoG_local);
-							break;
-						}
-						case 1:
-						{
-							for (std::vector<float>::const_iterator foo = HoG_local.begin(); foo != HoG_local.end(); foo++)
-							{
-								PHoG_level.insert(PHoG_level.begin()+PHoG_level.size(), HoG_local.begin(), HoG_local.end());
-							}
-							break;
-						}
-						case 2:
-						{
-								PHoG_level.insert(PHoG_level.begin()+PHoG_level.size(), HoG_local.begin(), HoG_local.end());
-							break;
-						}
-					}
-	
-					run_x = run_x + step_x;
-				}
-				run_y = run_y + step_y;
-			}
-			
-			sum_of_all += sum_of_level;
-			
-			switch(histrogram_concatenation)
-			{
-				case 0:
-				{
-					break;
-				}
-				case 1:
-				{
-					if (sum_of_level != 0.0)  //normalize the descriptor-entries
-					{
-						for (std::vector<float>::iterator Level_it = PHoG_level.begin(); Level_it != PHoG_level.end(); Level_it++)
-						{
-							*Level_it /= sum_of_level;
-						}
-					}
-					PHOG_descriptor.push_back(PHoG_level);
-					break;
-				}
-				case 2:
-				{
-					one_collecting_vector.insert(one_collecting_vector.begin()+one_collecting_vector.size(), PHoG_level.begin(), PHoG_level.end());
-					break;
-				}
-			}
-		}
-		else //better than anna bosch
-		{
-			int step_x = (int) ceil(gradient_orientations.width() / pow(2.0,level) );
-			int step_y = (int) ceil(gradient_orientations.height() / pow(2.0,level) );
-			if (verbose) cerr << "step_x: " << step_x << " step_y: " << step_y << endl;
-
-			std::vector<float> PHoG_level;
-	
-			int run_y = 0;
-			for (int y_counter = 0; y_counter < pow(2,level) ; y_counter++) 
-			{
-				int run_x = 0;
-				if (verbose) cerr << "run_y: " << run_y << endl;
-				for (int x_counter = 0; x_counter < pow(2,level) ; x_counter++)
-				{
-					if (verbose) cerr << "run_x: " << run_x << endl;
-					float sum_of_hog(0.0);
-					vector<float> HoG_local (number_Of_Bins);
-	
-					//check, wether rectangle lies on the boundary, if so, then correct the max-step
-					int y_max = (run_y + step_y);
-					if (gradient_orientations.height() < y_max)
-					{
-						if (verbose) cerr << "y_max old:: " << y_max << " y_max_new: "<<gradient_orientations.height() << endl;
-						y_max = gradient_orientations.height();
-						
-					}
-	
-					int x_max = (run_x + step_x);
-					if (gradient_orientations.width() < x_max)
-					{
-						if (verbose) cerr << "x_max old:: " << x_max << " x_max_new: "<<gradient_orientations.width() << endl;
-						x_max = gradient_orientations.width();
-						
-					}
-			
-					for (int j = run_y; j < y_max; j++)
-						for (int i = run_x; i < x_max; i++)
-						{
-							int orientation = 0;
-							try{	orientation = gradient_orientations.getPixel(i,j);
-							}
-							catch( ... )
-							{
-								cerr << "WARNING: PHOGFeature::calculate_PHOG_Pyramide gradient_orientations(i,j) not possible. (i,j): " << i << " " << j << endl;
-							}
-							float magnitude = 0.0;
-							try{	magnitude = gradient_magnitudes.getPixel(i,j);
-							}
-							catch( ... )
-							{
-								cerr << "WARNING: PHOGFeature::calculate_PHOG_Pyramide gradient_magnitudes(i,j) not possible. (i,j): " << i << " " << j << endl;
-							}
-							if ( (orientation<0) || ((uint)orientation>=HoG_local.size()))
-							{
-								cerr << "orientation is " << orientation << " and does not fit to HoG_local.size(): " << HoG_local.size() << endl;
-								cerr << "i: " << i << " j: " << j << " gradient_orientations.width() : " <<  gradient_orientations.width() << " gradient_orientations.height() : " << gradient_orientations.height() << endl;
-							}
- 							try{
-								HoG_local[orientation] += magnitude;
-							}
-							catch( ... )
-							{
-								cerr << "WARNING: PHOGFeature::calculate_PHOG_Pyramide HoG_local[orientation] += magnitude not possible. orientation: " << orientation << " magnitude " << magnitude << endl;
-							}
-							sum_of_hog += magnitude;
-						}
-					sum_of_level += sum_of_hog;
-					
-					switch(histrogram_concatenation)
-					{
-						case 0:
-						{
-							if (sum_of_hog != 0.0)  //normalize the descriptor-entries
-							{
-								for (std::vector<float>::iterator hog_it = HoG_local.begin(); hog_it != HoG_local.end(); hog_it++)
-								{
-									*hog_it /= sum_of_hog;
-								}
-							}
-							PHOG_descriptor.push_back(HoG_local);
-							break;
-						}
-						case 1:
-						{
-							for (std::vector<float>::const_iterator foo = HoG_local.begin(); foo != HoG_local.end(); foo++)
-							{
-								PHoG_level.insert(PHoG_level.begin()+PHoG_level.size(), HoG_local.begin(), HoG_local.end());
-							}
-							break;
-						}
-						case 2:
-						{
-								PHoG_level.insert(PHoG_level.begin()+PHoG_level.size(), HoG_local.begin(), HoG_local.end());
-							break;
-						}
-					}
-	
-					run_x = run_x + step_x;
-				}
-				run_y = run_y + step_y;
-			}
-			sum_of_all += sum_of_level;
-			
-			switch(histrogram_concatenation)
-			{
-				case 0:
-				{
-					break;
-				}
-				case 1:
-				{
-					if (sum_of_level != 0.0)  //normalize the descriptor-entries
-					{
-						for (std::vector<float>::iterator Level_it = PHoG_level.begin(); Level_it != PHoG_level.end(); Level_it++)
-						{
-							*Level_it /= sum_of_level;
-						}
-					}
-					PHOG_descriptor.push_back(PHoG_level);
-					break;
-				}
-				case 2:
-				{
-					one_collecting_vector.insert(one_collecting_vector.begin()+one_collecting_vector.size(), PHoG_level.begin(), PHoG_level.end());
-					break;
-				}
-			}
-		}
-	}
-	
-	if (histrogram_concatenation == ALL)
-	{
-		if (sum_of_all != 0.0)  //normalize the descriptor-entries
-		{
-			for (std::vector<float>::iterator it = one_collecting_vector.begin(); it != one_collecting_vector.end(); it++)
-			{
-				*it /= sum_of_all;
-			}
-		}
-		PHOG_descriptor.push_back(one_collecting_vector);
-	}
-}
-
-/**
-* @brief Calculates resulting PHOG-Features for the specified ROI in the given image
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-std::vector< std::vector<float> > PHOGFeature::calculate_PHOG_Features(const NICE::Image & orig_Image, const NICE::Rect & roi)
-{
-	if (like_AnnaBosch) //not supported right now!
-	{
-		std::cerr << "PHOGFeature::calculate_PHOG_Features is not supported right now" << std::endl;
-// 		//Canny Edge Detector
-// 		Image canny_Image;
-// 		canny_Image = (*canny(orig_Image, 10,30) );
-// 
-// 		//gradient-calculation
-// 		GrayImage16s* grad_x_Image= sobelX(canny_Image);
-// 		GrayImage16s* grad_y_Image = sobelY(canny_Image);
-// 		if (verbose)	cerr << "gradient-calculation done" << endl;
-// 
-// 		//gradient-orientation-calculation
-// 		NICE::Image gradient_orientations;
-// 		image_tool.calculateGradientOrientations( *grad_x_Image, *grad_y_Image, number_Of_Bins, gradient_orientations, unsignedBins);
-// 		if (verbose)	cerr << "gradient-orientation-calculation done" << endl;
-// 
-// 		//gradient-magnitude-calculation
-// 		//maybe this is not good - implicit cast from int to float in image structure
-// 		NICE::Image* gradient_magnitudes_int = gradientStrength( (*grad_x_Image), (*grad_y_Image) );
-// 		NICE::ImageT<float> gradient_magnitudes(orig_Image.width(), orig_Image.height());
-// 		for (int y = 0; y < orig_Image.height(); y++)
-// 			for (int x = 0; x < orig_Image.width(); x++)
-// 			{
-// 				gradient_magnitudes.setPixel(x,y,(*gradient_magnitudes_int).getPixel(x,y));
-// 			}
-// 		if (verbose)	cerr << "gradient-magnitude-calculation done" << endl;
-// 		
-// 		NICE::Image go_roi (gradient_orientations.subImage(roi));
-// 		NICE::ImageT<float> gm_roi (gradient_magnitudes.subImage(roi));
-// 
-// 	//pyramide-calculation
-// 
-		std::vector< std::vector<float> > PHOG_pyramide;
-// 		calculate_PHOG_Pyramide(go_roi, gm_roi, PHOG_pyramide);
-// 
-// 		if (verbose) cerr << "Pyramide-calculation done" << endl;
-
-		return PHOG_pyramide;
-
-	}
-	else
-	{
-		//gradient-calculation
-		NICE::ImageT<float> grad_x_Image;
-		NICE::ImageT<float> grad_y_Image;
-		image_tool.calculateGradients(orig_Image, grad_x_Image, grad_y_Image );
-		if (verbose)	cerr << "gradient-calculation done" << endl;
-
-		//gradient-orientation-calculation
-		NICE::Image gradient_orientations;
-		image_tool.calculateGradientOrientations(grad_x_Image, grad_y_Image, number_Of_Bins, gradient_orientations, unsignedBins);
-		if (verbose) 	cerr << "gradient-orientation-calculation done" << endl;
-
-		//gradient-magnitude-calculation
-		NICE::ImageT<float> gradient_magnitudes;
-		image_tool.calculateGradientMagnitudes(grad_x_Image, grad_y_Image, gradient_magnitudes);
-		if (verbose) 	cerr << "gradient-magnitude-calculation done" << endl;
-
-		NICE::Image go_roi (gradient_orientations.subImage(roi));
-		NICE::ImageT<float> gm_roi (gradient_magnitudes.subImage(roi));
-
-	//pyramide-calculation
-
-		std::vector< std::vector<float> > PHOG_pyramide;
-		calculate_PHOG_Pyramide(go_roi, gm_roi, PHOG_pyramide);
-
-		if (verbose) cerr << "Pyramide-calculation done" << endl;
-
-		return PHOG_pyramide;
-	}
-}
-//TODO ebenso für Farbbilder, falls das erwünscht ist. Frau Bosch macht einfach nur eine Grauwertkonvertierunt, also auch nicht so schön, wie Dalal und Triggs.!
-
-
-/** public things*/
-
-/** 
-* @brief Simple Default Constructor 
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-PHOGFeature::PHOGFeature()
-{
-	image_tool = OBJREC::Image_tools();
-	number_Of_Bins = 9;
-	unsignedBins = true;
-	number_of_Levels = 3;
-	like_AnnaBosch = false;
-	distances_only_between_levels = true;
-	histrogram_concatenation = NONE;
-	verbose = false;
-}
-
-/** 
-* @brief Recommended Constructor 
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-PHOGFeature::PHOGFeature( const Config *conf, std::string section)
-{
-	image_tool = OBJREC::Image_tools();
-	number_Of_Bins = conf->gI("PHOGFeature", "number_Of_Bins", 9);
-	unsignedBins = conf->gB("PHOGFeature", "unsignedBins", true);
-	number_of_Levels = conf->gI("PHOGFeature", "number_of_Levels", 3);
-	like_AnnaBosch = conf->gB("PHOGFeature", "like_AnnaBosch", false);
-	distances_only_between_levels = conf->gB("PHOGFeature", "distances_only_between_levels", true);
-	switch(conf->gI("PHOGFeature", "histrogram_concatenation", 0) )
-	{
-		case 0:
-		{histrogram_concatenation = NONE; break;}
-		case 1:
-		{histrogram_concatenation = LEVELWISE; break;}
-		case 2:
-		{histrogram_concatenation = ALL; break;}
-	}
-	verbose = conf->gB("PHOGFeature", "verbose", false);
-}
-
-/** 
-* @brief Simple Destructor 
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-PHOGFeature::~PHOGFeature()
-{
-
-}
-
-
-/** 
-* @brief Creating the PHOG-featureVectores of all trainingexamples
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-// std::vector<std::vector< std::vector<float> > >  PHOGFeature::createAllFeatureVectors(const OBJREC::LabeledSet::Permutation & order)
-// {
-// 
-// 	std::vector<std::vector< std::vector<float> > > PHOG_Features_all_images;
-// 
-// 	ProgressBar pb_createFV ("PHOGFeature::createAllFeatureVectors");
-// 	pb_createFV.show();
-// 
-// 	uint k = 0;
-// 	for ( LabeledSet::Permutation::const_iterator i = order.begin(); i != order.end(); i++,k++  )
-// 	{
-// 		string imgfilename = (*i).second->img();
-// 
-// 		NICE::Image img(imgfilename);
-// 
-// 		NICE::Rect roi = NICE::Rect(0,0,img.width(),img.height());
-// 		vector<vector<float> > PHOG = calculate_PHOG_Features(img, roi);
-// 
-// 		PHOG_Features_all_images.push_back ( PHOG );
-// 
-// 		pb_createFV.update ( order.size() );
-// 	}
-// 
-// 	// hide the last progress bar
-// 	pb_createFV.hide();
-// 
-// 	return PHOG_Features_all_images;
-// }
-
-
-/** 
-* @brief Creating the PHOG-featureVectores of all trainingexamples
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-// std::vector<std::vector< std::vector<float> > >  PHOGFeature::createAllFeatureVectors(const OBJREC::LabeledSet::Permutation & order, std::vector< NICE::Image > & gradient_orientations, std::vector<NICE::ImageT<float> > & gradient_magnitudes)
-// {
-// 
-// 	std::vector<std::vector< std::vector<float> > > PHOG_Features_all_images;
-// 
-// 	cerr << "Calculating gradient orientations." << endl;
-// 	gradient_orientations = calculate_gradient_orientations(order);
-// 	cerr << "Calculating gradient magnitudes." << endl;
-// 	gradient_magnitudes = calculate_gradient_magnitudes(order);
-// 
-// 	ProgressBar pb_quantization ("PHOGFeature::createAllFeatureVectors");
-// 	pb_quantization.show();
-// 
-// 	uint k = 0;
-// 	for ( LabeledSet::Permutation::const_iterator i = order.begin(); i != order.end(); i++,k++  )
-// 	{
-// 		std::string imgfilename = (*i).second->img();
-// 
-// 		NICE::Image img(imgfilename);
-// 
-// 		std::vector<std::vector<float> > PHOG;
-// 		calculate_PHOG_Pyramide(gradient_orientations[k], gradient_magnitudes[k], PHOG);
-// 
-// 		PHOG_Features_all_images.push_back ( PHOG );
-// 
-// 		pb_quantization.update ( order.size() );
-// 	}
-// 
-// 	// hide the last progress bar
-// 	pb_quantization.hide();
-// 
-// 	return PHOG_Features_all_images;
-// }
-
-/** 
-* @brief Creating the PHOG-featureVectores of all trainingexamples
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-// // // std::vector<std::vector< std::vector<float> > >  PHOGFeature::createAllFeatureVectors(const OBJREC::LabeledSet::Permutation & order, const std::vector<int> & trainSelection)
-// // // {
-// // // 
-// // // 	std::vector<std::vector< std::vector<float> > > PHOG_Features_all_images;
-// // // 
-// // // 	ProgressBar pb_quantization ("PHOGFeature::createAllFeatureVectors");
-// // // 	pb_quantization.show();
-// // // 
-// // // 	uint k = 0;
-// // // 	for ( std::vector<int>::const_iterator i = trainSelection.begin(); i != trainSelection.end(); i++,k++ )
-// // // 	{
-// // // 		if (verbose) cerr << " Image number " << *i << " will be treated now" << endl;
-// // // 		string imgfilename = order[*i].second->img();
-// // // 
-// // // 		NICE::Image img(imgfilename);
-// // // 
-// // // 		NICE::Rect roi = NICE::Rect(0,0,img.width(),img.height());
-// // // 		vector<vector<float> > PHOG = calculate_PHOG_Features(img, roi);
-// // // 
-// // // 		PHOG_Features_all_images.push_back ( PHOG );
-// // // 
-// // // 		pb_quantization.update ( trainSelection.size() );
-// // // 	}
-// // // 
-// // // 	// hide the last progress bar
-// // // 	pb_quantization.hide();
-// // // 
-// // // 	return PHOG_Features_all_images;
-// // // }
-// // 
-// // 
-// // 
-/** 
-* @brief Creating the PHOG-featureVectore for one trainingexample
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-std::vector<std::vector<float> > PHOGFeature::createOneFeatureVector(const std::string & imgfilename, const NICE::Rect & ROI)
-{
-	NICE::Image img(imgfilename);
-
-	std::vector<std::vector<float> > PHOG (calculate_PHOG_Features(img, ROI));
-
-	return PHOG;
-}
-
-/** 
-* @brief Creating the PHOG-featureVectore for one trainingexample
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-std::vector<std::vector<float> > PHOGFeature::createOneFeatureVector(const std::string & imgfilename)
-{
-	NICE::Image img(imgfilename);
-	NICE::Rect ROI(0,0,img.width(), img.height());
-
-	std::vector<std::vector<float> > PHOG (calculate_PHOG_Features(img, ROI));
-
-	return PHOG;
-}
-
-/** 
-* @brief Creating the PHOG-featureVectore for one trainingexample
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-std::vector<std::vector<float> > PHOGFeature::createOneFeatureVector(const NICE::Image img, const NICE::Rect & ROI)
-{
-	std::vector<std::vector<float> > PHOG (calculate_PHOG_Features(img, ROI));
-
-	return PHOG;
-}
-
-/** 
-* @brief Creating the PHOG-featureVectore for one trainingexample
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-std::vector<std::vector<float> > PHOGFeature::createOneFeatureVector(const NICE::Image img)
-{
-	NICE::Rect ROI(0,0,img.width(), img.height());
-	std::vector<std::vector<float> > PHOG (calculate_PHOG_Features(img, ROI));
-
-	return PHOG;
-}
-
-/** 
-* @brief computes the featurevector for the given image, which is already converted to a gradient-image, just considering features in the specified ROI
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-std::vector< std::vector<float> > PHOGFeature::createOneFeatureVectorDirect(NICE::Image & gradient_orientations, NICE::ImageT<float> & gradient_magnitudes, const NICE::Rect & ROI)
-{
-	NICE::Image ROI_go (gradient_orientations.subImage(ROI));
-	NICE::ImageT<float> ROI_gm (gradient_magnitudes.subImage(ROI));
-
-	std::vector< std::vector<float> > PHOG_pyramide;
-	calculate_PHOG_Pyramide(ROI_go, ROI_gm, PHOG_pyramide);
-
-	return PHOG_pyramide;
-}
-
-/** 
-* @brief computes the featurevector for the given image, which is already converted to a gradient-image, considering the whole image
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-std::vector< std::vector<float> > PHOGFeature::createOneFeatureVectorDirect(NICE::Image & gradient_orientations, NICE::ImageT<float> & gradient_magnitudes)
-{
-	NICE::Image ROI_go (gradient_orientations);
-	NICE::ImageT<float> ROI_gm (gradient_magnitudes);
-
-	std::vector< std::vector<float> > PHOG_pyramide;
-	calculate_PHOG_Pyramide(ROI_go, ROI_gm, PHOG_pyramide );
-
-	return PHOG_pyramide;
-}
-// // 
-// // /** 
-// // * @brief computes the gradient-orientation-images of all training-images
-// // * @author Alexander Lütz
-// // * @date 15/11/2011
-// // */
-// // std::vector< NICE::Image> PHOGFeature::calculate_gradient_orientations(const OBJREC::LabeledSet::Permutation & order)
-// // {
-// // 	std::vector< NICE::Image> gradient_orientations;
-// // 
-// // 	for(OBJREC::LabeledSet::Permutation::const_iterator i = order.begin(); i != order.end(); i++)
-// // 	{
-// // 		string filename = (*i).second->img();
-// // 		NICE::Image img (filename);
-// // 		//gradient-calculation
-// // 		NICE::ImageT<float> grad_x_Image;
-// // 		NICE::ImageT<float> grad_y_Image;
-// // 		image_tool.calculateGradients(img, grad_x_Image, grad_y_Image );
-// // 	
-// // 		//gradient-orientation-calculation
-// // 		NICE::Image gradient_orientation_image;
-// // 		image_tool.calculateGradientOrientations(grad_x_Image, grad_y_Image, number_Of_Bins, gradient_orientation_image, unsignedBins);
-// // 
-// // 		gradient_orientations.push_back(gradient_orientation_image);
-// // 	}
-// // 
-// // 	return gradient_orientations;
-// // }
-// 
-// /** 
-// * @brief computes the gradient-magnitudes-images of all training-images
-// * @author Alexander Lütz
-// * @date 15/11/2011
-// */
-// std::vector< NICE::ImageT<float> > PHOGFeature::calculate_gradient_magnitudes(const OBJREC::LabeledSet::Permutation & order)
-// {
-// 	std::vector< NICE::ImageT<float> > gradient_magnitudes;
-// 
-// 	for(OBJREC::LabeledSet::Permutation::const_iterator i = order.begin(); i != order.end(); i++)
-// 	{
-// 		string filename = (*i).second->img();
-// 		Image img (filename);
-// 		//gradient-calculation
-// 		NICE::ImageT<float> grad_x_Image;
-// 		NICE::ImageT<float> grad_y_Image;
-// 		image_tool.calculateGradients(img, grad_x_Image, grad_y_Image );
-// 	
-// 		//gradient-orientation-calculation
-// 		NICE::ImageT<float> gradient_magnitude_image;
-// 		image_tool.calculateGradientMagnitudes(grad_x_Image, grad_y_Image, gradient_magnitude_image);
-// 
-// 		gradient_magnitudes.push_back(gradient_magnitude_image);
-// 	}
-// 
-// 	return gradient_magnitudes;
-// }
-
-/** 
-* @brief computes the gradient-orientation-images of all training-images
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-NICE::Image PHOGFeature::calculate_gradient_orientations(const std::string & imgfilenam)
-{
-	NICE::Image gradient_orientations;
-
-	NICE::Image img (imgfilenam);
-	//gradient-calculation
-	NICE::ImageT<float> grad_x_Image;
-	NICE::ImageT<float> grad_y_Image;
-	image_tool.calculateGradients(img, grad_x_Image, grad_y_Image );
-
-	//gradient-orientation-calculation
-	NICE::Image gradient_orientation_image;
-	image_tool.calculateGradientOrientations(grad_x_Image, grad_y_Image, number_Of_Bins, gradient_orientation_image, unsignedBins);
-
-	return gradient_orientations;
-}
-
-/** 
-* @brief computes the gradient-magnitudes-images of all training-images
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-NICE::ImageT<float> PHOGFeature::calculate_gradient_magnitudes(const std::string & imgfilename)
-{
-	NICE::ImageT<float> gradient_magnitudes;
-
-	Image img (imgfilename);
-	//gradient-calculation
-	NICE::ImageT<float> grad_x_Image;
-	NICE::ImageT<float> grad_y_Image;
-	image_tool.calculateGradients(img, grad_x_Image, grad_y_Image );
-
-	//gradient-orientation-calculation
-	NICE::ImageT<float> gradient_magnitude_image;
-	image_tool.calculateGradientMagnitudes(grad_x_Image, grad_y_Image, gradient_magnitude_image);
-
-	return gradient_magnitudes;
-}
-
-/** 
-* @brief Compute the resulting kernel measuring the distance between the given feature-vectores
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-void PHOGFeature::calculate_Kernel_from_Features(const std::vector<std::vector< std::vector<float> > > & PHoG_Features, NICE::Matrix & PHoG_Kernel){
-
-// 	ProgressBar pb_kernelcalc ("PHOGFeature::Kernel Calculation");
-// 	pb_kernelcalc.show();
-	PHoG_Kernel = NICE::Matrix(PHoG_Features.size(), PHoG_Features.size(), 0.0);
-	uint ik = 0;
-	for ( std::vector< std::vector < std::vector<float> > >::const_iterator i = PHoG_Features.begin();i != PHoG_Features.end(); i++,ik++ )
-	{
-		uint jk = ik;
-		for ( std::vector< std::vector< std::vector<float> > >::const_iterator j = i; 
-			j != PHoG_Features.end(); j++,jk++ )
-		{
-			double kernelValue (measureDistance(*i,*j));
-		
-			PHoG_Kernel(ik,jk) = kernelValue;
-			PHoG_Kernel(jk,ik) = kernelValue;
-		}
-// 		pb_kernelcalc.update ( PHoG_Features.size() );
-	}
-}
-
-/** 
-* @brief function which computes the exp^(-Chi^2)-kernel of two PHOG-feature-vectores a and b
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-double PHOGFeature::measureDistance ( const std::vector<std::vector<float> > & a, const std::vector<std::vector<float> > & b )
-{
-	double expChi_value = 0.0;
-
-	if (a.size() != b.size() ) {
-		cerr << "a.size(): " << a.size() << " and b.size(): " << b.size() << endl;
-		fthrow(IOException, "Sizes of PHOG-Feature-vectores do not fit!");
-	}
-
-	for (uint i = 0; i < a.size(); i++)  //run over every HoG-Level 
-	{
-		std::vector<float> a_intern = a[i];
-		std::vector<float> b_intern = b[i];
-
-		double chi_value = 0.0;
-
-		if (a_intern.size() != b_intern.size() )  {
-			cerr << "a_intern.size(): " << a_intern.size() << " and b_intern.size(): " << b_intern.size() << endl;
-			fthrow(IOException, "Sizes of PHOG-Feature-vectores do not fit!");
-		}
-
-		for (uint j = 0; j < a_intern.size(); j++) //run over every HoG-entry of this level
-		{
-			float u = a_intern[j];
-			float v = b_intern[j];
-			float s = ( u + v );
-			if ( fabs(s) < 10e-6 ) continue;
-			float d = u-v;
-			chi_value += d*d / s;
-		}
-
-		chi_value *= 0.5;
-		expChi_value += exp(-chi_value);
-	}
-	expChi_value /= a.size(); //normalize to be in between zero and one
-
-	return expChi_value;
-}
-
-/** 
-* @brief Simply set the verbose-flag
-* @author Alexander Lütz
-* @date 15/11/2011
-*/
-void PHOGFeature::set_verbose(const bool & new_verbose){
-	verbose = new_verbose;
-}

+ 0 - 89
features/gradientfeatures/PHOGFeature.h~

@@ -1,89 +0,0 @@
-/** 
-* @file PHOGFeature.h
-* @author Alexander Lütz
-* @date 15/11/2011
-
-*/
-#ifndef _NICE_OBJREC_PHOGFEATUREINCLUDE
-#define _NICE_OBJREC_PHOGFEATUREINCLUDE
-
-#include "vislearning/baselib/Config.h"
-// #include "vislearning/cbaselib/MultiDataset.h"
-#include "Image_tools.h"
-
-namespace OBJREC {
-  
-/** @class PHOGFeature
- * Implementation of the PHOG-Features and corresponding Kernel as done by Anna Bosch et al.
- *
- * @author Alexander Lütz
- */
-
-
-class PHOGFeature
-{
-
-	public:
-		enum Histrogram_concatenation{NONE=0, LEVELWISE=1, ALL=2};
-
-	protected:
-		
-	Image_tools image_tool;
-	int number_Of_Bins;
-	bool unsignedBins;
-	int number_of_Levels;
-	bool like_AnnaBosch;
-	bool distances_only_between_levels;
-	Histrogram_concatenation histrogram_concatenation;
-	bool verbose;
-
-	/** Calculates the PHOG-Pyramide for given gradient images (idea of Anna Bosch and Andrew Zisserman)*/
-	void calculate_PHOG_Pyramide(const NICE::Image & gradient_orientations, const NICE::ImageT<float> & gradient_magnitudes,std::vector< std::vector<float> > & PHOG_descriptor);
-
-	/** Calculates resulting PHOG-Features for the specified ROI in the given image*/
-	std::vector< std::vector<float> > calculate_PHOG_Features(const NICE::Image & orig_Image, const NICE::Rect & roi);
-
-    public:
-		PHOGFeature();
-
-		/** recommended constructor */
-		PHOGFeature( const OBJREC::Config *conf, string section = "PHOGFeature");
-
-		/** simple destructor */
-		virtual ~PHOGFeature();
-
-//  		std::vector<std::vector< std::vector<float> > > createAllFeatureVectors(const OBJREC::LabeledSet::Permutation & order);
-// 
-// 		std::vector<std::vector< std::vector<float> > > createAllFeatureVectors(const OBJREC::LabeledSet::Permutation & order, std::vector< NICE::Image > & gradient_orientations, std::vector< NICE::ImageT<float> > & gradient_magnitudes);
-// 
-// 		std::vector<std::vector< std::vector<float> > > createAllFeatureVectors(const OBJREC::LabeledSet::Permutation & order, const std::vector<int> & trainSelection);
-
-
-		std::vector< std::vector<float> > createOneFeatureVector(const std::string & imgfilename, const NICE::Rect & ROI);
-		std::vector< std::vector<float> > createOneFeatureVector(const NICE::Image img, const NICE::Rect & ROI);
-		std::vector< std::vector<float> > createOneFeatureVector(const std::string & imgfilename);
-		std::vector< std::vector<float> > createOneFeatureVector(const NICE::Image img);
-
-		/** computes the featurevector for the given image, which is already converted to a gradient-image*/
-		std::vector< std::vector<float> > createOneFeatureVectorDirect(NICE::Image & gradient_orientations, NICE::ImageT<float> & gradient_magnitudes, const NICE::Rect & ROI);
-		std::vector< std::vector<float> > createOneFeatureVectorDirect(NICE::Image & gradient_orientations, NICE::ImageT<float> & gradient_magnitudes);
-
-// 		std::vector< NICE::Image> calculate_gradient_orientations(const OBJREC::LabeledSet::Permutation & order);
-// 		std::vector< NICE::ImageT<float> > calculate_gradient_magnitudes(const OBJREC::LabeledSet::Permutation &
-		NICE::Image calculate_gradient_orientations(const std::string & imgfilename);
-		NICE::ImageT<float> calculate_gradient_magnitudes(const std::string & imgfilename);
-
-		/**Compute the resulting kernel measuring the distance between the given feature-vectores*/
-		void calculate_Kernel_from_Features(const std::vector<std::vector< std::vector<float> > > & PHoG_Features, NICE::Matrix & PHoG_Kernel);
-
-		virtual double measureDistance ( const std::vector< std::vector<float> > & a, const std::vector< std::vector<float> > & b  );
-
-		virtual void sayYourName() {std::cerr << "I'm the PHOG-Feature." << std::endl;};
-
-		void set_verbose(const bool & new_verbose);
-		void set_histrogram_concatenation(const Histrogram_concatenation & _histrogram_concatenation){histrogram_concatenation = _histrogram_concatenation; std::cerr << "histrogram_concatenation: " << histrogram_concatenation << endl;};
-};
-
-}
-
-#endif

+ 0 - 82
features/gradientfeatures/progs/testPHOGFeatures.cpp~

@@ -1,82 +0,0 @@
-#include <iostream>
-#include "vislearning/baselib/Config.h"
-#include "vislearning/features/gradientfeatures/PHOGFeature.h"
-
-using namespace std;
-using namespace NICE;
-using namespace OBJREC;
-
-int main(int argc, char **argv)
-{	
-	Config *conf;
-	std::string imgfilename ("/progs/square_black.jpg");
-	if(argc < 1)
-	{
-		std::cerr << "No config file given, use default config and ./progs/square_black.jpg instaed" << std::endl;
-		conf = new Config();
-		
-		char path_c[512];
-		getcwd(path_c, 512);
-
-		if (path_c == NULL)
-		{ 
-			std::cerr << "default image is not readable. Aborting." << std::endl; 
-			return -1 ;
-		}
-		std::string path(path_c);
-		imgfilename = path + imgfilename;
-	}
-	else
-	{
-		conf = new Config( argc, argv );
-
-		imgfilename = conf->gS("main", "imgfilename", "");
-		if (imgfilename.compare("") == 0)
-		{
-			std::cerr << "No input image given. Aborting!" << std::endl;
-			return -1;
-		}
-	}
-
-	PHOGFeature PHOG(conf);
-	
-	PHOG.sayYourName();
-	
-	std::cerr << "Without concatenating any histogram resulting in \sum_{i=0}{level} 4^i histograms." << std::endl;
-	PHOG.set_histrogram_concatenation(OBJREC::PHOGFeature::NONE);
-	std::vector<std::vector<float> > resulting_feature = PHOG.createOneFeatureVector(imgfilename);
-	for (std::vector<std::vector<float> >::const_iterator i = resulting_feature.begin(); i != resulting_feature.end(); i++)
-	{
-		for (std::vector<float>::const_iterator j = (*i).begin(); j != (*i).end(); j++)
-		{
-			std::cerr << *j << " ";
-		}
-		std::cerr << std::endl << std::endl;
-	}
-	
-	std::cerr << "Concatenating histograms LEVELWISE resulting in #level histograms." << std::endl;
-	PHOG.set_histrogram_concatenation(OBJREC::PHOGFeature::LEVELWISE);
-	resulting_feature = PHOG.createOneFeatureVector(imgfilename);
-	for (std::vector<std::vector<float> >::const_iterator i = resulting_feature.begin(); i != resulting_feature.end(); i++)
-	{
-		for (std::vector<float>::const_iterator j = (*i).begin(); j != (*i).end(); j++)
-		{
-			std::cerr << *j << " ";
-		}
-		std::cerr << std::endl << std::endl;
-	}
-	
-	std::cerr << "Concatenating ALL histograms resulting in 1 final histogram." << std::endl;
-	PHOG.set_histrogram_concatenation(OBJREC::PHOGFeature::ALL);
-	resulting_feature = PHOG.createOneFeatureVector(imgfilename);
-	for (std::vector<std::vector<float> >::const_iterator i = resulting_feature.begin(); i != resulting_feature.end(); i++)
-	{
-		for (std::vector<float>::const_iterator j = (*i).begin(); j != (*i).end(); j++)
-		{
-			std::cerr << *j << " ";
-		}
-		std::cerr << std::endl << std::endl;
-	}
-
-	return 0;
-}

+ 413 - 416
features/localfeatures/LFColorWeijer.cpp

@@ -1,5 +1,5 @@
 #include "vislearning/features/localfeatures/LFColorWeijer.h"
-  
+
 #include <fstream>
 #include <iostream>
 #include "vislearning/baselib/ColorSpace.h"
@@ -11,485 +11,482 @@ using namespace std;
 using namespace NICE;
 
 //! color representation for visualization
-const int colors[11][3] = 
+const int colors[11][3] =
 {
-	{0,     0,   0}, // black
-	{0,     0, 255}, // blue
-	{165,  42,  42}, // brown
-	{190, 190, 190}, // grey
-	{  0, 255,   0}, // green
-	{255, 165,   0}, // orange
-	{255, 192, 203}, // pink
-	{160,  32, 240}, // purple
-	{255,   0,   0}, // red
-	{255, 255, 255}, // white
-	{255, 255,   0}, // yellow
+  {0,     0,   0}, // black
+  {0,     0, 255}, // blue
+  {165,  42,  42}, // brown
+  {190, 190, 190}, // grey
+  {  0, 255,   0}, // green
+  {255, 165,   0}, // orange
+  {255, 192, 203}, // pink
+  {160,  32, 240}, // purple
+  {255,   0,   0}, // red
+  {255, 255, 255}, // white
+  {255, 255,   0}, // yellow
 };
 
 
-LFColorWeijer::LFColorWeijer(const Config *c)
+LFColorWeijer::LFColorWeijer( const Config *c )
 {
-	conf = c;
-	
-	bin[0] = conf->gI("LFColorWeijer", "binL", 10);
-	bin[1] = conf->gI("LFColorWeijer", "bina", 20);
-	bin[2] = conf->gI("LFColorWeijer", "binb", 20);
-
-	maxv[0] =  100.0;
-	maxv[1] =   80.0;
-	maxv[2] =   50.0;
-
-	minv[0] =    0.0;
-	minv[1] = -105.0;
-	minv[2] = -200.0;
-
-	tfile = conf->gS("LFColorWeijer", "table", "/home/dbv/bilder/colorWeijer/color.txt");
-
-	for (int i = 0; i < 3; i++)
-	{
-		interval[i] = (maxv[i] - minv[i]) / (double)bin[i];
-	}
-
-	ifstream test(tfile.c_str());
-
-	if (test)
-	{
-		restore();
-	}
-	else
-	{
-		train();
-	}
+  conf = c;
+
+  bin[0] = conf->gI( "LFColorWeijer", "binL", 10 );
+  bin[1] = conf->gI( "LFColorWeijer", "bina", 20 );
+  bin[2] = conf->gI( "LFColorWeijer", "binb", 20 );
+
+  maxv[0] =  100.0;
+  maxv[1] =   80.0;
+  maxv[2] =   50.0;
+
+  minv[0] =    0.0;
+  minv[1] = -105.0;
+  minv[2] = -200.0;
+
+  tfile = conf->gS( "LFColorWeijer", "table", "/home/dbv/bilder/colorWeijer/color.txt" );
+
+  for ( int i = 0; i < 3; i++ )
+  {
+    interval[i] = ( maxv[i] - minv[i] ) / ( double )bin[i];
+  }
+
+  ifstream test( tfile.c_str() );
+
+  if ( test )
+  {
+    restore();
+  }
+  else
+  {
+    train();
+  }
 }
 
 LFColorWeijer::~LFColorWeijer()
 {
-	for(uint i = 0; i < hist.size(); i++)
-	{
-		for(uint j = 0; j < hist[i].size(); j++)
-		{
-			hist[i][j].clear();
-		}
-		hist[i].clear();
-	}
-	hist.clear();
+  for ( uint i = 0; i < hist.size(); i++ )
+  {
+    for ( uint j = 0; j < hist[i].size(); j++ )
+    {
+      hist[i][j].clear();
+    }
+    hist[i].clear();
+  }
+  hist.clear();
 }
 
 int LFColorWeijer::getDescSize() const
 {
-	return LASTCOLOR;
+  return LASTCOLOR;
 }
 
 void LFColorWeijer::store()
 {
-	ofstream fout(tfile.c_str(), ios_base::app);
-
-	fout << hist.size() << " " << hist[0].size() << " " << hist[0][0].size() << " " << hist[0][0][0].size() << endl;
-
-	for (uint i = 0; i < hist.size(); i++)
-	{
-		for (uint i0 = 0; i0 < hist[i].size(); i0++)
-		{
-			for (uint i1 = 0; i1 < hist[i][i0].size(); i1++)
-			{
-				for (uint i2 = 0; i2 < hist[i][i0][i1].size(); i2++)
-				{
-					fout << hist[i][i0][i1][i2] << " ";
-				}
-			}
-		}
-	}
+  ofstream fout( tfile.c_str(), ios_base::app );
+
+  fout << hist.size() << " " << hist[0].size() << " " << hist[0][0].size() << " " << hist[0][0][0].size() << endl;
+
+  for ( uint i = 0; i < hist.size(); i++ )
+  {
+    for ( uint i0 = 0; i0 < hist[i].size(); i0++ )
+    {
+      for ( uint i1 = 0; i1 < hist[i][i0].size(); i1++ )
+      {
+        for ( uint i2 = 0; i2 < hist[i][i0][i1].size(); i2++ )
+        {
+          fout << hist[i][i0][i1][i2] << " ";
+        }
+      }
+    }
+  }
 }
 
 void LFColorWeijer::smooth()
 {
-	int size0 = (int)hist.size();
-	int size1 = (int)hist[0].size();
-	int size2 = (int)hist[0][0].size();
-	int size3 = (int)hist[0][0][0].size();
-	for(int i0 = 0; i0 < size1; i0++)
-	{
-		for(int i1 = 0; i1 < size2; i1++)
-		{
-			for(int i2 = 0; i2 < size3; i2++)
-			{
-				double maxval = 0.0;
-				for(int i = 0; i < size0; i++)
-				{
-					maxval = std::max(maxval, hist[i][i0][i1][i2]);
-				}
-				if(maxval == 0.0)
-				{
-					for(int i = 0; i < size0; i++)
-					{
-						int anz = 0;
-						for(int a0 = std::max(i0-1,0); a0 <= std::min(i0+1,size1-1); a0++)
-						{
-							for(int a1 = std::max(i1-1,0); a1 <= std::min(i1+1,size2-1); a1++)
-							{
-								for(int a2 = std::max(i2-1,0); a2 <= std::min(i2+1,size3-1); a2++)
-								{
-									anz++;
-									hist[i][i0][i1][i2] += hist[i][a0][a1][a2];
-								}
-							}
-						}
-						hist[i][i0][i1][i2] /= anz;
-					}
-				}
-			}
-		}
-	}
+  int size0 = ( int )hist.size();
+  int size1 = ( int )hist[0].size();
+  int size2 = ( int )hist[0][0].size();
+  int size3 = ( int )hist[0][0][0].size();
+  for ( int i0 = 0; i0 < size1; i0++ )
+  {
+    for ( int i1 = 0; i1 < size2; i1++ )
+    {
+      for ( int i2 = 0; i2 < size3; i2++ )
+      {
+        double maxval = 0.0;
+        for ( int i = 0; i < size0; i++ )
+        {
+          maxval = std::max( maxval, hist[i][i0][i1][i2] );
+        }
+        if ( maxval == 0.0 )
+        {
+          for ( int i = 0; i < size0; i++ )
+          {
+            int anz = 0;
+            for ( int a0 = std::max( i0 - 1, 0 ); a0 <= std::min( i0 + 1, size1 - 1 ); a0++ )
+            {
+              for ( int a1 = std::max( i1 - 1, 0 ); a1 <= std::min( i1 + 1, size2 - 1 ); a1++ )
+              {
+                for ( int a2 = std::max( i2 - 1, 0 ); a2 <= std::min( i2 + 1, size3 - 1 ); a2++ )
+                {
+                  anz++;
+                  hist[i][i0][i1][i2] += hist[i][a0][a1][a2];
+                }
+              }
+            }
+            hist[i][i0][i1][i2] /= anz;
+          }
+        }
+      }
+    }
+  }
 }
 
 void LFColorWeijer::restore()
 {
-	int size0, size1, size2, size3;
-	ifstream fin(tfile.c_str());
-	fin >> size0;
-	fin >> size1;
-	fin >> size2;
-	fin >> size3;
-	hist.clear();
-
-	for (int i = 0; i < size0; i++)
-	{
-		vector<vector<vector<double> > > v2;
-
-		for (int i0 = 0; i0 < size1; i0++)
-		{
-			vector<vector<double> > v1;
-
-			for (int i1 = 0; i1 < size2; i1++)
-			{
-				vector<double> v0;
-
-				for (int i2 = 0; i2 < size3; i2++)
-				{
-					double val;
-					fin >> val;
-					v0.push_back(val);
-				}
-
-				v1.push_back(v0);
-			}
-
-			v2.push_back(v1);
-		}
-
-		hist.push_back(v2);
-	}
+  int size0, size1, size2, size3;
+  ifstream fin( tfile.c_str() );
+  fin >> size0;
+  fin >> size1;
+  fin >> size2;
+  fin >> size3;
+  hist.clear();
+
+  for ( int i = 0; i < size0; i++ )
+  {
+    vector<vector<vector<double> > > v2;
+
+    for ( int i0 = 0; i0 < size1; i0++ )
+    {
+      vector<vector<double> > v1;
+
+      for ( int i1 = 0; i1 < size2; i1++ )
+      {
+        vector<double> v0;
+
+        for ( int i2 = 0; i2 < size3; i2++ )
+        {
+          double val;
+          fin >> val;
+          v0.push_back( val );
+        }
+
+        v1.push_back( v0 );
+      }
+
+      v2.push_back( v1 );
+    }
+
+    hist.push_back( v2 );
+  }
 }
 
-int LFColorWeijer::getDescriptors ( const NICE::Image & img, VVector & positions, VVector & features ) const
+int LFColorWeijer::getDescriptors( const NICE::Image & img, VVector & positions, VVector & features ) const
 {
-	cerr << "this are COLOR Features, they won't work on gray value images" << endl;
-	exit(-1);
+  cerr << "this are COLOR Features, they won't work on gray value images" << endl;
+  exit( -1 );
 }
 
-int LFColorWeijer::getDescriptors(const NICE::ColorImage & img, VVector & positions, VVector & features) const
+int LFColorWeijer::getDescriptors( const NICE::ColorImage & img, VVector & positions, VVector & features ) const
 {
-	// in Lab umwandeln
-	for (int i = 0; i < (int)positions.size(); i++)
-	{
-			vector<double> vals;
-			vector<int> b;
-			int x = positions[i][0];
-			int y = positions[i][1];
-			
-			double R,G,B,X,Y,Z;
-			vector<double> lab(3,0.0);
-			
-			R=(double)img.getPixel(x,y,0)/255.0;
-			G=(double)img.getPixel(x,y,1)/255.0;
-			B=(double)img.getPixel(x,y,2)/255.0;
-			
-			ColorConversion::ccRGBtoXYZ(R,G,B,&X,&Y,&Z,0);
-			ColorConversion::ccXYZtoCIE_Lab(X,Y,Z,&lab[0],&lab[1],&lab[2],0);
-			
-			for (int i = 0; i < 3; i++)
-			{
-				int val = (int)((lab[i] - minv[i]) / interval[i]);
-				val = std::min(val, bin[i] - 1);
-				val = std::max(val, 0);
-				b.push_back(val);
-			}
-
-			Vector feat(hist.size());
-			
-			for (uint i = 0; i < hist.size(); i++)
-			{
-				feat[i] = hist[i][b[0]][b[1]][b[2]];
-			}
-			features.push_back(feat);
-	}
-	
-	return 1;
+  // in Lab umwandeln
+  for ( int i = 0; i < ( int )positions.size(); i++ )
+  {
+    vector<double> vals;
+    vector<int> b;
+    int x = positions[i][0];
+    int y = positions[i][1];
+
+    double R, G, B, X, Y, Z;
+    vector<double> lab( 3, 0.0 );
+
+    R = ( double )img.getPixel( x, y, 0 ) / 255.0;
+    G = ( double )img.getPixel( x, y, 1 ) / 255.0;
+    B = ( double )img.getPixel( x, y, 2 ) / 255.0;
+
+    ColorConversion::ccRGBtoXYZ( R, G, B, &X, &Y, &Z, 0 );
+    ColorConversion::ccXYZtoCIE_Lab( X, Y, Z, &lab[0], &lab[1], &lab[2], 0 );
+
+    for ( int i = 0; i < 3; i++ )
+    {
+      int val = ( int )(( lab[i] - minv[i] ) / interval[i] );
+      val = std::min( val, bin[i] - 1 );
+      val = std::max( val, 0 );
+      b.push_back( val );
+    }
+
+    Vector feat( hist.size() );
+
+    for ( uint i = 0; i < hist.size(); i++ )
+    {
+      feat[i] = hist[i][b[0]][b[1]][b[2]];
+    }
+    features.push_back( feat );
+  }
+
+  return 1;
 }
 
-void LFColorWeijer::visualizeFeatures ( NICE::Image & mark, const VVector & positions,	size_t color ) const
+void LFColorWeijer::visualizeFeatures( NICE::Image & mark, const VVector & positions, size_t color ) const
 {
-	
+
 }
 
-void LFColorWeijer::add(vector<vector<vector<double> > > &dest, vector<vector<vector<double> > > &src)
+void LFColorWeijer::add( vector<vector<vector<double> > > &dest, vector<vector<vector<double> > > &src )
 {
-	for(uint i0 = 0; i0 < src.size(); i0++)
-	{
-		for(uint i1 = 0; i1 < src[i0].size(); i1++)
-		{
-			for(uint i2 = 0; i2 < src[i0][i1].size(); i2++)
-			{
-				dest[i0][i1][i2] += src[i0][i1][i2];
-			}
-		}
-	}
+  for ( uint i0 = 0; i0 < src.size(); i0++ )
+  {
+    for ( uint i1 = 0; i1 < src[i0].size(); i1++ )
+    {
+      for ( uint i2 = 0; i2 < src[i0][i1].size(); i2++ )
+      {
+        dest[i0][i1][i2] += src[i0][i1][i2];
+      }
+    }
+  }
 }
 
-int LFColorWeijer::findColor(string &fn)
+int LFColorWeijer::findColor( string &fn )
 {
-	if(fn.find("black") != string::npos)
-		return BLACK;
-	if(fn.find("blue") != string::npos)
-		return BLUE;
-	if(fn.find("brown") != string::npos)
-		return BROWN;
-	if(fn.find("grey") != string::npos)
-		return GREY;
-	if(fn.find("green") != string::npos)
-		return GREEN;
-	if(fn.find("orange") != string::npos)
-		return ORANGE;
-	if(fn.find("pink") != string::npos)
-		return PINK;
-	if(fn.find("purple") != string::npos)
-		return PURPLE;
-	if(fn.find("red") != string::npos)
-		return RED;
-	if(fn.find("white") != string::npos)
-		return WHITE;
-	if(fn.find("yellow") != string::npos)
-		return YELLOW;
-	
-	return -1;
+  if ( fn.find( "black" ) != string::npos )
+    return BLACK;
+  if ( fn.find( "blue" ) != string::npos )
+    return BLUE;
+  if ( fn.find( "brown" ) != string::npos )
+    return BROWN;
+  if ( fn.find( "grey" ) != string::npos )
+    return GREY;
+  if ( fn.find( "green" ) != string::npos )
+    return GREEN;
+  if ( fn.find( "orange" ) != string::npos )
+    return ORANGE;
+  if ( fn.find( "pink" ) != string::npos )
+    return PINK;
+  if ( fn.find( "purple" ) != string::npos )
+    return PURPLE;
+  if ( fn.find( "red" ) != string::npos )
+    return RED;
+  if ( fn.find( "white" ) != string::npos )
+    return WHITE;
+  if ( fn.find( "yellow" ) != string::npos )
+    return YELLOW;
+
+  return -1;
 }
 
 vector<vector<vector<double > > > LFColorWeijer::createTable()
 {
-	vector<vector<vector<double> > > h;
-	for(int i0 = 0; i0 < bin[0]; i0++)
-	{
-		vector<vector< double > > vec;
-		for(int i1 = 0; i1 < bin[1]; i1++)
-		{
-			vector<double> v;
-			for(int i2 = 0; i2 < bin[2]; i2++)
-			{
-				v.push_back(0.0);
-			}
-			vec.push_back(v);
-		}
-		h.push_back(vec);
-	}
-	return h;
+  vector<vector<vector<double> > > h;
+  for ( int i0 = 0; i0 < bin[0]; i0++ )
+  {
+    vector<vector< double > > vec;
+    for ( int i1 = 0; i1 < bin[1]; i1++ )
+    {
+      vector<double> v;
+      for ( int i2 = 0; i2 < bin[2]; i2++ )
+      {
+        v.push_back( 0.0 );
+      }
+      vec.push_back( v );
+    }
+    h.push_back( vec );
+  }
+  return h;
 }
 
-void LFColorWeijer::normalize(vector<vector<vector<double> > > &tab)
+void LFColorWeijer::normalize( vector<vector<vector<double> > > &tab )
 {
-	double sum = 0.0;
-	
-	for(uint i0 = 0; i0 < tab.size(); i0++)
-	{
-		for(uint i1 = 0; i1 < tab[i0].size(); i1++)
-		{
-			for(uint i2 = 0; i2 < tab[i0][i1].size(); i2++)
-			{
-				sum += tab[i0][i1][i2];
-			}
-		}
-	}
-	
-	for(uint i0 = 0; i0 < tab.size(); i0++)
-	{
-		for(uint i1 = 0; i1 < tab[i0].size(); i1++)
-		{
-			for(uint i2 = 0; i2 < tab[i0][i1].size(); i2++)
-			{
-				tab[i0][i1][i2] /= sum;
-			}
-		}
-	}
-	
-	return;
+  double sum = 0.0;
+
+  for ( uint i0 = 0; i0 < tab.size(); i0++ )
+  {
+    for ( uint i1 = 0; i1 < tab[i0].size(); i1++ )
+    {
+      for ( uint i2 = 0; i2 < tab[i0][i1].size(); i2++ )
+      {
+        sum += tab[i0][i1][i2];
+      }
+    }
+  }
+
+  for ( uint i0 = 0; i0 < tab.size(); i0++ )
+  {
+    for ( uint i1 = 0; i1 < tab[i0].size(); i1++ )
+    {
+      for ( uint i2 = 0; i2 < tab[i0][i1].size(); i2++ )
+      {
+        tab[i0][i1][i2] /= sum;
+      }
+    }
+  }
+
+  return;
 }
 
-void LFColorWeijer::createHist(const ColorImage &cimg, vector<vector<vector<double> > > &hist, Image &mask)
+void LFColorWeijer::createHist( const ColorImage &cimg, vector<vector<vector<double> > > &hist, Image &mask )
 {
-	// in Lab umwandeln
-	NICE::MultiChannelImageT<double> genimg, imglab;
-
-	ColorSpace::ColorImagetoMultiChannelImage(cimg, genimg);
-	ColorSpace::convert(imglab, genimg, ColorSpace::COLORSPACE_LAB, ColorSpace::COLORSPACE_RGB);
-	
-	for(int y = 0; y < cimg.height(); y++)
-	{
-		for(int x = 0; x < cimg.width(); x++)
-		{
-			if(mask.getPixel(x,y) == 0)
-				continue;
-			vector<int> b;
-			for(int i = 0; i < 3; i++)
-			{
-				int val =(int)((imglab.get(x,y,i)-minv[i])/interval[i]);
-				val = std::min(val, bin[i]-1);
-				b.push_back(val);
-			}
-			hist[b[0]][b[1]][b[2]]++;
-		}
-	}
+  // in Lab umwandeln
+  NICE::MultiChannelImageT<double> genimg, imglab;
+
+  ColorSpace::ColorImagetoMultiChannelImage( cimg, genimg );
+  ColorSpace::convert( imglab, genimg, ColorSpace::COLORSPACE_LAB, ColorSpace::COLORSPACE_RGB );
+
+  for ( int y = 0; y < cimg.height(); y++ )
+  {
+    for ( int x = 0; x < cimg.width(); x++ )
+    {
+      if ( mask.getPixel( x, y ) == 0 )
+        continue;
+      vector<int> b;
+      for ( int i = 0; i < 3; i++ )
+      {
+        int val = ( int )(( imglab.get( x, y, i ) - minv[i] ) / interval[i] );
+        val = std::min( val, bin[i] - 1 );
+        b.push_back( val );
+      }
+      hist[b[0]][b[1]][b[2]]++;
+    }
+  }
 }
 
 void LFColorWeijer::train()
 {
-	cout << "train Starts" << endl;
-	for(int i = 0; i < LASTCOLOR; i++)
-	{
-		vector<vector<vector<double> > > h = createTable();
-		hist.push_back(h);
-	}
-	
-	string dir = conf->gS("LFColorWeijer", "table", "/home/dbv/bilder/colorWeijer/ebay/");
-	string images = conf->gS("LFColorWeijer", "table", "test_images.txt");
-	string mask = conf->gS("LFColorWeijer", "table", "mask_images.txt");
-		
-	string imagesfn;
-	string maskfn;
-	
-	ifstream finimg( (dir+images).c_str());
-	ifstream finmask( (dir+mask).c_str());
-	cout << dir+images << endl;
-	cout << dir+mask << endl;
-	// lese bilder und masken ein
-	while( finimg >> imagesfn && finmask >> maskfn)
-	{
-		Image mimg(dir+maskfn);
-		cout << dir+maskfn << endl;
-		ColorImage cimg(dir+imagesfn);
-			
-		int col = findColor(imagesfn);
-		vector<vector<vector<double> > > tab = createTable();
-			
-		createHist(cimg, tab, mimg); // erzeuge Lab Histogramm des Bildes
-			
-		normalize(tab);
-			
-		add(hist[col], tab);
-	}
-	finimg.close();
-	finmask.close();
-		
-		// normalisiere alle lookuptables
-	for(uint i = 0; i < hist.size(); i++)
-	{
-		normalize(hist[i]);
-	}
-		
-	smooth();
-	store();
+  cout << "train Starts" << endl;
+  for ( int i = 0; i < LASTCOLOR; i++ )
+  {
+    vector<vector<vector<double> > > h = createTable();
+    hist.push_back( h );
+  }
+
+  string dir = conf->gS( "LFColorWeijer", "table", "/home/dbv/bilder/colorWeijer/ebay/" );
+  string images = conf->gS( "LFColorWeijer", "table", "test_images.txt" );
+  string mask = conf->gS( "LFColorWeijer", "table", "mask_images.txt" );
+
+  string imagesfn;
+  string maskfn;
+
+  ifstream finimg(( dir + images ).c_str() );
+  ifstream finmask(( dir + mask ).c_str() );
+  cout << dir + images << endl;
+  cout << dir + mask << endl;
+  // lese bilder und masken ein
+  while ( finimg >> imagesfn && finmask >> maskfn )
+  {
+    Image mimg( dir + maskfn );
+    cout << dir + maskfn << endl;
+    ColorImage cimg( dir + imagesfn );
+
+    int col = findColor( imagesfn );
+    vector<vector<vector<double> > > tab = createTable();
+
+    createHist( cimg, tab, mimg ); // erzeuge Lab Histogramm des Bildes
+
+    normalize( tab );
+
+    add( hist[col], tab );
+  }
+  finimg.close();
+  finmask.close();
+
+  // normalisiere alle lookuptables
+  for ( uint i = 0; i < hist.size(); i++ )
+  {
+    normalize( hist[i] );
+  }
+
+  smooth();
+  store();
 }
 
-void LFColorWeijer::visualizeFeatures ( NICE::ColorImage & out, const VVector & features, const VVector & position ) const
+void LFColorWeijer::visualizeFeatures( NICE::ColorImage & out, const VVector & features, const VVector & position ) const
 {
-	for(int i = 0; i < (int)position.size(); i++)
-	{
-		int maxpos = 0;
-		double maxval = 0.0;
-		for(int j = 0; j < (int)features[i].size(); j++)
-		{
-			if(maxval < features[i][j])
-			{
-				maxval = features[i][j];
-				maxpos = j;
-			}
-		}
-		
-		out.setPixel(position[i][0],position[i][1],colors[maxpos][0],colors[maxpos][1],colors[maxpos][2]);
-	}
+  for ( int i = 0; i < ( int )position.size(); i++ )
+  {
+    int maxpos = 0;
+    double maxval = 0.0;
+    for ( int j = 0; j < ( int )features[i].size(); j++ )
+    {
+      if ( maxval < features[i][j] )
+      {
+        maxval = features[i][j];
+        maxpos = j;
+      }
+    }
+
+    out.setPixel( position[i][0], position[i][1], colors[maxpos][0], colors[maxpos][1], colors[maxpos][2] );
+  }
 }
 
-void LFColorWeijer::visualizeFeatures ( const NICE::ColorImage & cimg) const
+void LFColorWeijer::visualizeFeatures( const NICE::ColorImage & cimg ) const
 {
-	ColorImage out;
-	visualizeFeatures(cimg, out);
+  ColorImage out;
+  visualizeFeatures( cimg, out );
 }
 
-void LFColorWeijer::visualizeFeatures ( const NICE::ColorImage & cimg, NICE::ColorImage &out) const
+void LFColorWeijer::visualizeFeatures( const NICE::ColorImage & cimg, NICE::ColorImage &out ) const
 {
-	VVector pos, feats;
-	for(int y = 0; y < cimg.height(); y++)
-	{
-		for(int x = 0; x < cimg.width(); x++)
-		{
-			Vector vec(2);
-			vec[0] = x;
-			vec[1] = y;
-			pos.push_back(vec);
-		}
-	}
-	
-	getDescriptors(cimg, pos, feats);
-	
-	out.resize(cimg.width(), cimg.height());
-	out.set(0,0,0);
-	visualizeFeatures ( out, feats, pos);
-	ColorImage combinedout(cimg.width()*2, cimg.height());
-	
-	int width = (int)cimg.width();
-	
-	for(int y = 0; y < (int)cimg.height(); y++)
-	{
-		for(int x = 0; x < width; x++)
-		{
-			combinedout.setPixel(x,y,cimg.getPixel(x,y,0), cimg.getPixel(x,y,1),cimg.getPixel(x,y,2));
-			combinedout.setPixel(x+width,y,out.getPixel(x,y,0), out.getPixel(x,y,1),out.getPixel(x,y,2));
-		}
-	}
-	
-	showImage(combinedout, "Ergebnis");
+  VVector pos, feats;
+  for ( int y = 0; y < cimg.height(); y++ )
+  {
+    for ( int x = 0; x < cimg.width(); x++ )
+    {
+      Vector vec( 2 );
+      vec[0] = x;
+      vec[1] = y;
+      pos.push_back( vec );
+    }
+  }
+
+  getDescriptors( cimg, pos, feats );
+
+  out.resize( cimg.width(), cimg.height() );
+  out.set( 0, 0, 0 );
+  visualizeFeatures( out, feats, pos );
+  ColorImage combinedout( cimg.width()*2, cimg.height() );
+
+  int width = ( int )cimg.width();
+
+  for ( int y = 0; y < ( int )cimg.height(); y++ )
+  {
+    for ( int x = 0; x < width; x++ )
+    {
+      combinedout.setPixel( x, y, cimg.getPixel( x, y, 0 ), cimg.getPixel( x, y, 1 ), cimg.getPixel( x, y, 2 ) );
+      combinedout.setPixel( x + width, y, out.getPixel( x, y, 0 ), out.getPixel( x, y, 1 ), out.getPixel( x, y, 2 ) );
+    }
+  }
+
+  showImage( combinedout, "result" );
 }
 
-void LFColorWeijer::getFeats(const ColorImage &img, vector<vector<vector<double> > > &feats)
+void LFColorWeijer::getFeats( const ColorImage &img, MultiChannelImageT<double> &feats )
 {
-	int width = (int)img.width();
-	int height = (int)img.height();
-	
-	feats = vector<vector<vector<double> > >(width,vector<vector<double> >(height,vector<double>(hist.size(),0.0)));
-	
-	NICE::MultiChannelImageT<double> genimg, imglab;
-	
-	ColorSpace::ColorImagetoMultiChannelImage (img, genimg);
-	ColorSpace::convert(imglab, genimg, ColorSpace::COLORSPACE_LAB, ColorSpace::COLORSPACE_RGB);
-	
-	for(int y = 0; y < height; y++)
-	{
-		for(int x = 0; x < width; x++)
-		{
-			for (uint i = 0; i < hist.size(); i++)
-			{
-				vector<double> b(3,0.0);
-				for (int j = 0; j < 3; j++)
-				{
-					int val = (int)((imglab.get(x,y,j) - minv[j]) / interval[j]);
-					val = std::min(val, bin[j] - 1);
-					val = std::max(val, 0);
-					b[j] = val;
-				}
-				feats[x][y][i] = hist[i][b[0]][b[1]][b[2]];
-			}
-		}
-	}
-	
-	return;
+  int width = ( int )img.width();
+  int height = ( int )img.height();
+  feats.reInit( width, height, hist.size(), true );
+
+  NICE::MultiChannelImageT<double> genimg, imglab;
+
+  ColorSpace::ColorImagetoMultiChannelImage( img, genimg );
+  ColorSpace::convert( imglab, genimg, ColorSpace::COLORSPACE_LAB, ColorSpace::COLORSPACE_RGB );
+
+  for ( int y = 0; y < height; y++ )
+  {
+    for ( int x = 0; x < width; x++ )
+    {
+      for ( uint i = 0; i < hist.size(); i++ )
+      {
+        vector<double> b( 3, 0.0 );
+        for ( int j = 0; j < 3; j++ )
+        {
+          int val = ( int )(( imglab.get( x, y, j ) - minv[j] ) / interval[j] );
+          val = std::min( val, bin[j] - 1 );
+          val = std::max( val, 0 );
+          b[j] = val;
+        }
+        feats.set( x, y, hist[i][b[0]][b[1]][b[2]], i );
+      }
+    }
+  }
+
+  return;
 }
-
-

+ 2 - 1
features/localfeatures/LFColorWeijer.h

@@ -11,6 +11,7 @@
 #include "core/vector/MatrixT.h"
 #include "core/image/ImageT.h"
 #include "core/imagedisplay/ImageDisplay.h"
+#include "core/image/MultiChannelImageT.h"
 
 #include "LocalFeature.h"
 #include "core/basics/Config.h"
@@ -183,7 +184,7 @@ class LFColorWeijer : public LocalFeature
 		 * @param img input image
 		 * @param feats feature vector for each pixel
 		 */
-		void getFeats(const NICE::ColorImage &img, std::vector<std::vector<std::vector<double> > > &feats);
+		void getFeats(const NICE::ColorImage &img, NICE::MultiChannelImageT<double> &feats);
 };
 
 

+ 3 - 1
features/localfeatures/LFColorWeijer.h~

@@ -10,6 +10,8 @@
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
 #include "core/image/ImageT.h"
+#include "core/imagedisplay/ImageDisplay.h"
+#include "core/image/MultiChannelImageTb.h"
 
 #include "LocalFeature.h"
 #include "core/basics/Config.h"
@@ -182,7 +184,7 @@ class LFColorWeijer : public LocalFeature
 		 * @param img input image
 		 * @param feats feature vector for each pixel
 		 */
-		void getFeats(const NICE::ColorImage &img, std::vector<std::vector<std::vector<double> > > &feats);
+		void getFeats(const NICE::ColorImage &img, MultiChannelImageT<double> &feats);
 };
 
 

+ 3 - 0
features/localfeatures/LFSiftPP.cpp

@@ -13,6 +13,8 @@
 // #endif
 #include "vislearning/features/localfeatures/LFSiftPP.h"
 
+#include "core/basics/Exception.h"
+
 
 using namespace std;
 
@@ -196,6 +198,7 @@ void LFSiftPP::visualizeFeatures ( NICE::Image & mark,
 				 const VVector & positions,
 				 size_t color ) const
 {
+	fthrow(Exception, "LFSiftPP::visualizeFeatures -- not yet implemented due to old ICE version.");
 // #ifdef NICE_USELIB_ICE
 //     ice::Image mark_ice = ice::NewImg ( mark.width(), 
 // 	mark.height(), 255 );

+ 4 - 1
features/localfeatures/LocalFeatureSift.cpp

@@ -9,6 +9,8 @@
 // #endif
 #include <iostream>
 
+#include "core/basics/Exception.h"
+
 #include "vislearning/features/localfeatures/sift.h"
 #include "vislearning/features/localfeatures/LocalFeatureSift.h"
 
@@ -171,6 +173,8 @@ void LocalFeatureSift::visualizeFeatures ( NICE::Image & mark,
 				 const VVector & positions,
 				 size_t color ) const
 {
+	fthrow(Exception, "LocalFeatureSift::visualizeFeatures -- not yet implemented due to old ICE version.");
+//TODO check this!
 // #ifdef NICE_USELIB_ICE
 //     ice::Image mark_ice = ice::NewImg ( mark.width(), 
 // 	mark.height(), 255 );
@@ -212,6 +216,5 @@ void LocalFeatureSift::visualizeFeatures ( NICE::Image & mark,
 // #else
 // 	cerr << "uses ice visualization, please install ice or change to NICE visualization" << endl;
 // #endif
-//TODO check this!
 }
 

+ 1 - 1
math/kernels/CachedQuadraticDistances.cpp

@@ -15,7 +15,7 @@ using namespace OBJREC;
 
 void CachedQuadraticDistances::calcKernelData ( const VVector & vecSet, KernelData *kernelData ) const
 {
-	cerr << "CachedQuadraticDistances::calcKernelData()" << endl;
+	//cerr << "CachedQuadraticDistances::calcKernelData()" << endl;
 	Matrix *quadraticDistances = new Matrix ( vecSet.size(), vecSet.size() );;
 	// FIXME: memory leak -> only if vecSet.size() is to big (ca. >>5000)
 	int ii = 0;

+ 1 - 1
math/kernels/Kernel.cpp

@@ -84,7 +84,7 @@ void Kernel::calcKernelVector ( const VVector & vecSet, const NICE::Vector & y,
 	
 void Kernel::calcKernelData ( const VVector & vecSet, KernelData *kernelData ) const
 {
-	cerr << "Kernel::calcKernelData()" << endl;
+	//cerr << "Kernel::calcKernelData()" << endl;
 
 	NICE::Matrix & kernelMatrix = kernelData->getKernelMatrix();
 	calcGramMatrix ( vecSet, kernelMatrix );

+ 0 - 3
openProblems

@@ -1,3 +0,0 @@
-ICETools
-LocalFeatureSift
-LFSiftPP