Эх сурвалжийг харах

Merge branch 'master', remote branch 'dbv/master'

Alexander Luetz 13 жил өмнө
parent
commit
debabdd8a2
100 өөрчлөгдсөн 4719 нэмэгдсэн , 4305 устгасан
  1. 1 1
      baselib/ColorSpace.cpp
  2. 96 98
      baselib/ColorSpace.tcc
  3. 9 0
      baselib/FastFilter.h
  4. 47 0
      baselib/FastFilter.tcc
  5. 202 174
      baselib/ICETools.cpp
  6. 75 75
      baselib/ICETools.h
  7. 72 76
      baselib/ProgressBarQt.cpp
  8. 4 4
      baselib/ProgressBarQt.h
  9. 2 1
      cbaselib/BoundingBox.cpp
  10. 29 34
      cbaselib/BoundingBox.h
  11. 29 52
      cbaselib/CachedExample.cpp
  12. 273 248
      cbaselib/CachedExample.h
  13. 1 1
      cbaselib/ClassNames.cpp
  14. 5 1
      cbaselib/ClassNames.h
  15. 24 24
      cbaselib/ClassificationResult.cpp
  16. 59 62
      cbaselib/ClassificationResult.h
  17. 20 19
      cbaselib/Feature.h
  18. 12 11
      cbaselib/ImageInfo.cpp
  19. 73 62
      cbaselib/ImageInfo.h
  20. 218 218
      cbaselib/LabeledFileList.cpp
  21. 35 35
      cbaselib/LabeledFileList.h
  22. 175 166
      cbaselib/LabeledSetSelection.h
  23. 65 24
      cbaselib/LocalizationResult.cpp
  24. 4 0
      cbaselib/LocalizationResult.h
  25. 28 25
      cbaselib/MultiDataset.h
  26. 20 20
      cbaselib/Polygon.h
  27. 28 27
      cbaselib/progs/statisticsLabeledSetVector.cpp
  28. 49 47
      cbaselib/progs/testCachedExample.cpp
  29. 51 57
      cbaselib/progs/testLabeledSet.cpp
  30. 58 52
      classifier/classifierbase/KernelClassifier.h
  31. 31 24
      classifier/classifierbase/VecClassifier.h
  32. 2 0
      classifier/classifiercombination/VCPreRandomForest.cpp
  33. 0 2
      classifier/classifiercombination/VCPreRandomForest.h
  34. 2 0
      classifier/classifierinterfaces/VCFeaturePool.cpp
  35. 0 2
      classifier/classifierinterfaces/VCFeaturePool.h
  36. 94 91
      classifier/fpclassifier/boosting/FPCBoosting.h
  37. 3 0
      classifier/fpclassifier/logisticregression/FPCSMLR.cpp
  38. 68 69
      classifier/fpclassifier/logisticregression/FPCSMLR.h
  39. 3 0
      classifier/fpclassifier/logisticregression/SLR.cpp
  40. 1 3
      classifier/fpclassifier/logisticregression/SLR.h
  41. 3 0
      classifier/fpclassifier/randomforest/DecisionNode.cpp
  42. 1 2
      classifier/fpclassifier/randomforest/DecisionNode.h
  43. 42 26
      classifier/fpclassifier/randomforest/FPCDecisionTree.h
  44. 3 0
      classifier/fpclassifier/randomforest/FPCRandomForests.cpp
  45. 118 110
      classifier/fpclassifier/randomforest/FPCRandomForests.h
  46. 18 16
      classifier/genericClassifierSelection.h
  47. 71 67
      classifier/kernelclassifier/GPLaplaceOptimizationProblem.h
  48. 57 46
      classifier/kernelclassifier/KCGPLaplace.h
  49. 43 33
      classifier/kernelclassifier/KCGPLaplaceOneVsAll.h
  50. 47 37
      classifier/kernelclassifier/KCGPOneClass.h
  51. 66 65
      classifier/kernelclassifier/KCGPRegOneVsAll.h
  52. 44 34
      classifier/kernelclassifier/KCGPRegression.h
  53. 46 36
      classifier/kernelclassifier/KCMinimumEnclosingBall.h
  54. 39 29
      classifier/kernelclassifier/KCOneVsAll.h
  55. 27 26
      classifier/kernelclassifier/LHCumulativeGauss.h
  56. 66 47
      classifier/kernelclassifier/LaplaceApproximation.h
  57. 39 44
      classifier/vclassifier/VCAmitSVM.h
  58. 28 27
      classifier/vclassifier/VCCrossGeneralization.h
  59. 2 0
      classifier/vclassifier/VCDTSVM.cpp
  60. 0 2
      classifier/vclassifier/VCDTSVM.h
  61. 110 0
      classifier/vclassifier/VCNearestClassMean.cpp
  62. 55 0
      classifier/vclassifier/VCNearestClassMean.h
  63. 3 0
      classifier/vclassifier/VCOneVsAll.cpp
  64. 0 2
      classifier/vclassifier/VCOneVsAll.h
  65. 35 31
      classifier/vclassifier/VCOneVsOne.h
  66. 98 102
      features/fpfeatures/ColorHistogramFeature.cpp
  67. 34 37
      features/fpfeatures/ColorHistogramFeature.h
  68. 162 174
      features/fpfeatures/EOHFeature.cpp
  69. 49 46
      features/fpfeatures/EOHFeature.h
  70. 57 51
      features/fpfeatures/FIGradients.cpp
  71. 8 8
      features/fpfeatures/FIGradients.h
  72. 80 80
      features/fpfeatures/FIHistograms.cpp
  73. 191 187
      features/fpfeatures/HOGFeature.cpp
  74. 8 4
      features/fpfeatures/HaarFeature.cpp
  75. 163 168
      features/fpfeatures/HistFeature.cpp
  76. 53 58
      features/fpfeatures/HistFeature.h
  77. 180 173
      features/fpfeatures/PixelPairFeature.cpp
  78. 53 53
      features/fpfeatures/PixelPairFeature.h
  79. 121 117
      features/fpfeatures/SemanticFeature.cpp
  80. 47 47
      features/fpfeatures/SemanticFeature.h
  81. 1 1
      features/localfeatures/GenericLFSelection.h
  82. 1 1
      features/localfeatures/GenericLocalFeatureSelection.h
  83. 1 1
      features/localfeatures/LFColorWeijer.cpp
  84. 80 70
      features/localfeatures/LFReadCache.tcc
  85. 2 1
      features/localfeatures/LFSiftPP.h
  86. 49 47
      features/localfeatures/LFonHSG.h
  87. 2 1
      features/localfeatures/LocalFeatureRepresentation.h
  88. 2 5
      image/GenericImageTools.h
  89. 66 48
      image/GenericImageTools.tcc
  90. 2 2
      math/cluster/GMM.h
  91. 32 33
      math/cluster/KMeansOnline.h
  92. 48 48
      math/distances/genericDistance.h
  93. 10 5
      math/ftransform/PCA.cpp
  94. 0 88
      math/ftransform/progs/Makefile.inc
  95. 59 75
      math/ftransform/tests/TestFTransform.cpp
  96. 15 14
      math/ftransform/tests/TestFTransform.h
  97. 30 0
      math/ftransform/tests/pca.data
  98. 26 21
      math/kernels/genericKernel.h
  99. 54 54
      math/pdf/tests/TestPDF.cpp
  100. 4 0
      progs/libdepend.inc

+ 1 - 1
baselib/ColorSpace.cpp

@@ -22,7 +22,7 @@ using namespace NICE;
 //bad position for this function
 void ColorSpace::ColorImagetoMultiChannelImage(  const NICE::ColorImage &imgrgb, NICE::MultiChannelImageT<double> &genimg )
 {
-  genimg.reInit( imgrgb.width(), imgrgb.height(), 3, true );
+  genimg.reInit( imgrgb.width(), imgrgb.height(), 3);
   for ( int y = 0;y < imgrgb.height();y++ )
   {
     for ( int x = 0;x < imgrgb.width();x++ )

+ 96 - 98
baselib/ColorSpace.tcc

@@ -4,111 +4,109 @@
 
 namespace OBJREC {
 
-template<class SrcPixelType,class DstPixelType>
+template<class SrcPixelType, class DstPixelType>
 void ColorSpace::convert ( NICE::MultiChannelImageT<DstPixelType> & dst, const NICE::MultiChannelImageT<SrcPixelType> & src,
-	      int dstColorSpace, int srcColorSpace, double dstM, double srcM )
+                           int dstColorSpace, int srcColorSpace, double dstM, double srcM )
 {
-    assert ( (srcColorSpace >= 0) && (srcColorSpace < NUM_COLORSPACES) );
-    assert ( (dstColorSpace >= 0) && (dstColorSpace < NUM_COLORSPACES) );
+  assert ( ( srcColorSpace >= 0 ) && ( srcColorSpace < NUM_COLORSPACES ) );
+  assert ( ( dstColorSpace >= 0 ) && ( dstColorSpace < NUM_COLORSPACES ) );
 
-    dst.reInitFrom ( src, true );
+  dst.reInitFrom ( src );
 
-    if ( (srcColorSpace == COLORSPACE_RGB) && (dstColorSpace == COLORSPACE_HSL) )
-    {
-	 assert ( dst.numChannels == 3 );
-	 assert ( src.numChannels == 3 );
+  if ( ( srcColorSpace == COLORSPACE_RGB ) && ( dstColorSpace == COLORSPACE_HSL ) )
+  {
+    assert ( dst.channels() == 3 );
+    assert ( src.channels() == 3 );
 
-	 long k = 0;
-	 for ( int y = 0 ; y < src.ysize ; y++ )
-	     for ( int x = 0 ; x < src.xsize ; x++,k++ )
-	     {
-	       double R,G,B,H,S,L;
-	       R=(double)src.data[0][k]/srcM;
-	       G=(double)src.data[1][k]/srcM;
-	       B=(double)src.data[2][k]/srcM;
-	       ColorConversion::ccRGBtoHSL(R,G,B,&H,&S,&L);
-	       dst.data[0][k] = (DstPixelType)(H*dstM);
-	       dst.data[1][k] = (DstPixelType)(S*dstM);
-	       dst.data[2][k] = (DstPixelType)(L*dstM);
-	    }
-    } 
-    else if ( (srcColorSpace == COLORSPACE_RGB) && (dstColorSpace == COLORSPACE_LAB) )
-     {
-          long k = 0;
-          for ( int y = 0 ; y < src.ysize ; y++ )
-               for ( int x = 0 ; x < src.xsize ; x++,k++ )
-          {
-               double R,G,B,X,Y,Z,L,a,b;
-               R=(double)src.data[0][k]/255.0;
-			   G=(double)src.data[1][k]/255.0;
-			   B=(double)src.data[2][k]/255.0;
-               ColorConversion::ccRGBtoXYZ(R,G,B,&X,&Y,&Z,0);
-               ColorConversion::ccXYZtoCIE_Lab(X,Y,Z,&L,&a,&b,0);
-               dst.data[0][k] = (DstPixelType)(L);
-               dst.data[1][k] = (DstPixelType)(a);
-               dst.data[2][k] = (DstPixelType)(b);
-          }
-     }
-	 else if ( (srcColorSpace == COLORSPACE_LAB) && (dstColorSpace == COLORSPACE_RGB) )
-	 {
-		 long k = 0;
-		 for ( int y = 0 ; y < src.ysize ; y++ )
-			 for ( int x = 0 ; x < src.xsize ; x++,k++ )
-		 {
-			 double R,G,B,X,Y,Z,L,a,b;
-			 L=(double)src.data[0][k];
-			 a=(double)src.data[1][k];
-			 b=(double)src.data[2][k];
-			 ColorConversion::ccCIE_LabtoXYZ(L,a,b,&X,&Y,&Z,0);
-			 ColorConversion::ccXYZtoRGB(X,Y,Z,&R,&G,&B,0);
-			 dst.data[0][k] = (DstPixelType)(R);
-			 dst.data[1][k] = (DstPixelType)(G);
-			 dst.data[2][k] = (DstPixelType)(B);
-		 }		 
-	 }
-     else if ( (srcColorSpace == COLORSPACE_RGB) && (dstColorSpace == COLORSPACE_LMS) )
-     {
-          long k = 0;
-          for ( int y = 0 ; y < src.ysize ; y++ )
-               for ( int x = 0 ; x < src.xsize ; x++,k++ )
-          {
-               double R,G,B,X,Y,Z,L,M,S;
-               R=(double)src.data[0][k]/srcM;
-               G=(double)src.data[1][k]/srcM;
-               B=(double)src.data[2][k]/srcM;
-               ColorConversion::ccRGBtoXYZ(R,G,B,&X,&Y,&Z,0);
-               ColorConversion::ccXYZtoLMS(X,Y,Z,&L,&M,&S);
-               dst.data[0][k] = (DstPixelType)(L);
-               dst.data[1][k] = (DstPixelType)(M);
-               dst.data[2][k] = (DstPixelType)(S);
-          }
-     }
-     else if ( (srcColorSpace == COLORSPACE_RGB) && (dstColorSpace == COLORSPACE_OPP) )
-{
-          long k = 0;
-          for ( int y = 0 ; y < src.ysize ; y++ )
-               for ( int x = 0 ; x < src.xsize ; x++,k++ )
-{
-               double R,G,B,X,Y,Z,L,M,S,Lum,LM,SLM;
-               R=(double)src.data[0][k]/srcM;
-               G=(double)src.data[1][k]/srcM;
-               B=(double)src.data[2][k]/srcM;
-               ColorConversion::ccRGBtoXYZ(R,G,B,&X,&Y,&Z,0);
-               ColorConversion::ccXYZtoLMS(X,Y,Z,&L,&M,&S);
-               ColorConversion::ccLMStoOPP(L,M,S,&Lum,&LM,&SLM);
-               
-               dst.data[0][k] = (DstPixelType)(Lum);
-               dst.data[1][k] = (DstPixelType)(LM);
-               dst.data[2][k] = (DstPixelType)(SLM);
+    for ( int y = 0 ; y < src.height() ; y++ )
+      for ( int x = 0 ; x < src.width() ; x++)
+      {
+        double R, G, B, H, S, L;
+        R = ( double ) src.get(x,y,0) / srcM;
+        G = ( double ) src.get(x,y,1) / srcM;
+        B = ( double ) src.get(x,y,2) / srcM;
+        ColorConversion::ccRGBtoHSL ( R, G, B, &H, &S, &L );
+        dst[0](x,y) = ( DstPixelType ) ( H * dstM );
+        dst[1](x,y) = ( DstPixelType ) ( S * dstM );
+        dst[2](x,y) = ( DstPixelType ) ( L * dstM );
+      }
+  }
+  else if ( ( srcColorSpace == COLORSPACE_RGB ) && ( dstColorSpace == COLORSPACE_LAB ) )
+  {
+    for ( int y = 0 ; y < src.height() ; y++ )
+      for ( int x = 0 ; x < src.width() ; x++ )
+      {
+        double R, G, B, X, Y, Z, L, a, b;
+        R = ( double ) src.get(x,y,0) / 255.0;
+        G = ( double ) src.get(x,y,1) / 255.0;
+        B = ( double ) src.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 );
+        dst[0](x,y) = ( DstPixelType ) ( L );
+        dst[1](x,y) = ( DstPixelType ) ( a );
+        dst[2](x,y) = ( DstPixelType ) ( b );
+      }
+  }
+  else if ( ( srcColorSpace == COLORSPACE_LAB ) && ( dstColorSpace == COLORSPACE_RGB ) )
+  {
+    long k = 0;
+    for ( int y = 0 ; y < src.height() ; y++ )
+      for ( int x = 0 ; x < src.width() ; x++, k++ )
+      {
+        double R, G, B, X, Y, Z, L, a, b;
+        L = ( double ) src.get(x,y,0);
+        a = ( double ) src.get(x,y,1);
+        b = ( double ) src.get(x,y,2);
+        ColorConversion::ccCIE_LabtoXYZ ( L, a, b, &X, &Y, &Z, 0 );
+        ColorConversion::ccXYZtoRGB ( X, Y, Z, &R, &G, &B, 0 );
+        dst[0](x,y) = ( DstPixelType ) ( R );
+        dst[1](x,y) = ( DstPixelType ) ( G );
+        dst[2](x,y) = ( DstPixelType ) ( B );
+      }
+  }
+  else if ( ( srcColorSpace == COLORSPACE_RGB ) && ( dstColorSpace == COLORSPACE_LMS ) )
+  {
+    long k = 0;
+    for ( int y = 0 ; y < src.height() ; y++ )
+      for ( int x = 0 ; x < src.width() ; x++, k++ )
+      {
+        double R, G, B, X, Y, Z, L, M, S;
+        R = ( double ) src.get(x,y,0) / srcM;
+        G = ( double ) src.get(x,y,1) / srcM;
+        B = ( double ) src.get(x,y,2) / srcM;
+        ColorConversion::ccRGBtoXYZ ( R, G, B, &X, &Y, &Z, 0 );
+        ColorConversion::ccXYZtoLMS ( X, Y, Z, &L, &M, &S );
+        dst[0](x,y) = ( DstPixelType ) ( L );
+        dst[1](x,y) = ( DstPixelType ) ( M );
+        dst[2](x,y) = ( DstPixelType ) ( S );
+      }
+  }
+  else if ( ( srcColorSpace == COLORSPACE_RGB ) && ( dstColorSpace == COLORSPACE_OPP ) )
+  {
+    long k = 0;
+    for ( int y = 0 ; y < src.height() ; y++ )
+      for ( int x = 0 ; x < src.width() ; x++, k++ )
+      {
+        double R, G, B, X, Y, Z, L, M, S, Lum, LM, SLM;
+        R = ( double ) src.get(x,y,0) / srcM;
+        G = ( double ) src.get(x,y,1) / srcM;
+        B = ( double ) src.get(x,y,2) / srcM;
+        ColorConversion::ccRGBtoXYZ ( R, G, B, &X, &Y, &Z, 0 );
+        ColorConversion::ccXYZtoLMS ( X, Y, Z, &L, &M, &S );
+        ColorConversion::ccLMStoOPP ( L, M, S, &Lum, &LM, &SLM );
+
+        dst[0](x,y) = ( DstPixelType ) ( Lum );
+        dst[1](x,y) = ( DstPixelType ) ( LM );
+        dst[2](x,y) = ( DstPixelType ) ( SLM );
 #ifdef DEBUG
-               fprintf(stderr,"R:%.4f G:%.4f B:%.4f X:%.4f Y:%.4f Z:%.4f L:%.4f M:%.4f S:%.4f Lum:%.4f LM:%.4f SLM:%.4f\n",R,G,B,X,Y,Z,L,M,S,Lum,LM,SLM);
+        fprintf ( stderr, "R:%.4f G:%.4f B:%.4f X:%.4f Y:%.4f Z:%.4f L:%.4f M:%.4f S:%.4f Lum:%.4f LM:%.4f SLM:%.4f\n", R, G, B, X, Y, Z, L, M, S, Lum, LM, SLM );
 #endif
-}
-}
-     else {
-          fprintf (stderr, "ColorSpace::convert(): not yet implemented - SrcColorSpace %d -> DstColorSpace %d!!\n",srcColorSpace,dstColorSpace);
-	exit(-1);
-    }
+      }
+  }
+  else {
+    fprintf ( stderr, "ColorSpace::convert(): not yet implemented - SrcColorSpace %d -> DstColorSpace %d!!\n", srcColorSpace, dstColorSpace );
+    exit ( -1 );
+  }
 
 }
 

+ 9 - 0
baselib/FastFilter.h

@@ -65,6 +65,15 @@ class FastFilter
 	template <class SrcValueType, class DstValueType>
 	static void calcGradientX ( const SrcValueType *img, int xsize, int ysize, DstValueType *d );
 
+	///lazy attempt for realizing fast histogram of oriented gradients
+	///since (neg.) double values are allowed, fast filtering based on look-up tables is no longer possible
+	template <class GrayValueType, class OrientedGradientHistogramType>
+	static void calcOrientedGradientHistogram ( const GrayValueType *gray, 
+						    int xsize, int ysize,
+						    OrientedGradientHistogramType *hog, 
+						    int numBins, 
+						    bool usesigned );
+
 };
 
 } // namespace

+ 47 - 0
baselib/FastFilter.tcc

@@ -171,3 +171,50 @@ void FastFilter::calcGradient ( const GrayValueType *gray,
     delete [] gy;
 }
 
+
+//lazy attempt for realizing fast histogram of oriented gradients
+//since (neg.) double values are allowed, fast filtering based on look-up tables is no longer possible
+template <class GrayValueType, class OrientedGradientHistogramType>
+void FastFilter::calcOrientedGradientHistogram ( const GrayValueType *gray, 
+						 int xsize, int ysize,
+						 OrientedGradientHistogramType *hog, 
+						 int numBins, 
+						 bool usesigned )
+{
+    double *gx = new double[xsize*ysize];
+    calcGradientX ( gray, xsize, ysize, gx );
+    double *gy = new double[xsize*ysize];
+    calcGradientY ( gray, xsize, ysize, gy );
+    
+    double binq = usesigned ? 2*M_PI / numBins : M_PI / numBins;
+
+    for(int i=0; i<numBins; i++) hog[i] = (OrientedGradientHistogramType) 0.0;
+
+    int k = 0;
+    for ( int y = 0 ; y < ysize ; y++ )
+	for ( int x = 0 ; x < xsize ; x++,k++ )
+	{
+	    double rx = gx[k];
+	    double ry = gy[k];
+	    //GradientMagnitudeType g  = (GradientMagnitudeType)sqrt ( rx*rx + ry*ry );
+	    GrayValueType g  = (GrayValueType) sqrt(rx*rx + ry*ry);
+
+	    double angle = atan2(ry,rx);
+
+	    if ( usesigned ) {
+		if ( angle < 0 )
+		    angle = 2*M_PI + angle;
+	    } else {
+		if ( angle < 0 )
+		    angle = M_PI + angle;
+	    }
+
+	    uint bin = (uint)(angle / binq);
+            bin = bin < numBins ? bin : numBins - 1;
+	    hog[bin]+= (OrientedGradientHistogramType) g;
+	    
+	}
+
+    delete [] gx;
+    delete [] gy;
+}

+ 202 - 174
baselib/ICETools.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file ICETools.cpp
 * @brief simple ICE GUI tools
 * @author Erik Rodner
@@ -35,24 +35,24 @@ ICETools::~ICETools()
 
 void ICETools::selectRectangles ( const NICE::Image & panel, NICE::Image & overlay, vector<Vector> & x, int color )
 {
-	fthrow(Exception, "ICETools::selectRectangles -- not yet implemented due to old ICE version.");
+  fthrow ( Exception, "ICETools::selectRectangles -- not yet implemented due to old ICE version." );
 // #ifndef NOVISUAL
 //     // new NICE code
 //     vector<RectT<double> > rectangles;
-// 	 //TODO check this!
+//   //TODO check this!
 // //     NICE::selectRectangles ( panel, rectangles, "select rectangles" );
-// // 	 selectRectangles ( panel, rectangles, "select rectangles" );
-// 
+// //   selectRectangles ( panel, rectangles, "select rectangles" );
+//
 //     for ( vector<RectT<double> >::const_iterator i = rectangles.begin();
-// 	i != rectangles.end(); i++ )
+//  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 ); 
+//  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");
@@ -61,27 +61,27 @@ void ICETools::selectRectangles ( const NICE::Image & panel, NICE::Image & overl
 
 void ICETools::selectPoints ( const NICE::Image & panel, NICE::Image & overlay, vector<Vector> & x, int color )
 {
-	fthrow(Exception, "ICETools::selectPoints -- not yet implemented due to old ICE version.");
+  fthrow ( Exception, "ICETools::selectPoints -- not yet implemented due to old ICE version." );
 // #ifndef NOVISUAL
 //     vector<CoordT<double> > points;
-// 	 //TODO check this!
+//   //TODO check this!
 // //     NICE::selectPoints ( panel, points, "select points" );
-// // 	selectPoints ( panel, points, "select points" );
-// 
+// //  selectPoints ( panel, points, "select points" );
+//
 //     for ( vector<CoordT<double> >::const_iterator i = points.begin();
-// 	i != points.end(); i++ )
+//  i != points.end(); i++ )
 //     {
-// 	Vector vec (2);
-// 	vec[0] = i->x;
-// 	vec[1] = i->y;
-// 
-// 	x.push_back ( vec ); 
+//  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;
@@ -102,144 +102,172 @@ void ICETools::selectPoints ( const NICE::Image & panel, NICE::Image & overlay,
 
 void ICETools::toColor ( double x, double & r, double & g, double & b )
 {
-    size_t seg = (size_t)(x * 6.0);
-    double y   = ( 6*x - seg );
-
-    switch ( seg ) {
-	case 0: r=0.0; g=0.0; b=y;   break; 
-	case 1: r=0.0; g=  y; b=1.0; break; 
-	case 2: r=0.0; g=1.0; b=1.0-y; break; 
-	case 3: r=  y; g=1.0; b=0.0;   break; 
-	case 4: r=1.0; g=1.0-y; b=0.0;   break; 
-	case 5: r=1.0; g=y; b=y;   break; 
-	default: r=1.0; g=1.0; b=1.0; break;
-    }
+  size_t seg = ( size_t ) ( x * 6.0 );
+  double y   = ( 6 * x - seg );
+
+  switch ( seg ) {
+    case 0:
+      r = 0.0;
+      g = 0.0;
+      b = y;
+      break;
+    case 1:
+      r = 0.0;
+      g =  y;
+      b = 1.0;
+      break;
+    case 2:
+      r = 0.0;
+      g = 1.0;
+      b = 1.0 - y;
+      break;
+    case 3:
+      r =  y;
+      g = 1.0;
+      b = 0.0;
+      break;
+    case 4:
+      r = 1.0;
+      g = 1.0 - y;
+      b = 0.0;
+      break;
+    case 5:
+      r = 1.0;
+      g = y;
+      b = y;
+      break;
+    default:
+      r = 1.0;
+      g = 1.0;
+      b = 1.0;
+      break;
+  }
 }
 
 void ICETools::convertToRGB ( const NICE::Matrix & m, NICE::ColorImage & img )
 {
-	img.resize ( m.cols(), m.rows() );
-    double max = - numeric_limits<double>::max();
-    double min = numeric_limits<double>::max();
-    for ( size_t x = 0 ; x < (size_t)m.cols(); x++ )
-	for ( size_t y = 0 ; y < (size_t)m.rows() ; y++ )
-	{
-	    if (m(y, x) > max ) max =m(y, x);
-	    if (m(y, x) < min ) min =m(y, x);
-	}
-    
-    for ( size_t y = 0 ; y < (size_t)m.rows() ; y++ )
-	for ( size_t x = 0 ; x < (size_t)m.cols(); x++ )
-	{
-	    double val =(m(y, x) - min) / (max-min);
-	    double r,g,b;
-	    toColor(val, r, g, b);
-	    img.setPixel(x,y,0,(int)(r*255));
-	    img.setPixel(x,y,1,(int)(g*255));
-	    img.setPixel(x,y,2,(int)(b*255));
-	}
+  img.resize ( m.cols(), m.rows() );
+  double max = - numeric_limits<double>::max();
+  double min = numeric_limits<double>::max();
+  for ( size_t x = 0 ; x < ( size_t ) m.cols(); x++ )
+    for ( size_t y = 0 ; y < ( size_t ) m.rows() ; y++ )
+    {
+      if ( m ( y, x ) > max ) max = m ( y, x );
+      if ( m ( y, x ) < min ) min = m ( y, x );
+    }
+cout << "max: " << max << " min: " << min << endl;
+  for ( size_t y = 0 ; y < ( size_t ) m.rows() ; y++ )
+    for ( size_t x = 0 ; x < ( size_t ) m.cols(); x++ )
+    {
+      double val = ( m ( y, x ) - min ) / ( max - min );
+      double r, g, b;
+      toColor ( val, r, g, b );
+      img.setPixel ( x, y, 0, ( int ) ( r*255 ) );
+      img.setPixel ( x, y, 1, ( int ) ( g*255 ) );
+      img.setPixel ( x, y, 2, ( int ) ( b*255 ) );
+    }
 }
 
 void ICETools::convertToRGB ( const NICE::FloatImage & m, NICE::ColorImage & img )
 {
-	img.resize ( m.width(), m.height() );
-    double max = - numeric_limits<double>::max();
-    double min = numeric_limits<double>::max();
-    for ( size_t x = 0 ; x < (size_t)m.width(); x++ )
-	for ( size_t y = 0 ; y < (size_t)m.height() ; y++ )
-	{
-	    double v = m.getPixel(x,y);
-	    if ( v > max ) max = v;
-	    if ( v < min ) min = v;
-	}
-    
-    for ( size_t y = 0 ; y < (size_t)m.height() ; y++ )
-	for ( size_t x = 0 ; x < (size_t)m.width(); x++ )
-	{
-	    double val = (m.getPixel(x,y) - min) / (max-min);
-	    double r,g,b;
-	    toColor(val, r, g, b);
-	    img.setPixel(x,y,0,(int)(r*255));
-	    img.setPixel(x,y,1,(int)(g*255));
-	    img.setPixel(x,y,2,(int)(b*255));
-	}
+  img.resize ( m.width(), m.height() );
+  double max = - numeric_limits<double>::max();
+  double min = numeric_limits<double>::max();
+  for ( size_t x = 0 ; x < ( size_t ) m.width(); x++ )
+    for ( size_t y = 0 ; y < ( size_t ) m.height() ; y++ )
+    {
+      double v = m.getPixel ( x, y );
+      if ( v > max ) max = v;
+      if ( v < min ) min = v;
+    }
+
+  for ( size_t y = 0 ; y < ( size_t ) m.height() ; y++ )
+    for ( size_t x = 0 ; x < ( size_t ) m.width(); x++ )
+    {
+      double val = ( m.getPixel ( x, y ) - min ) / ( max - min );
+      double r, g, b;
+      toColor ( val, r, g, b );
+      img.setPixel ( x, y, 0, ( int ) ( r*255 ) );
+      img.setPixel ( x, y, 1, ( int ) ( g*255 ) );
+      img.setPixel ( x, y, 2, ( int ) ( b*255 ) );
+    }
 }
 
 void ICETools::calcGrayImage ( const NICE::ColorImage & img, NICE::Image & imgg )
 {
-    imgg.resize(img.width(), img.height());
-    for ( int y = 0 ; y < img.height(); y++ )
-      for ( int x = 0 ; x < img.width() ; x++ )
-      {
-        unsigned char g = (unsigned char)(0.299*img.getPixel(x,y,0) + 
-          0.587*img.getPixel(x,y,1) + 0.114*img.getPixel(x,y,2));
-        imgg.setPixel(x,y,g);
-      }
+  imgg.resize ( img.width(), img.height() );
+  for ( int y = 0 ; y < img.height(); y++ )
+    for ( int x = 0 ; x < img.width() ; x++ )
+    {
+      unsigned char g = ( unsigned char ) ( 0.299 * img.getPixel ( x, y, 0 ) +
+                                            0.587 * img.getPixel ( x, y, 1 ) + 0.114 * img.getPixel ( x, y, 2 ) );
+      imgg.setPixel ( x, y, g );
+    }
 }
 
 double *ICETools::convertICE2M ( const NICE::Matrix & M )
 {
-    double *raw = new double [ M.rows() * M.cols() ];
-    long index = 0;
-    for ( uint i = 0 ; i < M.rows() ; i++ )
-      for ( uint j = 0 ; j < M.cols() ; j++, index++ )
-        raw[index] = M(i, j);
+  double *raw = new double [ M.rows() * M.cols() ];
+  long index = 0;
+  for ( uint i = 0 ; i < M.rows() ; i++ )
+    for ( uint j = 0 ; j < M.cols() ; j++, index++ )
+      raw[index] = M ( i, j );
 
-    return raw;
+  return raw;
 }
 
 void ICETools::convertM2ICE ( NICE::Matrix & M, double *raw )
 {
-    long index = 0;
-    for ( int i = 0 ; i < (int)M.rows() ; i++ )
-		for ( int j = 0 ; j < (int)M.cols() ; j++, index++ )
-	    	M(i, j) = raw[index];
+  long index = 0;
+  for ( int i = 0 ; i < ( int ) M.rows() ; i++ )
+    for ( int j = 0 ; j < ( int ) M.cols() ; j++, index++ )
+      M ( i, j ) = raw[index];
 }
 
 #ifndef NOVISUAL
-int ICETools::markImage (const NICE::Image & img, NICE::Image & mark, int marksize, int color)
+int ICETools::markImage ( const NICE::Image & img, NICE::Image & mark, int marksize, int color )
 {
-    fprintf (stderr, "ICETools::markImage: reimplement this function for NICE\n");
-    exit(-1);
-
-/*
-    int flags;
-    int p[2];
-    int xo = -1;
-    int yo = -1;
-    
-    while(1) {
-	// refactor-nice.pl: check this substitution
-	// old: flags = Mouse(img,p[0],p[1]);
-	// REFACTOR-FIXME Unable to map this statement
-	if ( (flags & M_LEFT_DOWN) > 0 ) {
-	    if ( (p[0] != xo) || (p[1] != yo) ) {
-		if ( marksize == 1 ) {
-		    // refactor-nice.pl: check this substitution
-		    // old: PutVal( mark, p[0], p[1], color );
-		    mark.setPixel(p[0],p[1],color);
-		} else {
-		    // refactor-nice.pl: check this substitution
-		    // old: Marker(3, p[0], p[1], color, marksize, mark);
-		    // REFACTOR-FIXME Unable to map this statement
-		}
-       
-		xo = p[0];
-		yo = p[1];
-	    }
-	}
-	if ( (flags & M_RIGHT_DOWN) > 0 ) {
-	    while ( (flags & M_RIGHT_DOWN) > 0 ) {
-		// refactor-nice.pl: check this substitution
-		// old: flags = Mouse(img,p[0],p[1]);
-		// REFACTOR-FIXME Unable to map this statement
-	    };
-	    return -1;
-	}
+  fprintf ( stderr, "ICETools::markImage: reimplement this function for NICE\n" );
+  exit ( -1 );
+
+  /*
+      int flags;
+      int p[2];
+      int xo = -1;
+      int yo = -1;
+
+      while(1) {
+   // refactor-nice.pl: check this substitution
+   // old: flags = Mouse(img,p[0],p[1]);
+   // REFACTOR-FIXME Unable to map this statement
+   if ( (flags & M_LEFT_DOWN) > 0 ) {
+       if ( (p[0] != xo) || (p[1] != yo) ) {
+    if ( marksize == 1 ) {
+        // refactor-nice.pl: check this substitution
+        // old: PutVal( mark, p[0], p[1], color );
+        mark.setPixel(p[0],p[1],color);
+    } else {
+        // refactor-nice.pl: check this substitution
+        // old: Marker(3, p[0], p[1], color, marksize, mark);
+        // REFACTOR-FIXME Unable to map this statement
     }
-*/
 
-    return 0;
+    xo = p[0];
+    yo = p[1];
+       }
+   }
+   if ( (flags & M_RIGHT_DOWN) > 0 ) {
+       while ( (flags & M_RIGHT_DOWN) > 0 ) {
+    // refactor-nice.pl: check this substitution
+    // old: flags = Mouse(img,p[0],p[1]);
+    // REFACTOR-FIXME Unable to map this statement
+       };
+       return -1;
+   }
+      }
+  */
+
+  return 0;
 }
 
 // refactor-nice.pl: check this substitution
@@ -247,46 +275,46 @@ int ICETools::markImage (const NICE::Image & img, NICE::Image & mark, int marksi
 int ICETools::showImages ( vector<NICE::Image> & imagelist )
 {
 #ifndef NOVISUAL
-    for ( size_t j = 0 ; j < imagelist.size() ; j++ )
-    {
-	// refactor-nice.pl: check this substitution
-	// old: Show(ON, imagelist[j]);
-	showImage(imagelist[j]);
-    }
+  for ( size_t j = 0 ; j < imagelist.size() ; j++ )
+  {
+    // refactor-nice.pl: check this substitution
+    // old: Show(ON, imagelist[j]);
+    showImage ( imagelist[j] );
+  }
 #endif
 
-    // assumption: same size
-    // refactor-nice.pl: check this substitution
-    // old: int xsize = imagelist[0]->xsize;
-    int xsize = imagelist[0].width();
-    // refactor-nice.pl: check this substitution
-    // old: int ysize = imagelist[0]->ysize;
-    int ysize = imagelist[0].height();
-
-    int n = imagelist.size();
-    int n1 = (int)sqrt(n);
-    int n2 = n/n1 + 1;
-
-    NICE::Image img (n1*xsize, n2*ysize);
-    img.set(0);
-    int k = 0;
-    for ( int j = 0 ; j < n2 ; j++ )
-	for ( int i = 0 ; i < n1 ; i++,k++ )
-	    if ( k >= n ) break;
-	    else {
-		for ( int y = 0 ; y < imagelist[k].height(); y++ )
-		    for ( int x = 0 ; x < imagelist[k].width(); x++ )
-		    {
-          img.setPixel( i*xsize + x, j*ysize + y,
-              imagelist[k].getPixel(x,y) );
-		    }
-	    }
-
-    img.write ("display.bmp");
-
-    getchar();
-
-    return 0;
+  // assumption: same size
+  // refactor-nice.pl: check this substitution
+  // old: int xsize = imagelist[0]->xsize;
+  int xsize = imagelist[0].width();
+  // refactor-nice.pl: check this substitution
+  // old: int ysize = imagelist[0]->ysize;
+  int ysize = imagelist[0].height();
+
+  int n = imagelist.size();
+  int n1 = ( int ) sqrt ( n );
+  int n2 = n / n1 + 1;
+
+  NICE::Image img ( n1*xsize, n2*ysize );
+  img.set ( 0 );
+  int k = 0;
+  for ( int j = 0 ; j < n2 ; j++ )
+    for ( int i = 0 ; i < n1 ; i++, k++ )
+      if ( k >= n ) break;
+      else {
+        for ( int y = 0 ; y < imagelist[k].height(); y++ )
+          for ( int x = 0 ; x < imagelist[k].width(); x++ )
+          {
+            img.setPixel ( i*xsize + x, j*ysize + y,
+                           imagelist[k].getPixel ( x, y ) );
+          }
+      }
+
+  img.write ( "display.bmp" );
+
+  getchar();
+
+  return 0;
 }
 
 #endif

+ 75 - 75
baselib/ICETools.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file ICETools.h
 * @brief simple ICE GUI tools
 * @author Erik Rodner
@@ -13,7 +13,7 @@
 #include "core/vector/MatrixT.h"
 
 #include <vector>
- 
+
 
 namespace OBJREC {
 
@@ -21,82 +21,82 @@ namespace OBJREC {
 class ICETools
 {
 
-    protected:
-
-    public:
-  
-	/** simple constructor */
-	ICETools();
-      
-	/** simple destructor */
-	virtual ~ICETools();
-
-	/** select a set of rectangles (selection of top-left and bottom-right
-	    @param panel image which is displayed
-	    @param overlay overlay image which will be used to mark points
-	    @param x returned list of rectangles (top-left-x,top-left-y,width,height)
-	    @param color color which is used to mark points
-	*/
-	static void selectRectangles ( const NICE::Image & panel, NICE::Image & overlay, 
-	    std::vector<NICE::Vector> & x, int color );
-
-	/** select a set of points 
-	    @param panel image which is displayed
-	    @param overlay overlay image which will be used to mark points
-	    @param x returned list of image points
-	    @param color color which is used to mark points
-	*/
-	static void selectPoints ( const NICE::Image & panel, NICE::Image & overlay, 
-	    std::vector<NICE::Vector> & x, int color );
-
-	/** convert a double image to a pseudocolor rgb image
-	    @param m input double image
-	    @param img resulting pseudocolor rgb image
-	*/
-	static void convertToRGB ( const NICE::FloatImage & m, NICE::ColorImage & img );
-
-	/** convert a matrix to a pseudocolor rgb image
-	    @param m input double image
-	    @param img resulting pseudocolor rgb image
-	*/
-	static void convertToRGB ( const NICE::Matrix & m, NICE::ColorImage & img );
-
-	/** convert a single double value to a pseudocolor
-	    @param x input double value
-	    @param r resulting red value
-	    @param g resulting green value
-	    @param b resulting blue value
-	*/
-	static void toColor ( double x, double & r, double & g, double & b );
-
-	/** calc grayscale image from a rgb image
-	    @param img color image
-	    @param imgg resulting grayscale image
-	*/
-	static void calcGrayImage ( const NICE::ColorImage & img, NICE::Image & imgg );
-
-	/** convert a c buffer to a matrix
-	    @param M resulting matrix
-	    @param raw input c buffer
-	*/
-	static void convertM2ICE ( NICE::Matrix & M, double *raw );
-
-	/** convert a matrix to a c buffer
-	    @param M input matrix
-	    @return resulting c buffer
-	*/
-	static double *convertICE2M ( const NICE::Matrix & M );
-
-	/** show a collection of images 
-	    @param imagelist collection of images
-	    @return ...
-	*/
-	static int showImages ( std::vector<NICE::Image> & imagelist );
+  protected:
+
+  public:
+
+    /** simple constructor */
+    ICETools();
+
+    /** simple destructor */
+    virtual ~ICETools();
+
+    /** select a set of rectangles (selection of top-left and bottom-right
+        @param panel image which is displayed
+        @param overlay overlay image which will be used to mark points
+        @param x returned list of rectangles (top-left-x,top-left-y,width,height)
+        @param color color which is used to mark points
+    */
+    static void selectRectangles ( const NICE::Image & panel, NICE::Image & overlay,
+                                   std::vector<NICE::Vector> & x, int color );
+
+    /** select a set of points
+        @param panel image which is displayed
+        @param overlay overlay image which will be used to mark points
+        @param x returned list of image points
+        @param color color which is used to mark points
+    */
+    static void selectPoints ( const NICE::Image & panel, NICE::Image & overlay,
+                               std::vector<NICE::Vector> & x, int color );
+
+    /** convert a double image to a pseudocolor rgb image
+        @param m input double image
+        @param img resulting pseudocolor rgb image
+    */
+    static void convertToRGB ( const NICE::FloatImage & m, NICE::ColorImage & img );
+
+    /** convert a matrix to a pseudocolor rgb image
+        @param m input double image
+        @param img resulting pseudocolor rgb image
+    */
+    static void convertToRGB ( const NICE::Matrix & m, NICE::ColorImage & img );
+
+    /** convert a single double value to a pseudocolor
+        @param x input double value
+        @param r resulting red value
+        @param g resulting green value
+        @param b resulting blue value
+    */
+    static void toColor ( double x, double & r, double & g, double & b );
+
+    /** calc grayscale image from a rgb image
+        @param img color image
+        @param imgg resulting grayscale image
+    */
+    static void calcGrayImage ( const NICE::ColorImage & img, NICE::Image & imgg );
+
+    /** convert a c buffer to a matrix
+        @param M resulting matrix
+        @param raw input c buffer
+    */
+    static void convertM2ICE ( NICE::Matrix & M, double *raw );
+
+    /** convert a matrix to a c buffer
+        @param M input matrix
+        @return resulting c buffer
+    */
+    static double *convertICE2M ( const NICE::Matrix & M );
+
+    /** show a collection of images
+        @param imagelist collection of images
+        @return ...
+    */
+    static int showImages ( std::vector<NICE::Image> & imagelist );
 
 #ifndef NOVISUAL
-	static int markImage (const NICE::Image & img, NICE::Image & mark, int marksize, int maxColor);
+    static int markImage ( const NICE::Image & img, NICE::Image & mark, int marksize, int maxColor );
 #endif
-     
+
 };
 
 

+ 72 - 76
baselib/ProgressBarQt.cpp

@@ -54,36 +54,32 @@ ProgressBarQt::~ProgressBarQt()
 {
 }
 
-void ProgressBarQt::timediff2str ( char *text, long time )
+void ProgressBarQt::timediff2str(char *text, double dtime)
 {
-  int seconds;
-  int minutes;
-  int hours;
-  int milliseconds;
-
-  milliseconds = time % 100;
-  time /= 100;
-  seconds = time % 60;
-  time /= 60;
-  minutes = time % 60;
-  time /= 60;
-  hours = time;
-
-  if ( hours != 0 )
-  {
-    sprintf ( text, "%dh %dm %d.%d s", hours, minutes, seconds, milliseconds );
-  }
-  else if ( minutes != 0 )
-  {
-    sprintf ( text, "%dm %d.%d s", minutes, seconds, milliseconds );
-  }
-  else
-  {
-    sprintf ( text, "%d.%d s", seconds, milliseconds );
-  }
+  int time = int (dtime / 60);
+	double seconds = dtime - time*60;
+	int minutes;
+	int hours;
+
+	minutes = time % 60;
+	time /= 60;
+	hours = time;
+
+	if (hours != 0)
+	{
+		sprintf(text, "%dh %dm %5.2fs", hours, minutes, seconds);
+	}
+	else if (minutes != 0)
+	{
+		sprintf(text, "%dm %5.2fs", minutes, seconds);
+	}
+	else
+	{
+		sprintf(text, "%fs", seconds);
+	}
 }
 
-void ProgressBarQt::displayTimeStat ( int posy, char *text, long time )
+void ProgressBarQt::displayTimeStat(int posy, char *text, double time)
 {
   // Text (char *str,int x0,int y0,int val,int exp,Image img);
   char disptext[200];
@@ -100,7 +96,8 @@ double ProgressBarQt::getCurrentTime()
 
   gettimeofday ( &curtime, NULL );
 
-  return curtime.tv_sec * 100.0 + curtime.tv_usec / 10000.0;
+	//return curtime.tv_sec * 100.0 + curtime.tv_usec / 10000.0;
+	return curtime.tv_sec + curtime.tv_usec * 1e-6;
 }
 
 void ProgressBarQt::show()
@@ -122,15 +119,14 @@ void ProgressBarQt::show()
 void ProgressBarQt::hide()
 {
 
-  if ( display_on )
-  {
-    //  Show ( OFF, display, name );
-    display_on = false;
-  }
-  if ( graphicIsAvailable() )
-  {
-    dialogwindow->hide();
-  }
+	if (display_on)
+	{
+		display_on = false;
+	}
+	if (graphicIsAvailable())
+	{
+		dialogwindow->hide();
+	}
 }
 
 void ProgressBarQt::stop()
@@ -150,45 +146,45 @@ void ProgressBarQt::reset ( const std::string & _name )
 
 void ProgressBarQt::update ( int count )
 {
-  step++;
-
-  double progress = step / ( double ) count;
-
-  elapsed_time = getCurrentTime() - start_time;
-  avg_time_step = elapsed_time / step;
-  estimated_time = ( count - step ) * avg_time_step;
-
-  size_t mod;
-  if ( avg_time_step > 50.0 )
-    mod = 1;
-  else
-    mod = ( size_t ) ( 50.0 / avg_time_step ) + 1;
-
-  if ( ( mod <= 1 ) || ( step % mod == 0 ) )
-  {
-    char percent_text[10];
-    sprintf ( percent_text, "%4.2f %%", step * 100.0 / count );
-
-    displayTimeStat ( 0, "Elapsed Time : ", ( long int ) elapsed_time );
-    displayTimeStat ( 1, "Estimated Time : ", ( long int ) estimated_time );
-    displayTimeStat ( 2, "Avg. Time per step : ", ( long int ) avg_time_step );
-
-    char eltime[200];
-    char estime[200];
-    char avgtime[200];
-    timediff2str ( eltime, ( long int ) elapsed_time );
-    timediff2str ( estime, ( long int ) estimated_time );
-    timediff2str ( avgtime, ( long int ) avg_time_step );
-    fprintf (
-      stderr,
-      "[PROGRESS] %s %s (elapsed time %s, estimated time %s, avg %s), \n",
-      name.c_str(), percent_text, eltime, estime, avgtime );
-    //set progress value.
-    if ( graphicIsAvailable() )
-    {
-      progressdialog->setValue ( progress * 100 );
-    }
-  }
+	step++;
+
+	double progress = step / (double) count;
+
+	elapsed_time = getCurrentTime() - start_time;
+	avg_time_step = elapsed_time / step;
+	estimated_time = (count - step) * avg_time_step;
+
+	size_t mod;
+	if (avg_time_step > 1.0)
+		mod = 1;
+	else
+		mod = (size_t) (1.0 / avg_time_step) + 1;
+
+	if ((mod <= 1) || (step % mod == 0))
+	{
+		char percent_text[10];
+		sprintf(percent_text, "%4.2f %%", step * 100.0 / count);
+
+		displayTimeStat(0, "Elapsed Time : ", elapsed_time);
+		displayTimeStat(1, "Estimated Time : ", estimated_time);
+		displayTimeStat(2, "Avg. Time per step : ", avg_time_step);
+
+		char eltime[200];
+		char estime[200];
+		char avgtime[200];
+		timediff2str(eltime, elapsed_time);
+		timediff2str(estime, estimated_time);
+		timediff2str(avgtime, avg_time_step);
+		fprintf(
+				stderr,
+				"[PROGRESS] %s %s (elapsed time %s, estimated time %s, avg %s), \n",
+				name.c_str(), percent_text, eltime, estime, avgtime);
+		//set progress value.
+		if (graphicIsAvailable())
+		{
+			progressdialog->setValue(progress * 100);
+		}
+	}
 }
 
 bool ProgressBarQt::graphicIsAvailable()

+ 4 - 4
baselib/ProgressBarQt.h

@@ -49,10 +49,10 @@ class ProgressBarQt
 
     bool useGraphics;
 
-    void timediff2str ( char *text, long time );
-    void displayTimeStat ( int posy, char *text, long time );
-    double getCurrentTime();
-    bool graphicIsAvailable();
+	void timediff2str(char *text, double time);
+	void displayTimeStat(int posy, char *text, double time);
+	double getCurrentTime();
+	bool graphicIsAvailable();
 
   public:
 

+ 2 - 1
cbaselib/BoundingBox.cpp

@@ -132,6 +132,7 @@ BoundingBox::setID(const int &anID)
 		return;
 		/* NOTREACHED */
 	}
+	id_ = anID;
 }
 
 //! returns top left coordinate of the bounding box
@@ -191,7 +192,7 @@ BoundingBox::isValid() const
 		bottom_right_.x < 0 ||
 		bottom_right_.y < 0 ||
 		bottom_right_.y <= top_left_.y ||
-		top_left_.x <= bottom_right_.x)
+		top_left_.x >= bottom_right_.x)
 	{
 		return false;
 		/* NOTREACHED */

+ 29 - 34
cbaselib/BoundingBox.h

@@ -10,46 +10,41 @@
 
 #include "core/image/CoordT.h"
 
-using namespace NICE;
-
-namespace OBJREC {
+namespace OBJREC
+{
 
 //! \brief Contains category ID, top left and bottom right points of the bounding
-//!  box rectangle. 
+//!  box rectangle.
 class BoundingBox
 {
-public:
-	BoundingBox();
-	BoundingBox(const BoundingBox &copy);
-	~BoundingBox();
-	
-	void setTopLeft(const CoordT< int > &aTopLeft);
-	void setTopLeft(const int &x, const int &y);
-	void setBottomRight(const CoordT< int > &aBottomRight);
-	void setBottomRight(const int &x, const int &y);
-	void setWidth(const int &aWidth);
-	void setHeight(const int &aHeight);
-	void setID(const int &anID);
-	
-	CoordT< int > topLeft() const;
-	CoordT< int > bottomRight() const;
-	int width();
-	int height();
-	int id() const;
-	
-	bool isValid() const;
-	void validate();
-	
-private:
-	CoordT< int > top_left_;
-	CoordT< int > bottom_right_;
-	int id_;
+  public:
+    BoundingBox();
+    BoundingBox ( const BoundingBox &copy );
+    ~BoundingBox();
+
+    void setTopLeft ( const NICE::CoordT< int > &aTopLeft );
+    void setTopLeft ( const int &x, const int &y );
+    void setBottomRight ( const NICE::CoordT< int > &aBottomRight );
+    void setBottomRight ( const int &x, const int &y );
+    void setWidth ( const int &aWidth );
+    void setHeight ( const int &aHeight );
+    void setID ( const int &anID );
+
+    NICE::CoordT< int > topLeft() const;
+    NICE::CoordT< int > bottomRight() const;
+    int width();
+    int height();
+    int id() const;
+
+    bool isValid() const;
+    void validate();
+
+  private:
+    NICE::CoordT< int > top_left_;
+    NICE::CoordT< int > bottom_right_;
+    int id_;
 };
 
 } //namespace
 
 #endif /* __BOUNDINGBOX_H__ */
-
-/*
- * 
- */

+ 29 - 52
cbaselib/CachedExample.cpp

@@ -59,15 +59,9 @@ CachedExample::CachedExample ( const NICE::Image & _img )
 
   oxsize = _img.width();
   oysize = _img.height();
-  int *gray = new int [ oxsize*oysize ];
-  int k = 0;
-  for ( int y = 0 ; y < oysize ; y++ )
-    for ( int x = 0 ; x < oxsize ; x++, k++ )
-      gray[k] = _img.getPixel ( x, y );
-
-  ichannels[I_GRAYVALUES].reInit ( oxsize, oysize, 1, false );
-  ichannels[I_GRAYVALUES].setImage ( gray, oxsize, oysize, 0 );
-
+  
+  ichannels[I_GRAYVALUES].freeData();
+  ichannels[I_GRAYVALUES].addChannel(_img);
   hasColorInformation = false;
 }
 
@@ -87,31 +81,18 @@ CachedExample::CachedExample ( const NICE::ColorImage & img, bool disableGrayCon
     NICE::Image imggray;
     ICETools::calcGrayImage ( img, imggray );
 
-    ichannels[I_GRAYVALUES].reInit ( oxsize, oysize, 1, true );
-    int *gray = ichannels[I_GRAYVALUES].data[0];
-    int k = 0;
-    for ( int y = 0 ; y < oysize ; y++ )
-      for ( int x = 0 ; x < oxsize ; x++, k++ )
-        // refactor-nice.pl: check this substitution
-        // old: gray[k] = GetVal(imggray,x,y);
-        gray[k] = imggray.getPixel ( x, y );
+    ichannels[I_GRAYVALUES].freeData();
+    ichannels[I_GRAYVALUES].addChannel(imggray);
   }
 
-  ichannels[I_COLOR].reInit ( oxsize, oysize, 3, true );
+  ichannels[I_COLOR].reInit ( oxsize, oysize, 3);
 
-  long int k = 0;
   for ( int y = 0 ; y < oysize ; y++ )
-    for ( int x = 0 ; x < oxsize ; x++, k++ )
+    for ( int x = 0 ; x < oxsize ; x++ )
     {
-      // refactor-nice.pl: check this substitution
-      // old: ichannels[I_COLOR].data[0][k] = GetVal(img.RedImage(), x, y);
-      ichannels[I_COLOR].data[0][k] = img.getPixel ( x, y, 0 );
-      // refactor-nice.pl: check this substitution
-      // old: ichannels[I_COLOR].data[1][k] = GetVal(img.GreenImage(), x, y);
-      ichannels[I_COLOR].data[1][k] = img.getPixel ( x, y, 1 );
-      // refactor-nice.pl: check this substitution
-      // old: ichannels[I_COLOR].data[2][k] = GetVal(img.BlueImage(), x, y);
-      ichannels[I_COLOR].data[2][k] = img.getPixel ( x, y, 2 );
+      ichannels[I_COLOR](x,y,0) = img.getPixel ( x, y, 0 );
+      ichannels[I_COLOR](x,y,1) = img.getPixel ( x, y, 1 );
+      ichannels[I_COLOR](x,y,2) = img.getPixel ( x, y, 2 );
     }
 
   hasColorInformation = true;
@@ -173,12 +154,8 @@ void CachedExample::readImageData ()
   oxsize = imggray.width();
   oysize = imggray.height();
 
-  ichannels[I_GRAYVALUES].reInit ( oxsize, oysize, 1, true );
-  int *gray = ichannels[I_GRAYVALUES].data[0];
-  int k = 0;
-  for ( int y = 0 ; y < oysize ; y++ )
-    for ( int x = 0 ; x < oxsize ; x++, k++ )
-      gray[k] = imggray.getPixel ( x, y );
+  ichannels[I_GRAYVALUES].freeData();
+  ichannels[I_GRAYVALUES].addChannel(imggray);
 }
 
 void CachedExample::readImageDataRGB ()
@@ -199,40 +176,40 @@ void CachedExample::readImageDataRGB ()
 
   hasColorInformation = true;
 
-  ichannels[I_COLOR].reInit ( oxsize, oysize, 3, true );
-
-  long k = 0;
+  ichannels[I_COLOR].reInit ( oxsize, oysize, 3);
+  
   for ( int y = 0 ; y < oysize ; y++ )
-    for ( int x = 0 ; x < oxsize ; x++, k++ )
+    for ( int x = 0 ; x < oxsize ; x++)
     {
-      ichannels[I_COLOR].data[0][k] = img.getPixel ( x, y, 0 );
-      ichannels[I_COLOR].data[1][k] = img.getPixel ( x, y, 1 );
-      ichannels[I_COLOR].data[2][k] = img.getPixel ( x, y, 2 );
+      ichannels[I_COLOR](x,y,0) = img.getPixel ( x, y, 0 );
+      ichannels[I_COLOR](x,y,1) = img.getPixel ( x, y, 1 );
+      ichannels[I_COLOR](x,y,2) = img.getPixel ( x, y, 2 );
     }
 }
 
 void CachedExample::calcIntegralImage ()
 {
-  if ( ichannels[I_GRAYVALUES].xsize == 0 )
+  if ( ichannels[I_GRAYVALUES].width() == 0 )
   {
     readImageData ();
-    if ( ichannels[I_GRAYVALUES].xsize == 0 )
+    if ( ichannels[I_GRAYVALUES].width() == 0 )
     {
       fprintf ( stderr, "CachedExample::getChannel: unable to recover data channel\n" );
       exit ( -1 );
     }
   }
 
-  lchannels[L_INTEGRALIMAGE].reInit ( ichannels[I_GRAYVALUES].xsize,
-                                      ichannels[I_GRAYVALUES].ysize,
-                                      1, true );
+  lchannels[L_INTEGRALIMAGE].reInit ( ichannels[I_GRAYVALUES].width(),
+                                      ichannels[I_GRAYVALUES].height(),
+                                      1);
 
-  GenericImageTools::calcIntegralImage (
-    lchannels[L_INTEGRALIMAGE].data[0],
-    ichannels[I_GRAYVALUES].data[0],
-    ichannels[I_GRAYVALUES].xsize,
-    ichannels[I_GRAYVALUES].ysize );
+  ImageT<long int> tmp = lchannels[L_INTEGRALIMAGE][0];
 
+  GenericImageTools::calcIntegralImage (
+    tmp,
+    ichannels[I_GRAYVALUES][0],
+    ichannels[I_GRAYVALUES].width(),
+    ichannels[I_GRAYVALUES].height() );
 }
 
 void CachedExample::buildIntegralSV ( int svchannel,

+ 273 - 248
cbaselib/CachedExample.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file CachedExample.h
 * @brief data caching of several feature images and many more
 * @author Erik Rodner
@@ -15,290 +15,315 @@
 #include "core/image/MultiChannelImageT.h"
 #include "core/basics/FileMgt.h"
 
-using namespace NICE;
-
-namespace OBJREC {
+namespace OBJREC
+{
 
 /** data caching of several feature images and many more,
-    can be used in conjunction with Example 
+    can be used in conjunction with Example
     to share image data between different sliding windows within
     an image
     @see Example */
 class CachedExample
 {
 
-    protected:
-	/** resize image to this fixed width */
-	int newWidth;
-	/** resize image to this fixed height */
-	int newHeight;
-
-	/** original image width */
-	int oxsize;
-	/** original image height */
-	int oysize;
-
-	/** filename of image */
-	std::string imgfn;
-
-	/** array of double images */
-	MultiChannelImageT<double> *dchannels;
-
-	/** array of integer images */
-	MultiChannelImageT<int> *ichannels;
-
-	/** array of histogram images */
-	MultiChannelImageT<long> *lchannels;
-
-	/** maps for temporary files */
-	std::map<int, std::string> dtemps;
-	std::map<int, std::string> itemps;
-	std::map<int, std::string> ltemps;
-
-	/** read standard image data from file */
-	void readImageData ();
-	
-	/** read rgb image data from file */
-	void readImageDataRGB ();
-
-	/** calc grayvalue integral image */
-	void calcIntegralImage ();
-
-	/** array of histogram images */
-	SparseVector **svmap;
-	
-	/** sizes of histogram images */
-	int *svmap_xsize;
-	int *svmap_ysize;
-
-	bool hasColorInformation;
-
-    public:
-
-	/** whether one can obtain color information */
-	bool colorInformationAvailable() const;
-
-  	enum {
-	    L_INTEGRALIMAGE = 0,
-	    L_NUMCHANNELS
-	};
-
-	/** integer channel types */
-	enum {
-	    I_GRAYVALUES = 0,
-	    I_COLOR,
-	    I_EDGES,
-	    I_NUMCHANNELS
-	};
-
-	/** double value channels */
-	enum {
-	    D_EOH = 0,
-	    D_INTEGRALPRIOR,
-	    D_INTEGRALEOH,
-	    D_INTEGRALCOLOR,
-	    D_NUMCHANNELS
-	};
-
-	
-	/** sparse histogram channel types */
-	enum {
-	    SVTEXTON = 0,
-	    SVNUMCHANNELS
-	};
-
-	/** default init method */
-	void init ();
-
-	/** simple constructor 
-	    @param imgfn image filename
-	    @param newWidth resize raw image to this width
-	    @param newHeight resize raw image to this height
-	*/
-	CachedExample( const std::string & imgfn, int newWidth = -1, 
-					     int newHeight = -1 );
-	
-	/** constructor (disabled buffering)
-	    @param img gray-value image
-	*/
-	CachedExample( const NICE::Image & img );
-      
-	/** constructor (disabled buffering)
-	    @param img rgb image
-	    @param disableGrayConversion whether to provide gray values or not
-	*/
-	CachedExample( const NICE::ColorImage & img, bool disableGrayConversion = false );
-
-	/** simple destructor */
-	virtual ~CachedExample();
-
-	/**
-	 * get the NICE::Image Filename
-	 * @return NICE::Image Filename
-	 */
-	inline std::string getFilename();
-	
-	
-	/** get double image channel 
-	    @param channel channel type (choose from enum type)
-	    @param[out] xsize width of image
-	    @param[out] ysize height of image
-	    @return buffer to image data
-	*/
-	inline MultiChannelImageT<double> & getDChannel ( int channel ); 
-
-	/** get integer image channel 
-	    @param channel channel type (choose from enum type)
-	    @param[out] xsize width of image
-	    @param[out] ysize height of image
-	    @return buffer to image data
-	*/
-	inline MultiChannelImageT<int> & getIChannel ( int channel ); 
-
-	/** get long image channel 
-	    @param channel channel type (choose from enum type)
-	    @param[out] xsize width of image
-	    @param[out] ysize height of image
-	    @return buffer to image data
-	*/
-	inline MultiChannelImageT<long> & getLChannel ( int channel ); 
-
-	/** get histogram image
-	    @param svchannel channel type (choose from histogram channel enum)
-	    @param[out] xsize width of raw image
-	    @param[out] ysize height of raw image
-	    @param[out] tm_xsize width of histogram channel buffer
-	    @param[out] tm_ysize height of histogram channel buffer
-	    @remark buffer will be not copied !!
-	    @return pointer to histogram channel buffer
-	*/
-	SparseVector *getSVMap ( int svchannel, int & xsize, int & ysize, int & tm_xsize, int & tm_ysize ) const;
-
-	/** assign histogram channel buffer and compute integral image
-	    @param svchannel 
-	    @param _map pointer to histogram channel buffer
-	    @param xsize_s width of histogram channel buffer
-	    @param ysize_s height of histogram channel buffer
-	    @remark buffer will be not copied !!
-	*/
-	void buildIntegralSV ( int svchannel, SparseVector *_map, int xsize_s, int ysize_s );
-	
-    	/** assign histogram channel buffer
-	    @param svchannel 
-	    @param _map pointer to histogram channel buffer
-	    @param xsize_s width of histogram channel buffer
-	    @param ysize_s height of histogram channel buffer
-	    @remark buffer will be not copied !!
-	*/
-	void setSVMap ( int svchannel, SparseVector *_map, int xsize_s, int ysize_s );
-
-	/** get image sizes */
-	void getImageSize ( int & xsize, int & ysize ) const { xsize = oxsize; ysize = oysize; };
-
-	/** drop precached data: 
-		(1) this is only possible if an image filename is given 
-		(2) only data channels are deleted that can be reproduced by CachedExample itself
-	*/
-	void dropPreCached();
-
-	template<class ImgPixelValue>
-	void dropImages ( MultiChannelImageT<ImgPixelValue> *images, 
-			  std::map<int, std::string> & temps, 
-			  int numImages ); 
+  protected:
+    /** resize image to this fixed width */
+    int newWidth;
+    /** resize image to this fixed height */
+    int newHeight;
+
+    /** original image width */
+    int oxsize;
+    /** original image height */
+    int oysize;
+
+    /** filename of image */
+    std::string imgfn;
+
+    /** array of double images */
+    NICE::MultiChannelImageT<double> *dchannels;
+
+    /** array of integer images */
+    NICE::MultiChannelImageT<int> *ichannels;
+
+    /** array of histogram images */
+    NICE::MultiChannelImageT<long> *lchannels;
+
+    /** maps for temporary files */
+    std::map<int, std::string> dtemps;
+    std::map<int, std::string> itemps;
+    std::map<int, std::string> ltemps;
+
+    /** read standard image data from file */
+    void readImageData ();
+
+    /** read rgb image data from file */
+    void readImageDataRGB ();
+
+    /** calc grayvalue integral image */
+    void calcIntegralImage ();
+
+    /** array of histogram images */
+    NICE::SparseVector **svmap;
+
+    /** sizes of histogram images */
+    int *svmap_xsize;
+    int *svmap_ysize;
+
+    bool hasColorInformation;
+
+  public:
+
+    /** whether one can obtain color information */
+    bool colorInformationAvailable() const;
+
+    enum
+    {
+      L_INTEGRALIMAGE = 0,
+      L_NUMCHANNELS
+    };
+
+    /** integer channel types */
+    enum
+    {
+      I_GRAYVALUES = 0,
+      I_COLOR,
+      I_EDGES,
+      I_NUMCHANNELS
+    };
+
+    /** double value channels */
+    enum
+    {
+      D_EOH = 0,
+      D_INTEGRALPRIOR,
+      D_INTEGRALEOH,
+      D_INTEGRALCOLOR,
+      D_NUMCHANNELS
+    };
+
+
+    /** sparse histogram channel types */
+    enum
+    {
+      SVTEXTON = 0,
+      SVNUMCHANNELS
+    };
+
+    /** default init method */
+    void init ();
+
+    /** simple constructor
+        @param imgfn image filename
+        @param newWidth resize raw image to this width
+        @param newHeight resize raw image to this height
+    */
+    CachedExample ( const std::string & imgfn, int newWidth = -1,
+                    int newHeight = -1 );
+
+    /** constructor (disabled buffering)
+        @param img gray-value image
+    */
+    CachedExample ( const NICE::Image & img );
+
+    /** constructor (disabled buffering)
+        @param img rgb image
+        @param disableGrayConversion whether to provide gray values or not
+    */
+    CachedExample ( const NICE::ColorImage & img, bool disableGrayConversion = false );
+
+    /** simple destructor */
+    virtual ~CachedExample();
+
+    /**
+     * get the NICE::Image Filename
+     * @return NICE::Image Filename
+     */
+    inline std::string getFilename();
+
+
+    /** get double image channel
+        @param channel channel type (choose from enum type)
+        @param[out] xsize width of image
+        @param[out] ysize height of image
+        @return buffer to image data
+    */
+    inline NICE::MultiChannelImageT<double> & getDChannel ( int channel );
+
+    /** get integer image channel
+        @param channel channel type (choose from enum type)
+        @param[out] xsize width of image
+        @param[out] ysize height of image
+        @return buffer to image data
+    */
+    inline NICE::MultiChannelImageT<int> & getIChannel ( int channel );
+
+    /** get long image channel
+        @param channel channel type (choose from enum type)
+        @param[out] xsize width of image
+        @param[out] ysize height of image
+        @return buffer to image data
+    */
+    inline NICE::MultiChannelImageT<long> & getLChannel ( int channel );
+
+    /** get histogram image
+        @param svchannel channel type (choose from histogram channel enum)
+        @param[out] xsize width of raw image
+        @param[out] ysize height of raw image
+        @param[out] tm_xsize width of histogram channel buffer
+        @param[out] tm_ysize height of histogram channel buffer
+        @remark buffer will be not copied !!
+        @return pointer to histogram channel buffer
+    */
+    NICE::SparseVector *getSVMap ( int svchannel, int & xsize, int & ysize, int & tm_xsize, int & tm_ysize ) const;
+
+    /** assign histogram channel buffer and compute integral image
+        @param svchannel
+        @param _map pointer to histogram channel buffer
+        @param xsize_s width of histogram channel buffer
+        @param ysize_s height of histogram channel buffer
+        @remark buffer will be not copied !!
+    */
+    void buildIntegralSV ( int svchannel, NICE::SparseVector *_map, int xsize_s, int ysize_s );
+
+    /** assign histogram channel buffer
+    @param svchannel
+    @param _map pointer to histogram channel buffer
+    @param xsize_s width of histogram channel buffer
+    @param ysize_s height of histogram channel buffer
+    @remark buffer will be not copied !!
+    */
+    void setSVMap ( int svchannel, NICE::SparseVector *_map, int xsize_s, int ysize_s );
+
+    /** get image sizes */
+    void getImageSize ( int & xsize, int & ysize ) const
+    {
+      xsize = oxsize;
+      ysize = oysize;
+    };
+
+    /** drop precached data:
+     (1) this is only possible if an image filename is given
+     (2) only data channels are deleted that can be reproduced by CachedExample itself
+    */
+    void dropPreCached();
+
+    template<class ImgPixelValue>
+    void dropImages ( NICE::MultiChannelImageT<ImgPixelValue> *images,
+                      std::map<int, std::string> & temps,
+                      int numImages );
 };
 
 
 /********************** INLINE FUNCTIONS *****************************/
-inline MultiChannelImageT<double> & CachedExample::getDChannel ( int channel )
+inline NICE::MultiChannelImageT<double> & CachedExample::getDChannel ( int channel )
 {
-    assert ( (channel >= 0) && (channel < D_NUMCHANNELS) ); 
-
-    if ( dchannels[channel].data == NULL ) {
-	std::map<int, std::string>::const_iterator j = dtemps.find(channel);
-	if ( j == dtemps.end() ) {
-	    //fprintf (stderr, "MultiChannelImageT: unable to recover data channel %s (double %d)!\n", 
-	    //	imgfn.c_str(), channel);
-	} else {
-	    //fprintf (stderr, "MultiChannelImageT: restoring data from %s ", j->second.c_str() );
-	    dchannels[channel].restore ( j->second );
-	    //fprintf (stderr, "(%d x %d)\n", dchannels[channel].xsize, dchannels[channel].ysize );
-	}
+  assert ( ( channel >= 0 ) && ( channel < D_NUMCHANNELS ) );
+
+  if ( dchannels[channel].channels() == 0 )
+  {
+    std::map<int, std::string>::const_iterator j = dtemps.find ( channel );
+    if ( j == dtemps.end() )
+    {
+      //fprintf (stderr, "NICE::MultiChannelImageT: unable to recover data channel %s (double %d)!\n",
+      // imgfn.c_str(), channel);
+    }
+    else
+    {
+      //fprintf (stderr, "NICE::MultiChannelImageT: restoring data from %s ", j->second.c_str() );
+      dchannels[channel].restore ( j->second );
+      //fprintf (stderr, "(%d x %d)\n", dchannels[channel].xsize, dchannels[channel].ysize );
     }
+  }
 
-    return dchannels[channel];
+  return dchannels[channel];
 }
 
 inline std::string CachedExample::getFilename()
 {
-	return imgfn;
+  return imgfn;
 }
 
-inline MultiChannelImageT<int> & CachedExample::getIChannel ( int channel )
+inline NICE::MultiChannelImageT<int> & CachedExample::getIChannel ( int channel )
 {
-    assert ( (channel >= 0) && (channel < I_NUMCHANNELS) ); 
+  assert ( ( channel >= 0 ) && ( channel < I_NUMCHANNELS ) );
 
-    if ( (ichannels[channel].data == NULL) )
+  if ( ( ichannels[channel].channels() == 0 ) )
+  {
+    if ( ( imgfn != "" ) && ( channel == I_GRAYVALUES ) )
     {
-	if ( (imgfn != "") && (channel == I_GRAYVALUES) ) 
-	{
-	    readImageData();
-	} else if ( (imgfn != "") && (channel == I_COLOR) ) {
-	    readImageDataRGB();
-	    assert ( hasColorInformation );
-	} else {
-	    std::map<int, std::string>::const_iterator j = itemps.find(channel);
-	    if ( j == itemps.end() ) {
-		//fprintf (stderr, "MultiChannelImageT: unable to recover data channel (int %d)!\n", channel);
-		//exit(-1);
-	    } else {
-		//fprintf (stderr, "MultiChannelImageT: restoring data from %s\n", j->second.c_str() );
-		ichannels[channel].restore ( j->second );
-	    }
-	}
+      readImageData();
     }
+    else if ( ( imgfn != "" ) && ( channel == I_COLOR ) )
+    {
+      readImageDataRGB();
+      assert ( hasColorInformation );
+    }
+    else
+    {
+      std::map<int, std::string>::const_iterator j = itemps.find ( channel );
+      if ( j == itemps.end() )
+      {
+        //fprintf (stderr, "NICE::MultiChannelImageT: unable to recover data channel (int %d)!\n", channel);
+        //exit(-1);
+      }
+      else
+      {
+        //fprintf (stderr, "NICE::MultiChannelImageT: restoring data from %s\n", j->second.c_str() );
+        ichannels[channel].restore ( j->second );
+      }
+    }
+  }
 
-    return ichannels[channel];
+  return ichannels[channel];
 }
 
-inline MultiChannelImageT<long> & CachedExample::getLChannel ( int channel )
+inline NICE::MultiChannelImageT<long> & CachedExample::getLChannel ( int channel )
 {
-    assert ( (channel >= 0) && (channel < L_NUMCHANNELS) ); 
-
-    if ( lchannels[channel].data == NULL ) {
-	std::map<int, std::string>::const_iterator j = ltemps.find(channel);
-	if ( j == ltemps.end() ) {
-
-	    if ( channel == L_INTEGRALIMAGE ) {
-		calcIntegralImage();
-	    } else {
-		//fprintf (stderr, "MultiChannelImageT: unable to recover data channel (long %d)!\n", channel);
-		//exit(-1);
-	    }
-	} else {
-	    //fprintf (stderr, "MultiChannelImageT: restoring data from %s\n", j->second.c_str() );
-	    lchannels[channel].restore ( j->second );
-	}
+  assert ( ( channel >= 0 ) && ( channel < L_NUMCHANNELS ) );
+
+  if ( lchannels[channel].channels() == 0 )
+  {
+    std::map<int, std::string>::const_iterator j = ltemps.find ( channel );
+    if ( j == ltemps.end() )
+    {
+
+      if ( channel == L_INTEGRALIMAGE )
+      {
+        calcIntegralImage();
+      }
+      else
+      {
+        //fprintf (stderr, "NICE::MultiChannelImageT: unable to recover data channel (long %d)!\n", channel);
+        //exit(-1);
+      }
+    }
+    else
+    {
+      //fprintf (stderr, "NICE::MultiChannelImageT: restoring data from %s\n", j->second.c_str() );
+      lchannels[channel].restore ( j->second );
     }
+  }
 
-    return lchannels[channel];
+  return lchannels[channel];
 }
 
 template<class ImgPixelValue>
-void CachedExample::dropImages ( MultiChannelImageT<ImgPixelValue> *images, std::map<int, std::string> & temps, int numImages )
+void CachedExample::dropImages ( NICE::MultiChannelImageT<ImgPixelValue> *images, std::map<int, std::string> & temps, int numImages )
 {
-    for ( int i = 0 ; i < numImages; i++ )
+  for ( int i = 0 ; i < numImages; i++ )
+  {
+    std::map<int, std::string>::iterator j = temps.find ( i );
+    if ( j == temps.end() )
     {
-	std::map<int, std::string>::iterator j = temps.find(i);
-	if ( j == temps.end() )
-	{
-	    std::string tempfilename = FileMgt::createTempFile("tmp/cachedexample_%s");
-	    //fprintf (stderr, "CachedExample: dumping channel %d/%d to %s (%d x %d)\n", i, numImages, tempfilename.c_str(),
-	    //	images[i].xsize, images[i].ysize );
-	    images[i].store ( tempfilename );
-	    temps[i] = tempfilename;
-	}
-	images[i].freeData();
+      std::string tempfilename = NICE::FileMgt::createTempFile ( "tmp/cachedexample_%s" );
+      //fprintf (stderr, "CachedExample: dumping channel %d/%d to %s (%d x %d)\n", i, numImages, tempfilename.c_str(),
+      // images[i].xsize, images[i].ysize );
+      images[i].store ( tempfilename );
+      temps[i] = tempfilename;
     }
+    images[i].freeData();
+  }
 
 }
 

+ 1 - 1
cbaselib/ClassNames.cpp

@@ -391,7 +391,7 @@ void ClassNames::getRGBColor ( int classno, int & r, int & g, int & b ) const
 void ClassNames::getClassnoFromColor ( int & classno, int r, int g, int b ) const
 {
   long color = 256 * ( 256 * r + g ) + b;
-  map<long, int>::const_iterator i = tbl_color_classno.find ( color );
+  __gnu_cxx::hash_map<long, int>::const_iterator i = tbl_color_classno.find ( color );
 
   if ( i == tbl_color_classno.end() )
   {

+ 5 - 1
cbaselib/ClassNames.h

@@ -15,6 +15,10 @@
 #include <string>
 #include <map>
 
+// in future we should replace this with 
+// unordered_map, but it is still experimental but standard c++
+#include <ext/hash_map>
+
 #include "core/basics/Config.h"
 #include "core/basics/Persistent.h"
 
@@ -31,7 +35,7 @@ class ClassNames : public NICE::Persistent
     std::map<std::string, std::string> tbl_text_code;
     std::map<int, std::string> tbl_classno_code;
     std::map<std::string, int> tbl_code_classno;
-    std::map<long, int> tbl_color_classno;
+    __gnu_cxx::hash_map<long, int> tbl_color_classno;
     std::map<int, long> tbl_classno_color;
 
     int maxClassNo;

+ 24 - 24
cbaselib/ClassificationResult.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file ClassificationResult.cpp
 * @brief classification result, what else?
 * @author Erik Rodner
@@ -20,33 +20,33 @@ using namespace NICE;
 
 
 
-ClassificationResult::ClassificationResult( int _rejection_status, int maxClassNo ) : scores(maxClassNo+1)
+ClassificationResult::ClassificationResult ( int _rejection_status, int maxClassNo ) : scores ( maxClassNo + 1 )
 {
-    rejection_status = _rejection_status;
-    classno = -1;
-    classno_groundtruth = -1;
-    classname = "rejected";
-	uncertainty = 0.0;
+  rejection_status = _rejection_status;
+  classno = -1;
+  classno_groundtruth = -1;
+  classname = "rejected";
+  uncertainty = 0.0;
 }
 
-ClassificationResult::ClassificationResult( int _classno, double _score, int maxClassNo ) : scores(maxClassNo+1)
+ClassificationResult::ClassificationResult ( int _classno, double _score, int maxClassNo ) : scores ( maxClassNo + 1 )
 {
-    rejection_status = REJECTION_NONE;
-    classno = _classno;
-    scores[classno] = _score;
-    classname = "unknown";
-    classno_groundtruth = -1;
-	uncertainty = 0.0;
+  rejection_status = REJECTION_NONE;
+  classno = _classno;
+  scores[classno] = _score;
+  classname = "unknown";
+  classno_groundtruth = -1;
+  uncertainty = 0.0;
 }
 
-ClassificationResult::ClassificationResult( int _classno, const FullVector & _scores )
+ClassificationResult::ClassificationResult ( int _classno, const FullVector & _scores )
 {
-    rejection_status = REJECTION_NONE;
-    classno = _classno;
-    scores = _scores;
-    classname = "unknown";
-    classno_groundtruth = -1;
-	uncertainty = 0.0;
+  rejection_status = REJECTION_NONE;
+  classno = _classno;
+  scores = _scores;
+  classname = "unknown";
+  classno_groundtruth = -1;
+  uncertainty = 0.0;
 }
 
 ClassificationResult::~ClassificationResult()
@@ -55,10 +55,10 @@ ClassificationResult::~ClassificationResult()
 
 double ClassificationResult::confidence () const
 {
-    return scores.get(classno);
+  return scores.get ( classno );
 }
-	
+
 bool ClassificationResult::ok () const
 {
-    return ( rejection_status == REJECTION_NONE );
+  return ( rejection_status == REJECTION_NONE );
 }

+ 59 - 62
cbaselib/ClassificationResult.h

@@ -1,6 +1,6 @@
-/** 
+/**
 * @file ClassificationResult.h
-* @brief classification result data (probabilities, most probable class, rejection status, ...) 
+* @brief classification result data (probabilities, most probable class, rejection status, ...)
 * @author Erik Rodner
 * @date 02/13/2008
 
@@ -16,7 +16,7 @@
 #include <map>
 #include "core/vector/SparseVectorT.h"
 #include "vislearning/math/mathbase/FullVector.h"
-  
+
 
 namespace OBJREC {
 
@@ -24,66 +24,63 @@ namespace OBJREC {
 class ClassificationResult
 {
 
-    public:
-
-	/** rejection types */
-	enum {
-	    REJECTION_FEATURE = 0,
-	    REJECTION_CLASSIFIER,
-	    REJECTION_MISC,
-	    REJECTION_NONE,
-	    REJECTION_UNINTIALIZED
-	};
-
-	/** rejection status (selected from enum) */
-	int rejection_status;
-
-	/** std::vector consisting of scores for each class 
-	    @remark no guaranteed probabilities
-	    low scores means low probability for this class
-	*/
-	FullVector scores;
-
-	/** most important part: class number of classification result,
-	    most probable class */
-	int classno;
-
-	/** evil workaround: ground truth class number (useful within ClassificationResults)
-	    @see testClassification.cpp
-	    @see ClassificationResults
-	*/
-	int classno_groundtruth;
-
-	/** text representation of the most probable class 
-	    @remark has to be set manually !! */
-	std::string classname;
- 
- 	/** uncertainty of the estimate, only available for GP classifiers */
-	double uncertainty;
- 
-	/** simple constructor, create rejected result */
-	ClassificationResult( int rejection_status = REJECTION_UNINTIALIZED, int maxClassNo = 0 );
-      
-	/** result of classification only consists of the most probable
-	    class @p classno and a score of this assigment */
-	ClassificationResult( int classno, double score, int maxClassNo );
-	
-	/** result of classification consists of most probable class @p classno
-	    and a score for each of the other classes */
-	ClassificationResult( int classno, const FullVector & scores );
-
-	/** simple destructor */
-	virtual ~ClassificationResult();
-
-	/** was it rejected ? */
-	bool ok () const;
-
-	/** probability of predicted class */
-	double confidence () const;
-
-     
-};
+  public:
+
+    /** rejection types */
+    enum {
+      REJECTION_FEATURE = 0,
+      REJECTION_CLASSIFIER,
+      REJECTION_MISC,
+      REJECTION_NONE,
+      REJECTION_UNINTIALIZED
+    };
+
+    /** rejection status (selected from enum) */
+    int rejection_status;
+
+    /** std::vector consisting of scores for each class
+        @remark no guaranteed probabilities
+        low scores means low probability for this class
+    */
+    FullVector scores;
+
+    /** most important part: class number of classification result,
+        most probable class */
+    int classno;
+
+    /** evil workaround: ground truth class number (useful within ClassificationResults)
+        @see testClassification.cpp
+        @see ClassificationResults
+    */
+    int classno_groundtruth;
+
+    /** text representation of the most probable class
+        @remark has to be set manually !! */
+    std::string classname;
 
+    /** uncertainty of the estimate, only available for GP classifiers */
+    double uncertainty;
+
+    /** simple constructor, create rejected result */
+    ClassificationResult ( int rejection_status = REJECTION_UNINTIALIZED, int maxClassNo = 0 );
+
+    /** result of classification only consists of the most probable
+        class @p classno and a score of this assigment */
+    ClassificationResult ( int classno, double score, int maxClassNo );
+
+    /** result of classification consists of most probable class @p classno
+        and a score for each of the other classes */
+    ClassificationResult ( int classno, const FullVector & scores );
+
+    /** simple destructor */
+    virtual ~ClassificationResult();
+
+    /** was it rejected ? */
+    bool ok () const;
+
+    /** probability of predicted class */
+    double confidence () const;
+};
 
 } // namespace
 

+ 20 - 19
cbaselib/Feature.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file Feature.h
 * @brief abstraction of a feature
 * @author Erik Rodner
@@ -38,29 +38,29 @@ class FeatureStorageUnsorted : public std::map< int, FeatureValuesUnsorted > {};
 class Feature : public NICE::Persistent
 {
 
-    protected:
+protected:
 
-    public:
-  
-	/** simple constructor */
-	Feature();
-      
-	/** simple destructor */
-	virtual ~Feature();
+public:
 
-	virtual double val( const Example *example ) const = 0;
+    /** simple constructor */
+    Feature();
 
-	virtual Feature *clone() const = 0;
+    /** simple destructor */
+    virtual ~Feature();
 
-	virtual void explode ( FeaturePool & featurePool, bool variableWindow = true ) const = 0;
+    virtual double val( const Example *example ) const = 0;
 
-	virtual void calcFeatureValues ( const Examples & examples,
-				    std::vector<int> & examples_selection,
-				    FeatureValuesUnsorted & values ) const;
-    
-        virtual void calcFeatureValues ( const Examples & examples,
-				    std::vector<int> & examples_selection,
-				    FeatureValues & values ) const;
+    virtual Feature *clone() const = 0;
+
+    virtual void explode ( FeaturePool & featurePool, bool variableWindow = true ) const = 0;
+
+    virtual void calcFeatureValues ( const Examples & examples,
+                                     std::vector<int> & examples_selection,
+                                     FeatureValuesUnsorted & values ) const;
+
+    virtual void calcFeatureValues ( const Examples & examples,
+                                     std::vector<int> & examples_selection,
+                                     FeatureValues & values ) const;
 
 };
 
@@ -70,3 +70,4 @@ class Feature : public NICE::Persistent
 #undef ROADWORKS
 
 #endif
+

+ 12 - 11
cbaselib/ImageInfo.cpp

@@ -99,20 +99,18 @@ ImageInfo::loadImageInfo(const string &aFilename)
 			/* path to the segmented image */
 			if (element.tagName() == "segmented") {
 				string_buffer = element.text();
-				if (string_buffer.isEmpty()) {
-					continue;
+				if ( !string_buffer.isEmpty() ) {
+					QByteArray array = string_buffer.toAscii();
+					segmented_image_path_ = string(array.data());
 				}
-				QByteArray array = string_buffer.toAscii();
-				segmented_image_path_ = string(array.data());
 			}
 			/* image description */
 			else if (element.tagName() == "description") {
 				string_buffer = element.text();
-				if (string_buffer.isEmpty()) {
-					continue;
+				if ( !string_buffer.isEmpty()) {
+					QByteArray array = string_buffer.toAscii();
+					image_description_ = string(array.data());
 				}
-				QByteArray array = string_buffer.toAscii();
-				image_description_ = string(array.data());
 			}
 			/* tags */
 			else if (element.tagName() == "tags") {
@@ -157,8 +155,8 @@ ImageInfo::loadImageInfo(const string &aFilename)
 					string_buffer = subElement.text();
 
 					if (subElement.tagName() == "bbox") {
-						BoundingBox bbox = BBoxFromData(&string_buffer);
-						bbox.setID(id);
+						BoundingBox bbox = BBoxFromData(&string_buffer, id);
+						//bbox.setID(id);
 						bboxes_.push_back(bbox);
 					}
 					if (subElement.tagName() == "poly") {
@@ -320,10 +318,13 @@ ImageInfo::loadCategoryInfo(QDomElement *anElement)
  */
 BoundingBox
 ImageInfo::BBoxFromData(
-	QString *aBBoxData
+	QString *aBBoxData,
+	int &id
 )
 {
 	BoundingBox bbox;
+	bbox.setID(id);
+
 	QString buffer;
 	int startPos = 0;
 	bool ok = 1;

+ 73 - 62
cbaselib/ImageInfo.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file ImageInfo.h
 * @brief localization info + image filename + ?
 * @author Erik Rodner
@@ -10,7 +10,7 @@
 #include "core/image/ImageT.h"
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
- 
+
 #include "vislearning/cbaselib/Polygon.h"
 #include "vislearning/cbaselib/BoundingBox.h"
 #include "vislearning/cbaselib/CategoryInfo.h"
@@ -25,71 +25,82 @@ class QDomElement;
 
 #endif //NICE_USELIB_QT4_XML
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 /** localization info + image filename + ? */
 class ImageInfo
 {
 
-    protected:
-	std::string imagefn;
-	LocalizationResult *lr;
-	bool localization_info;
-
-	#ifdef NICE_USELIB_QT4_XML
-	
-	Polygon	polyFromData(QString *aPolyData);
-	BoundingBox BBoxFromData(QString *aBBoxData);
-	void loadLegendFromElement(QDomElement *anElement);
-	bool loadCategoryInfo(QDomElement *anElement);
-	ImageT< unsigned int >	imageTFromData(
-		const int &aWidth,
-		const int &aHeight,
-		QString *aPureData
-	);
-
-	#endif //NICE_USELIB_QT4_XML
-
-    public:
-  
-	/** simple constructor */
-	ImageInfo( const std::string & _imagefn, LocalizationResult *_lr ) : 
-	    imagefn(_imagefn), lr(_lr), localization_info(true) {};
-	
-	ImageInfo() {};
-      
-	ImageInfo( const std::string & _imagefn ) : 
-	    imagefn(_imagefn), lr(NULL), localization_info(false) {};
-
-	/** simple destructor */
-	virtual ~ImageInfo();
-
-	const std::string & img () const { return imagefn; };
-	const LocalizationResult *localization () const { assert(localization_info); return lr; };
-	bool hasLocalizationInfo () const { return localization_info; };
-	
-	bool loadImageInfo(const std::string &aFilename);
-	
-	const std::list< CategoryInfo > * labels() const;
-	const std::list< BoundingBox > * bboxes() const;
-	const std::list< Polygon > * polys() const;
-	ImageT< unsigned int > labeledImage() const;
-	std::string tags() const;
-	std::string imagePath() const;
-	std::string imageDescription() const;
-	std::string segmentedImagePath() const;
-
-    private:
-	std::list< CategoryInfo > labels_;
-	std::list< BoundingBox > bboxes_;
-	std::list< Polygon > polys_;
-	ImageT< unsigned int > labeled_image_;
-	//std::list< std::string > tags_;
-	std::string tags_;
-	std::string image_path_;
-	std::string image_description_;
-	std::string segmented_image_path_;
-	
+  protected:
+    std::string imagefn;
+    LocalizationResult *lr;
+    bool localization_info;
+
+#ifdef NICE_USELIB_QT4_XML
+
+    Polygon polyFromData ( QString *aPolyData );
+    BoundingBox BBoxFromData ( QString *aBBoxData, int &id );
+    void loadLegendFromElement ( QDomElement *anElement );
+    bool loadCategoryInfo ( QDomElement *anElement );
+    NICE::ImageT< unsigned int > imageTFromData (
+      const int &aWidth,
+      const int &aHeight,
+      QString *aPureData
+    );
+
+#endif //NICE_USELIB_QT4_XML
+
+  public:
+
+    /** simple constructor */
+    ImageInfo ( const std::string & _imagefn, LocalizationResult *_lr ) :
+        imagefn ( _imagefn ), lr ( _lr ), localization_info ( true ) {};
+
+    ImageInfo() {};
+
+    ImageInfo ( const std::string & _imagefn ) :
+        imagefn ( _imagefn ), lr ( NULL ), localization_info ( false ) {};
+
+    /** simple destructor */
+    virtual ~ImageInfo();
+
+    const std::string & img () const
+    {
+      return imagefn;
+    };
+    const LocalizationResult *localization () const
+    {
+      assert ( localization_info );
+      return lr;
+    };
+    bool hasLocalizationInfo () const
+    {
+      return localization_info;
+    };
+
+    bool loadImageInfo ( const std::string &aFilename );
+
+    const std::list< CategoryInfo > * labels() const;
+    const std::list< BoundingBox > * bboxes() const;
+    const std::list< Polygon > * polys() const;
+    NICE::ImageT< unsigned int > labeledImage() const;
+    std::string tags() const;
+    std::string imagePath() const;
+    std::string imageDescription() const;
+    std::string segmentedImagePath() const;
+
+  private:
+    std::list< CategoryInfo > labels_;
+    std::list< BoundingBox > bboxes_;
+    std::list< Polygon > polys_;
+    NICE::ImageT< unsigned int > labeled_image_;
+    //std::list< std::string > tags_;
+    std::string tags_;
+    std::string image_path_;
+    std::string image_description_;
+    std::string segmented_image_path_;
+
 };
 
 

+ 218 - 218
cbaselib/LabeledFileList.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LabeledFileList.cpp
 * @brief reads images from directory
 * @author Erik Rodner
@@ -22,9 +22,9 @@ using namespace OBJREC;
 using namespace std;
 using namespace NICE;
 
-LabeledFileList::LabeledFileList() 
+LabeledFileList::LabeledFileList()
 {
-    debug_dataset = false;
+  debug_dataset = false;
 }
 
 LabeledFileList::~LabeledFileList()
@@ -33,247 +33,247 @@ LabeledFileList::~LabeledFileList()
 
 
 LocalizationResult *LabeledFileList::getLocalizationInfo ( const ClassNames & classnames,
-					    int classno,
-					    const std::string & file,
-					    const Config & conf ) const
+    int classno,
+    const std::string & file,
+    const Config & conf ) const
 {
-    /*
-    localization_pattern = image
-    localization_subst   = mask
-    localization_format  = image
-    */
-    std::string format = conf.gS("main", "localization_format", "unknown");
-    if ( format == "unknown" )
-	return NULL;
-
-    std::string pattern = conf.gS("main", "localization_pattern" );
-    std::string subst   = conf.gS("main", "localization_subst" );
-
-    std::string lfile = file;
-    if ( ! StringTools::regexSubstitute ( lfile, pattern, subst ) )
-    {
-	fprintf (stderr, "Unable to substitute using pattern #%s# and string #%s#\n",
-	    pattern.c_str(), lfile.c_str() );
-	exit(-1);
+  /*
+  localization_pattern = image
+  localization_subst   = mask
+  localization_format  = image
+  */
+  std::string format = conf.gS ( "main", "localization_format", "unknown" );
+  if ( format == "unknown" )
+    return NULL;
+
+  std::string pattern = conf.gS ( "main", "localization_pattern" );
+  std::string subst   = conf.gS ( "main", "localization_subst" );
+
+  std::string lfile = file;
+  if ( ! StringTools::regexSubstitute ( lfile, pattern, subst ) )
+  {
+    fprintf ( stderr, "Unable to substitute using pattern #%s# and string #%s#\n",
+              pattern.c_str(), lfile.c_str() );
+    exit ( -1 );
+  }
+
+  if ( ! FileMgt::fileExists ( lfile ) ) return NULL;
+  if ( debug_dataset )
+  {
+    fprintf ( stderr, "LabeledFileList: reading localization information %s\n", lfile.c_str() );
+  }
+
+  LocalizationResult *lr = NULL;
+
+  if ( format == "image" )
+  {
+    NICE::Image mask;
+    try {
+      mask.read ( lfile );
+    } catch ( ImageException & ) {
+      fprintf ( stderr, "WARNING: unable to open file %s (no localization info provided)\n",
+                lfile.c_str() );
+      return NULL;
     }
 
-    if ( ! FileMgt::fileExists(lfile) ) return NULL;
-    if ( debug_dataset )
-    {
-	fprintf (stderr, "LabeledFileList: reading localization information %s\n", lfile.c_str() );
+    lr = new LocalizationResult ( &classnames, mask, classno );
+
+  } else if ( format == "imagergb" ) {
+    NICE::ColorImage mask;
+    try {
+      mask.read ( lfile );
+    } catch ( ImageException &e ) {
+      fprintf ( stderr, "WARNING: unable to open file %s (no localization info provided)\n",
+                lfile.c_str() );
+      fprintf ( stderr, "Error: %s\n", e.what() );
+      return NULL;
     }
+    lr = new LocalizationResult ( &classnames, mask );
 
-    LocalizationResult *lr = NULL;
+  } else if ( format == "polygon" ) {
+    lr = new LocalizationResult ( &classnames );
 
-    if ( format == "image" )
-    {
-		NICE::Image mask;
-		try {
-			mask.read(lfile);
-		} catch (ImageException &) {
-			fprintf (stderr, "WARNING: unable to open file %s (no localization info provided)\n",
-			lfile.c_str() );
-			return NULL;
-		}
-		
-		lr = new LocalizationResult ( &classnames, mask, classno );
-
-    } else if ( format == "imagergb" ) {
-		NICE::ColorImage mask;
-		try {
-			mask.read( lfile );
-		} catch (ImageException &e) {
-			fprintf (stderr, "WARNING: unable to open file %s (no localization info provided)\n",
-			lfile.c_str() );
-			fprintf (stderr, "Error: %s\n", e.what() );
-			return NULL;
-		}
-		lr = new LocalizationResult ( &classnames, mask );
-
-    } else if ( format == "polygon" ) {
-		lr = new LocalizationResult ( &classnames );
-
-		lr->read ( lfile, LocalizationResult::FILEFORMAT_POLYGON );
-
-		if ( debug_dataset )
-		   fprintf (stderr, "LabeledFileList: object localization %d\n", (int)lr->size() );
-		} else {
-			fthrow(Exception, "Localization format not yet supported !!\n");
-		}
-   
-	if ( debug_dataset )
-	    if ( lr != NULL )
-			fprintf (stderr, "%s (%d objects)\n", lfile.c_str(), (int)lr->size() );
-
-    return lr;
+    lr->read ( lfile, LocalizationResult::FILEFORMAT_POLYGON );
+
+    if ( debug_dataset )
+      fprintf ( stderr, "LabeledFileList: object localization %d\n", ( int ) lr->size() );
+  } else {
+    fthrow ( Exception, "Localization format not yet supported !!\n" );
+  }
+
+  if ( debug_dataset )
+    if ( lr != NULL )
+      fprintf ( stderr, "%s (%d objects)\n", lfile.c_str(), ( int ) lr->size() );
+
+  return lr;
 }
 
 void LabeledFileList::getFromPattern (
-    const std::string & dir,
-    const Config & datasetconf,
-    const ClassNames & classnames, 
-    LabeledSet & ls,
-    bool localizationInfoDisabled ) const
+  const std::string & dir,
+  const Config & datasetconf,
+  const ClassNames & classnames,
+  LabeledSet & ls,
+  bool localizationInfoDisabled ) const
 {
-    std::string filemask;
-    
-    if ( dir.substr(dir.length()-1,1) != "/" )
-		filemask = dir + "/" + datasetconf.gS("main", "pattern");
-    else
-		filemask = dir + datasetconf.gS("main", "pattern");
-
-    std::vector<string> files;
-
-    int classnameField = datasetconf.gI("main", "classname_field", 1);
-    std::string fixedClassname = datasetconf.gS("main", "fixed_classname", "");
-    
-    files.clear();
-    FileMgt::DirectoryRecursive ( files, dir );
-    fprintf (stderr, "LabeledFileList: Files: %d\n", (int)files.size());
-
-    sort ( files.begin(), files.end() );
-
-    for ( vector<string>::const_iterator i  = files.begin();
-					 i != files.end(); 
-					 i++ ) 
+  std::string filemask;
+
+  if ( dir.substr ( dir.length() - 1, 1 ) != "/" )
+    filemask = dir + "/" + datasetconf.gS ( "main", "pattern" );
+  else
+    filemask = dir + datasetconf.gS ( "main", "pattern" );
+
+  std::vector<string> files;
+
+  int classnameField = datasetconf.gI ( "main", "classname_field", 1 );
+  std::string fixedClassname = datasetconf.gS ( "main", "fixed_classname", "" );
+
+  files.clear();
+  FileMgt::DirectoryRecursive ( files, dir );
+  fprintf ( stderr, "LabeledFileList: Files: %d\n", ( int ) files.size() );
+
+  sort ( files.begin(), files.end() );
+
+  for ( vector<string>::const_iterator i  = files.begin();
+        i != files.end();
+        i++ )
+  {
+    vector<string> submatches;
+    // refactor-nice.pl: check this substitution
+    // old: const string & file = *i;
+    const std::string & file = *i;
+    if ( debug_dataset )
+      fprintf ( stderr, "LabeledFileList: next file: %s\n", file.c_str() );
+
+    bool match = StringTools::regexMatch ( file, filemask, submatches );
+
+    if ( ( fixedClassname == "" ) && ( ( int ) submatches.size() <= classnameField ) ) match = false;
+
+    if ( ! match )
     {
-		vector<string> submatches;
-		// refactor-nice.pl: check this substitution
-		// old: const string & file = *i;
-		const std::string & file = *i;
-		if ( debug_dataset ) 
-			fprintf (stderr, "LabeledFileList: next file: %s\n", file.c_str() );
-
-		bool match = StringTools::regexMatch ( file, filemask, submatches );
-
-		if ( (fixedClassname == "") && ((int)submatches.size() <= classnameField) ) match = false;
-
-		if ( ! match  )
-		{
-			if ( debug_dataset )
-			fprintf (stderr, "LabeledFileList: WARNING: %s does not match filemask: %s!!\n", file.c_str(), filemask.c_str() );
-		} else {
-			std::string classcode = ( fixedClassname == "" ) ? submatches[classnameField] : fixedClassname;
-
-			if ( classnames.existsClassCode(classcode) ) {
-				int classno = classnames.classno(classcode);
-				LocalizationResult *lr  = NULL;
-				
-				if ( ! localizationInfoDisabled )
-					lr = getLocalizationInfo ( 
-					classnames, classno, file, datasetconf);
-
-				if ( debug_dataset )
-					fprintf (stderr, "LabeledFileList: LabeledSet: add %s (%d)\n", file.c_str(), classno );
-				if ( lr == NULL ) 
-				{
-					ls.add ( classno, new ImageInfo(file) );
-				} else {
-					ls.add ( classno, new ImageInfo(file, lr) );
-					if ( debug_dataset )
-					fprintf (stderr, "LabeledFileList: LocalizationResult added!\n");
-
-				}
-			} else {
-				if ( debug_dataset )
-				{
-					for ( vector<string>::iterator i = submatches.begin();
-								   i != submatches.end();
-								   i++ )
-					{
-						fprintf (stderr, "LabeledFileList: submatch: %s\n", i->c_str() );
-					}
-					fprintf (stderr, "LabeledFileList: WARNING: code %s ignored !\n", classcode.c_str() );
-				}
-			}
-		}
-		if ( debug_dataset )
-			fprintf (stderr, "LabeledFileList: filename processed\n");
-	}
-
-    cerr << "directory " << dir << " loaded..." << endl;
-    ls.printInformation();
+      if ( debug_dataset )
+        fprintf ( stderr, "LabeledFileList: WARNING: %s does not match filemask: %s!!\n", file.c_str(), filemask.c_str() );
+    } else {
+      std::string classcode = ( fixedClassname == "" ) ? submatches[classnameField] : fixedClassname;
+
+      if ( classnames.existsClassCode ( classcode ) ) {
+        int classno = classnames.classno ( classcode );
+        LocalizationResult *lr  = NULL;
+
+        if ( ! localizationInfoDisabled )
+          lr = getLocalizationInfo (
+                 classnames, classno, file, datasetconf );
+
+        if ( debug_dataset )
+          fprintf ( stderr, "LabeledFileList: LabeledSet: add %s (%d)\n", file.c_str(), classno );
+        if ( lr == NULL )
+        {
+          ls.add ( classno, new ImageInfo ( file ) );
+        } else {
+          ls.add ( classno, new ImageInfo ( file, lr ) );
+          if ( debug_dataset )
+            fprintf ( stderr, "LabeledFileList: LocalizationResult added!\n" );
+
+        }
+      } else {
+        if ( debug_dataset )
+        {
+          for ( vector<string>::iterator i = submatches.begin();
+                i != submatches.end();
+                i++ )
+          {
+            fprintf ( stderr, "LabeledFileList: submatch: %s\n", i->c_str() );
+          }
+          fprintf ( stderr, "LabeledFileList: WARNING: code %s ignored !\n", classcode.c_str() );
+        }
+      }
+    }
+    if ( debug_dataset )
+      fprintf ( stderr, "LabeledFileList: filename processed\n" );
+  }
+
+  cerr << "directory " << dir << " loaded..." << endl;
+  ls.printInformation();
 
 }
 
 void LabeledFileList::getFromList (
-    const std::string & filelist,
-    const Config & datasetconf,
-    const ClassNames & classnames, 
-    LabeledSet & ls,
-    bool localizationInfoDisabled) const
+  const std::string & filelist,
+  const Config & datasetconf,
+  const ClassNames & classnames,
+  LabeledSet & ls,
+  bool localizationInfoDisabled ) const
 {
-	if ( debug_dataset ) 
-		fprintf (stderr, "Reading file list: %s\n", filelist.c_str() );
+  if ( debug_dataset )
+    fprintf ( stderr, "Reading file list: %s\n", filelist.c_str() );
 
-    ifstream ifs ( filelist.c_str(), ios::in );
-	if ( ! ifs.good() ) 
-		fthrow(IOException, "File list " << filelist << " not found !");
-    
-    std::string fixedClassname = datasetconf.gS("main", "fixed_classname", "");
+  ifstream ifs ( filelist.c_str(), ios::in );
+  if ( ! ifs.good() )
+    fthrow ( IOException, "File list " << filelist << " not found !" );
 
-    while ( ! ifs.eof() )
-    {
-		std::string classcode;
-		std::string file;
-
-		if ( fixedClassname == "" ) {
-			if ( ! (ifs >> classcode) ) break;
-		} else {
-			classcode = fixedClassname;
-		}
-
-		if ( ! (ifs >> file) ) break;
-
-		if ( classnames.existsClassCode(classcode) ) {
-			int classno = classnames.classno(classcode);
-			
-			LocalizationResult *lr  = NULL;
-			
-			if ( ! localizationInfoDisabled )
-				lr = getLocalizationInfo ( classnames, classno, file, datasetconf);
-
-			if ( debug_dataset )
-				cerr << "Adding file " << file << " with classno " << classno << endl;
-
-			if ( lr == NULL ) 
-				ls.add ( classno, new ImageInfo(file) );
-			else
-				ls.add ( classno, new ImageInfo(file, lr) );
-		} else {
-			if ( debug_dataset )
-				fprintf (stderr, "WARNING: code %s ignored !\n", classcode.c_str() );
-		}
+  std::string fixedClassname = datasetconf.gS ( "main", "fixed_classname", "" );
+
+  while ( ! ifs.eof() )
+  {
+    std::string classcode;
+    std::string file;
 
+    if ( fixedClassname == "" ) {
+      if ( ! ( ifs >> classcode ) ) break;
+    } else {
+      classcode = fixedClassname;
     }
 
-	if ( debug_dataset )
-	    ls.printInformation();
-}
+    if ( ! ( ifs >> file ) ) break;
 
+    if ( classnames.existsClassCode ( classcode ) ) {
+      int classno = classnames.classno ( classcode );
 
-void LabeledFileList::get ( 
-    const std::string & dir,
-    const Config & datasetconf,
-    const ClassNames & classnames, 
-    LabeledSet & ls, 
-    bool localizationInfoDisabled,
-    bool debugDataset ) 
-{
-    std::string pattern = datasetconf.gS("main", "pattern", "");
-    std::string filelist = datasetconf.gS("main", "filelist", "");
-    this->debug_dataset = debugDataset;
+      LocalizationResult *lr  = NULL;
 
-    if ( pattern.size() > 0 ) 
-		getFromPattern ( dir, datasetconf, classnames, ls, localizationInfoDisabled );
-    else if ( filelist.size() > 0 ) {
+      if ( ! localizationInfoDisabled )
+        lr = getLocalizationInfo ( classnames, classno, file, datasetconf );
 
-		std::string cfilelist = datasetconf.gS("main", "filelist");
-		std::string filelist = ( cfilelist.substr(0,1) == "/" ) ? cfilelist : dir + "/" + cfilelist;
+      if ( debug_dataset )
+        cerr << "Adding file " << file << " with classno " << classno << endl;
 
-		getFromList ( filelist, datasetconf, classnames, ls, localizationInfoDisabled );
+      if ( lr == NULL )
+        ls.add ( classno, new ImageInfo ( file ) );
+      else
+        ls.add ( classno, new ImageInfo ( file, lr ) );
     } else {
-		fprintf (stderr, "LabeledFileList: Unable to obtain labeled file list\n");
-		exit(-1);
+      if ( debug_dataset )
+        fprintf ( stderr, "WARNING: code %s ignored !\n", classcode.c_str() );
     }
+
+  }
+
+  if ( debug_dataset )
+    ls.printInformation();
+}
+
+
+void LabeledFileList::get (
+  const std::string & dir,
+  const Config & datasetconf,
+  const ClassNames & classnames,
+  LabeledSet & ls,
+  bool localizationInfoDisabled,
+  bool debugDataset )
+{
+  std::string pattern = datasetconf.gS ( "main", "pattern", "" );
+  std::string filelist = datasetconf.gS ( "main", "filelist", "" );
+  this->debug_dataset = debugDataset;
+
+  if ( pattern.size() > 0 )
+    getFromPattern ( dir, datasetconf, classnames, ls, localizationInfoDisabled );
+  else if ( filelist.size() > 0 ) {
+
+    std::string cfilelist = datasetconf.gS ( "main", "filelist" );
+    std::string filelist = ( cfilelist.substr ( 0, 1 ) == "/" ) ? cfilelist : dir + "/" + cfilelist;
+
+    getFromList ( filelist, datasetconf, classnames, ls, localizationInfoDisabled );
+  } else {
+    fprintf ( stderr, "LabeledFileList: Unable to obtain labeled file list\n" );
+    exit ( -1 );
+  }
 }

+ 35 - 35
cbaselib/LabeledFileList.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LabeledFileList.h
 * @brief reads images from directory
 * @author Erik Rodner
@@ -21,40 +21,40 @@ namespace OBJREC {
 /** reads images from directory */
 class LabeledFileList
 {
-    private:
-	bool debug_dataset;
-
-    public:
-  
-	/** simple constructor */
-	LabeledFileList(); 
-      
-	/** simple destructor */
-	virtual ~LabeledFileList();
- 
-	LocalizationResult *getLocalizationInfo ( const ClassNames & classnames,
-					    int classno,
-					    const std::string & file,
-					    const NICE::Config & conf ) const;
-
-	void get ( const std::string & dir,
-		   const NICE::Config & datasetconf,
-		   const ClassNames & classnames, 
-		   LabeledSet & ls,
-		   bool localizationInfoDisabled = false,
-		   bool debugDataset = false );
-		   
-	void getFromPattern ( const std::string & dir,
-		   const NICE::Config & datasetconf,
-		   const ClassNames & classnames, 
-		   LabeledSet & ls,
-		   bool localizationInfoDisabled = false ) const;
-
-	void getFromList ( const std::string & filelist,
-		   const NICE::Config & datasetconf,
-		   const ClassNames & classnames, 
-		   LabeledSet & ls,
-		   bool localizationInfoDisabled = false ) const;
+  private:
+    bool debug_dataset;
+
+  public:
+
+    /** simple constructor */
+    LabeledFileList();
+
+    /** simple destructor */
+    virtual ~LabeledFileList();
+
+    LocalizationResult *getLocalizationInfo ( const ClassNames & classnames,
+        int classno,
+        const std::string & file,
+        const NICE::Config & conf ) const;
+
+    void get ( const std::string & dir,
+               const NICE::Config & datasetconf,
+               const ClassNames & classnames,
+               LabeledSet & ls,
+               bool localizationInfoDisabled = false,
+               bool debugDataset = false );
+
+    void getFromPattern ( const std::string & dir,
+                          const NICE::Config & datasetconf,
+                          const ClassNames & classnames,
+                          LabeledSet & ls,
+                          bool localizationInfoDisabled = false ) const;
+
+    void getFromList ( const std::string & filelist,
+                       const NICE::Config & datasetconf,
+                       const ClassNames & classnames,
+                       LabeledSet & ls,
+                       bool localizationInfoDisabled = false ) const;
 
 };
 

+ 175 - 166
cbaselib/LabeledSetSelection.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LabeledSetSelection.h
 * @brief Select a subset of a LabeledSet
 * @author Erik Rodner
@@ -14,177 +14,186 @@
 
 #include <set>
 #include <map>
-  
-namespace OBJREC {
+
+namespace OBJREC
+{
 
 /** Select a subset of a LabeledSet */
 template <class F>
 class LabeledSetSelection
 {
 
-    protected:
-
-    public:
-  
-	static void selectRandom ( const std::map<int,int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
-	{
-	    F & base_nonconst = const_cast< F & >(base);
-	    //srand(time(NULL));
-
-	    for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin(); 
-				    i != fixedPositiveExamples.end() ; 
-				    i++ )
-	    {
-			int classno = i->first;
-			int fixedPositiveExamples = i->second;
-
-			std::set<int> memory;
-
-			int count = base_nonconst[classno].size();
-			if ( (count < fixedPositiveExamples) ) {
-				fthrow ( Exception, "LabeledSetSelection::selectRandom: unable to select " << fixedPositiveExamples 
-					<< " of " << count << " examples" );
-			}
-
-			for ( int j = 0 ; j < fixedPositiveExamples ; j++ )
-			{
-				int k;
-				do {
-				k = rand() % count;
-				} while ( memory.find(k) != memory.end() );
-
-				memory.insert(k);
-				positive.add_reference ( classno, base_nonconst[classno][k]);
-			}
-
-			for ( int k = 0 ; k < count ; k++ )
-				if ( memory.find(k) == memory.end() )
-				negative.add_reference ( classno, base_nonconst[classno][k]);
-	    }
-	}
-
-	static void selectRandomMax ( const std::map<int,int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
-	{
-	    F & base_nonconst = const_cast< F & >(base);
-	    //srand(time(NULL));
-
-	    for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin(); 
-				    i != fixedPositiveExamples.end() ; 
-				    i++ )
-	    {
-			int classno = i->first;
-			int fixedPositiveExamples = i->second;
-
-			std::set<int> memory;
-
-			int count = base_nonconst[classno].size();
-
-			int m = fixedPositiveExamples < count ? fixedPositiveExamples : count;
-			for ( int j = 0 ; j < m ; j++ )
-			{
-				int k;
-				do {
-					k = rand() % count;
-				} while ( memory.find(k) != memory.end() );
-
-				memory.insert(k);
-				positive.add_reference ( classno, base_nonconst[classno][k]);
-			}
-
-			for ( int k = 0 ; k < count ; k++ )
-				if ( memory.find(k) == memory.end() )
-					negative.add_reference ( classno, base_nonconst[classno][k]);
-	    }
-	}
-
-	static void selectSequentialStep ( const std::map<int, int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
-	{
-	    F & base_nonconst = const_cast< F & >(base);
-
-	    for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin(); 
-				    i != fixedPositiveExamples.end() ; 
-				    i++ )
-	    {
-			int classno = i->first;
-			int fixedPositiveExamples = i->second;
-			int count = base_nonconst[classno].size();
-			int step = fixedPositiveExamples ? (count / fixedPositiveExamples) : 0;
-
-			if ( count < fixedPositiveExamples ) {
-				fthrow ( Exception, "LabeledSetSelection::selectSequentialStep: unable to select " << fixedPositiveExamples 
-						<< " of " << count << " examples (classno " << classno << ")" );
-		}
-
-
-		int k = 0;
-		for ( int j = 0 ; j < count ; j++ )
-		{
-		    if ( (step == 0) || (k >= fixedPositiveExamples) || (j % step != 0) ) 
-				negative.add_reference ( classno, base_nonconst[classno][j] );
-		    else {
-				k++;
-				positive.add_reference ( classno, base_nonconst[classno][j] );
-		    }
-		}
-	    }
-	};
-
-
-	static void selectSequential ( const std::map<int, int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
-	{
-	    F & base_nonconst = const_cast< F & >(base);
-
-	    for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin(); 
-				    i != fixedPositiveExamples.end() ; 
-				    i++ )
-	    {
-			int classno = i->first;
-			int fixedPositiveExamples = i->second;
-			int count = base_nonconst[classno].size();
-
-			if ( count < fixedPositiveExamples ) {
-				fthrow ( Exception, "LabeledSetSelection::selectSequential: unable to select " << fixedPositiveExamples 
-					<< " of " << count << " examples" );
-			}
-
-			for ( int j = 0 ; j < fixedPositiveExamples ; j++ )
-				positive.add_reference ( classno, base_nonconst[classno][j] );
-			
-			for ( int j = fixedPositiveExamples ; j < count ; j++ )
-				negative.add_reference ( classno, base_nonconst[classno][j] );
-	    }
-
-	};
-
-	static void selectClasses ( const std::set<int> & classnos, const F & base, F & positive, F & negative )
-	{
-	    F & base_nonconst = const_cast< F & >(base);
-
-	    std::vector<int> classes;
-	    base.getClasses(classes);
-
-	    for ( std::set<int>::const_iterator i = classnos.begin(); 
-				    i != classnos.end() ; 
-				    i++ )
-	    {
-			int classno = *i;
-			int count = base_nonconst[classno].size();
-			for ( int j = 0 ; j < count ; j++ )
-				positive.add_reference ( classno, base_nonconst[classno][j]);
-	    }
-
-	    for ( std::vector<int>::const_iterator i = classes.begin(); 
-				    i != classes.end() ; 
-				    i++ )
-	    {
-			int classno = *i;
-			if ( classnos.find(classno) != classnos.end() ) continue;
-			int count = base_nonconst[classno].size();
-			for ( int j = 0 ; j < count ; j++ )
-				negative.add_reference ( classno, base_nonconst[classno][j]);
-	    }
-
-	};
+  protected:
+
+  public:
+
+    static void selectRandom ( const std::map<int,int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
+    {
+      F & base_nonconst = const_cast< F & > ( base );
+      //srand(time(NULL));
+
+      for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin();
+            i != fixedPositiveExamples.end() ;
+            i++ )
+      {
+        int classno = i->first;
+        int fixedPositiveExamples = i->second;
+
+        std::set<int> memory;
+
+        int count = base_nonconst[classno].size();
+        if ( ( count < fixedPositiveExamples ) )
+        {
+          fthrow ( NICE::Exception, "LabeledSetSelection::selectRandom: unable to select " << fixedPositiveExamples
+                   << " of " << count << " examples" );
+        }
+
+        for ( int j = 0 ; j < fixedPositiveExamples ; j++ )
+        {
+          int k;
+          do
+          {
+            k = rand() % count;
+          }
+          while ( memory.find ( k ) != memory.end() );
+
+          memory.insert ( k );
+          positive.add_reference ( classno, base_nonconst[classno][k] );
+        }
+
+        for ( int k = 0 ; k < count ; k++ )
+          if ( memory.find ( k ) == memory.end() )
+            negative.add_reference ( classno, base_nonconst[classno][k] );
+      }
+    }
+
+    static void selectRandomMax ( const std::map<int,int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
+    {
+      F & base_nonconst = const_cast< F & > ( base );
+      //srand(time(NULL));
+
+      for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin();
+            i != fixedPositiveExamples.end() ;
+            i++ )
+      {
+        int classno = i->first;
+        int fixedPositiveExamples = i->second;
+
+        std::set<int> memory;
+
+        int count = base_nonconst[classno].size();
+
+        int m = fixedPositiveExamples < count ? fixedPositiveExamples : count;
+        for ( int j = 0 ; j < m ; j++ )
+        {
+          int k;
+          do
+          {
+            k = rand() % count;
+          }
+          while ( memory.find ( k ) != memory.end() );
+
+          memory.insert ( k );
+          positive.add_reference ( classno, base_nonconst[classno][k] );
+        }
+
+        for ( int k = 0 ; k < count ; k++ )
+          if ( memory.find ( k ) == memory.end() )
+            negative.add_reference ( classno, base_nonconst[classno][k] );
+      }
+    }
+
+    static void selectSequentialStep ( const std::map<int, int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
+    {
+      F & base_nonconst = const_cast< F & > ( base );
+
+      for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin();
+            i != fixedPositiveExamples.end() ;
+            i++ )
+      {
+        int classno = i->first;
+        int fixedPositiveExamples = i->second;
+        int count = base_nonconst[classno].size();
+        int step = fixedPositiveExamples ? ( count / fixedPositiveExamples ) : 0;
+
+        if ( count < fixedPositiveExamples )
+        {
+          fthrow ( NICE::Exception, "LabeledSetSelection::selectSequentialStep: unable to select " << fixedPositiveExamples
+                   << " of " << count << " examples (classno " << classno << ")" );
+        }
+
+
+        int k = 0;
+        for ( int j = 0 ; j < count ; j++ )
+        {
+          if ( ( step == 0 ) || ( k >= fixedPositiveExamples ) || ( j % step != 0 ) )
+            negative.add_reference ( classno, base_nonconst[classno][j] );
+          else
+          {
+            k++;
+            positive.add_reference ( classno, base_nonconst[classno][j] );
+          }
+        }
+      }
+    };
+
+
+    static void selectSequential ( const std::map<int, int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
+    {
+      F & base_nonconst = const_cast< F & > ( base );
+
+      for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin();
+            i != fixedPositiveExamples.end() ;
+            i++ )
+      {
+        int classno = i->first;
+        int fixedPositiveExamples = i->second;
+        int count = base_nonconst[classno].size();
+
+        if ( count < fixedPositiveExamples )
+        {
+          fthrow ( NICE::Exception, "LabeledSetSelection::selectSequential: unable to select " << fixedPositiveExamples
+                   << " of " << count << " examples" );
+        }
+
+        for ( int j = 0 ; j < fixedPositiveExamples ; j++ )
+          positive.add_reference ( classno, base_nonconst[classno][j] );
+
+        for ( int j = fixedPositiveExamples ; j < count ; j++ )
+          negative.add_reference ( classno, base_nonconst[classno][j] );
+      }
+
+    };
+
+    static void selectClasses ( const std::set<int> & classnos, const F & base, F & positive, F & negative )
+    {
+      F & base_nonconst = const_cast< F & > ( base );
+
+      std::vector<int> classes;
+      base.getClasses ( classes );
+
+      for ( std::set<int>::const_iterator i = classnos.begin();
+            i != classnos.end() ;
+            i++ )
+      {
+        int classno = *i;
+        int count = base_nonconst[classno].size();
+        for ( int j = 0 ; j < count ; j++ )
+          positive.add_reference ( classno, base_nonconst[classno][j] );
+      }
+
+      for ( std::vector<int>::const_iterator i = classes.begin();
+            i != classes.end() ;
+            i++ )
+      {
+        int classno = *i;
+        if ( classnos.find ( classno ) != classnos.end() ) continue;
+        int count = base_nonconst[classno].size();
+        for ( int j = 0 ; j < count ; j++ )
+          negative.add_reference ( classno, base_nonconst[classno][j] );
+      }
+
+    };
 
 };
 

+ 65 - 24
cbaselib/LocalizationResult.cpp

@@ -16,6 +16,13 @@
 #include "vislearning/cbaselib/LocalizationResult.h"
 #include "core/basics/StringTools.h"
 
+// use this macro to show labeled images
+#undef DEBUG_LOCALIZATIONREAD
+
+#ifdef DEBUG_LOCALIZATIONREAD
+#include <core/imagedisplay/ImageDisplay.h>
+#endif
+
 using namespace OBJREC;
 
 using namespace std;
@@ -141,10 +148,10 @@ LocalizationResult::~LocalizationResult ()
 	delete slr;
     }
 }
-#undef DEBUG_LOCALIZATIONREAD
 LocalizationResult::LocalizationResult ( const ClassNames *_cn, const NICE::Image & img, int classno ) : cn(_cn)
 {
-     const int t = 200; // FIXME
+     // FIXME: just a bad predefined threshold !
+     const int t = 200; 
      NICE::Region reg;
 
 #ifdef DEBUG_LOCALIZATIONREAD
@@ -158,8 +165,6 @@ LocalizationResult::LocalizationResult ( const ClassNames *_cn, const NICE::Imag
      for ( int y = 0 ; y < img.height(); y++ )
 	 for ( int x = 0 ; x < img.width(); x++ )
 	 {
-	     // refactor-nice.pl: check this substitution
-	     // old: if ( GetVal(img, x, y) < t )
 	     if ( img.getPixel(x,y) < t )
 	     {
 #ifdef DEBUG_LOCALIZATIONREAD
@@ -191,33 +196,69 @@ LocalizationResult::LocalizationResult ( const ClassNames *_cn, const NICE::Colo
      NICE::Image imgo (xsize,ysize);
      imgo.set(0);
 #endif
-     
-     for ( int y = 0 ; y < ysize ; y++ )
-		 for ( int x = 0 ; x < xsize ; x++ )
-		 {
-			 int r = img.getPixel(x,y,0);
-			 int g = img.getPixel(x,y,1);
-			 int b = img.getPixel(x,y,2);
 
-			 int classno;
-
-			 _cn->getClassnoFromColor ( classno, r, g, b );
-
-			 if ( classno >= 0 )
-			regions[classno].add(x,y);
-			#ifdef DEBUG_LOCALIZATIONREAD
-			imgo.setPixel(x,y,classno);
-			#endif
-		 }
+    
+     for ( int y = 0 ; y < ysize ; y++ )
+     {
+       int xstart = 0;   
+       // RGB values of the current pixel
+       int r = img.getPixel(0,y,0);
+       int g = img.getPixel(0,y,1);
+       int b = img.getPixel(0,y,2);
+
+       for ( int x = 0 ; x < xsize ; x++ )
+       {
+         int r_next, g_next, b_next;
+         if ( x != xsize - 1 ) {
+           r_next = img.getPixel(x,y,0);
+           g_next = img.getPixel(x,y,1);
+           b_next = img.getPixel(x,y,2);
+         } else {
+           // at the border of the image, we should
+           // always have a color change to add the last
+           // line segment
+           r_next = -1;
+           g_next = -1;
+           b_next = -1;
+         }
+
+         // now the RGB color changes and we have an object boundary
+         // therefore we have to add a line segment
+         if ( r != r_next || g != g_next || b != b_next )
+         {
+           int classno;
+           // look up class number for the label color
+           _cn->getClassnoFromColor ( classno, r, g, b );
+           
+           if ( classno >= 0 ) {
+             // add line segment as an rectangular region
+             regions[classno].add( xstart, y, x, y );
+             
+        #ifdef DEBUG_LOCALIZATIONREAD
+             for ( int z = xstart ; z <= x ; z++ )
+               imgo.setPixel(z,y,classno);
+        #endif
+             xstart = x+1;
+           }
+         }
+
+        r = r_next;
+        g = g_next;
+        b = b_next;
+       }
+     }
 
+     #ifdef DEBUG_LOCALIZATIONREAD
+     showImageOverlay(imgo, imgo);
+     #endif 
 
      for ( map<int, NICE::Region>::const_iterator j  = regions.begin();
 					    j != regions.end();
 					    j++ )
      {
-	 int classno = j->first;
-	 ClassificationResult *r = new ClassificationResult (classno, 1.0, _cn->getMaxClassno());
-	 push_back ( new SingleLocalizationResult ( r, j->second ) );
+    	 int classno = j->first;
+    	 ClassificationResult *r = new ClassificationResult (classno, 1.0, _cn->getMaxClassno());
+    	 push_back ( new SingleLocalizationResult ( r, j->second ) );
      }
 
      hasLabeledImage = false;

+ 4 - 0
cbaselib/LocalizationResult.h

@@ -71,6 +71,10 @@ class LocalizationResult : public std::vector<SingleLocalizationResult *>, publi
 	NICE::Image *labeledImage;
 	
     public:
+
+  typedef std::vector<SingleLocalizationResult *>::iterator iterator;
+  typedef std::vector<SingleLocalizationResult *>::const_iterator const_iterator;
+
 	bool hasLabeledImage;
 	int xsize;
 	int ysize;

+ 28 - 25
cbaselib/MultiDataset.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file MultiDataset.h
 * @brief multiple datasets
 * @author Erik Rodner
@@ -27,30 +27,33 @@ namespace OBJREC {
 class MultiDataset
 {
 
-    protected:
-	LabeledFileList lfl;
-	std::map<std::string, ClassNames> classnames;
-	std::map<std::string, LabeledSet> datasets;
-
-	void selectExamples ( const std::string & examples_command,
-		      const LabeledSet & base,
-		      LabeledSet & positives,
-		      LabeledSet & negatives,
-		      const ClassNames & cn ) const;
-
-    public:
-  
-	/** simple constructor */
-	MultiDataset( const NICE::Config *conf );
-      
-	/** simple destructor */
-	virtual ~MultiDataset();
-    
-	const ClassNames & getClassNames ( const std::string & key ) const;
-	
-	const LabeledSet * operator[] ( const std::string & key ) const;
-
-	const LabeledSet * at ( const std::string & key ) const;
+protected:
+    LabeledFileList lfl;
+    std::map<std::string, ClassNames> classnames;
+    std::map<std::string, LabeledSet> datasets;
+
+    void selectExamples ( const std::string & examples_command,
+                          const LabeledSet & base,
+                          LabeledSet & positives,
+                          LabeledSet & negatives,
+                          const ClassNames & cn ) const;
+
+public:
+
+    /** simple constructor */
+    MultiDataset( const NICE::Config *conf );
+
+    /** simple destructor */
+    virtual ~MultiDataset();
+
+    /** access class information, e.g., md.getClassNames("train") */
+    const ClassNames & getClassNames ( const std::string & key ) const;
+
+    /** access stored dataset by name, e.g., md["train"], if you have a [train] section
+      * in your config file */
+    const LabeledSet * operator[] ( const std::string & key ) const;
+
+    const LabeledSet * at ( const std::string & key ) const;
 
 };
 

+ 20 - 20
cbaselib/Polygon.h

@@ -11,31 +11,31 @@
 #include "core/image/CoordT.h"
 #include <list>
 
-using namespace NICE;
 
-typedef std::list< CoordT< int > > PointsList;
+typedef std::list< NICE::CoordT< int > > PointsList;
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 //! \brief Contains category ID and point list of the polygon
 class Polygon
 {
-public:
-	Polygon();
-	Polygon(const Polygon &copy);
-	~Polygon();
-	
-	void push(const CoordT< int > &aPoint);
-	void push(const int &x, const int &y);
-	void setID(const int &anID);
-	
-	const PointsList * points() const;
-	CoordT< int > pop();
-	int id() const;
-	
-private:
-	PointsList points_;
-	int id_;
+  public:
+    Polygon();
+    Polygon ( const Polygon &copy );
+    ~Polygon();
+
+    void push ( const NICE::CoordT< int > &aPoint );
+    void push ( const int &x, const int &y );
+    void setID ( const int &anID );
+
+    const PointsList * points() const;
+    NICE::CoordT< int > pop();
+    int id() const;
+
+  private:
+    PointsList points_;
+    int id_;
 };
 
 } //namespace
@@ -43,5 +43,5 @@ private:
 #endif /* __POLYGON_H__ */
 
 /*
- * 
+ *
  */

+ 28 - 27
cbaselib/progs/statisticsLabeledSetVector.cpp

@@ -6,47 +6,48 @@
 
 using namespace std;
 using namespace OBJREC;
+using namespace NICE;
 
 int main ( int argc, char **argv )
 {
 
-    Config conf ( argc, argv );
+  Config conf ( argc, argv );
 
-    string setfn = conf.gS("main", "set", "train.vec" );
-    int format = conf.gI("main", "format", 2 );
+  string setfn = conf.gS ( "main", "set", "train.vec" );
+  int format = conf.gI ( "main", "format", 2 );
 
-    LabeledSetVector set;
+  LabeledSetVector set;
 
-    set.read ( setfn, format );
+  set.read ( setfn, format );
 
-    set.printInformation();
+  set.printInformation();
 
-    double maximum_value = - numeric_limits<double>::max();
-    double minimum_value = numeric_limits<double>::max();
-    double maximum_norm = 0;
-    double minimum_norm = numeric_limits<double>::max();
+  double maximum_value = - numeric_limits<double>::max();
+  double minimum_value = numeric_limits<double>::max();
+  double maximum_norm = 0;
+  double minimum_norm = numeric_limits<double>::max();
 
-    LOOP_ALL(set)
-    {
-	EACH(classno, x);
+  LOOP_ALL ( set )
+  {
+    EACH ( classno, x );
 
-	if ( x.Max() > maximum_value ) 
-	    maximum_value = x.Max();
+    if ( x.Max() > maximum_value )
+      maximum_value = x.Max();
 
-	if ( x.Min() < minimum_value ) 
-	    minimum_value = x.Min();
+    if ( x.Min() < minimum_value )
+      minimum_value = x.Min();
 
-	if ( x.normL2() > maximum_norm )
-	    maximum_norm = x.normL2();
+    if ( x.normL2() > maximum_norm )
+      maximum_norm = x.normL2();
 
-	if ( x.normL2() < minimum_norm )
-	    minimum_norm = x.normL2();
+    if ( x.normL2() < minimum_norm )
+      minimum_norm = x.normL2();
 
-    }
+  }
 
-    fprintf (stderr, "min value: %f\n", minimum_value );
-    fprintf (stderr, "max value: %f\n", maximum_value );
-    fprintf (stderr, "min L2-norm: %f\n", minimum_norm );
-    fprintf (stderr, "max L2-norm: %f\n", maximum_norm );
-    fprintf (stderr, "dimension: %d\n", set.dimension() );
+  fprintf ( stderr, "min value: %f\n", minimum_value );
+  fprintf ( stderr, "max value: %f\n", maximum_value );
+  fprintf ( stderr, "min L2-norm: %f\n", minimum_norm );
+  fprintf ( stderr, "max L2-norm: %f\n", maximum_norm );
+  fprintf ( stderr, "dimension: %d\n", set.dimension() );
 }

+ 49 - 47
cbaselib/progs/testCachedExample.cpp

@@ -1,9 +1,8 @@
-/** 
+/**
 * @file testCachedExample.cpp
 * @brief test cached example implementation
 * @author Erik Rodner
 * @date 09/12/2008
-
 */
 
 #include <core/imagedisplay/ImageDisplay.h>
@@ -19,61 +18,64 @@ using namespace NICE;
 using namespace std;
 
 
-int main (int argc, char **argv)
-{   
-    std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
+int main ( int argc, char **argv )
+{
+  std::set_terminate ( __gnu_cxx::__verbose_terminate_handler );
 
-    char configfile [300];
+  char configfile [300];
 
-    struct CmdLineOption options[] = {
-	{"config", "use config file", NULL, "%s", configfile},
-	{NULL, NULL, NULL, NULL, NULL} 
-    };
-    int ret;
-    char *more_options[argc];
-    ret = parse_arguments( argc, (const char**)argv, options, more_options);
+  struct CmdLineOption options[] = {
+    {"config", "use config file", NULL, "%s", configfile},
+    {NULL, NULL, NULL, NULL, NULL}
+  };
+  int ret;
+  char *more_options[argc];
+  ret = parse_arguments ( argc, ( const char** ) argv, options, more_options );
 
-    if ( ret != 0 )
-    {
-	if ( ret != 1 ) fprintf (stderr, "Error parsing command line !\n");
-	exit (-1);
-    }
+  if ( ret != 0 )
+  {
+    if ( ret != 1 ) fprintf ( stderr, "Error parsing command line !\n" );
+    exit ( -1 );
+  }
 
-    Config conf ( configfile );
-    
-    int i = 0;
-    while ( more_options[i] != NULL )
-    {
+  Config conf ( configfile );
 
-	std::string filename ( more_options[i] );
-	fprintf (stderr, "Filename: %s\n", filename.c_str() );
-	CachedExample ce ( filename );
+  int i = 0;
+  while ( more_options[i] != NULL )
+  {
 
-	NICE::MultiChannelImageT<int> & img = ce.getIChannel(CachedExample::I_COLOR);
-	NICE::MultiChannelImageT<double> & imgc = ce.getDChannel(CachedExample::D_INTEGRALCOLOR);
+    std::string filename ( more_options[i] );
+    fprintf ( stderr, "Filename: %s\n", filename.c_str() );
+    CachedExample ce ( filename );
 
-	imgc.reInitFrom ( img, true );
-	for ( uint j = 0 ; j < img.numChannels; j++ )
-	    GenericImageTools::calcIntegralImage ( imgc.data[j], img.data[j], img.xsize, img.ysize );
+    NICE::MultiChannelImageT<int> & img = ce.getIChannel ( CachedExample::I_COLOR );
+    NICE::MultiChannelImageT<double> & imgc = ce.getDChannel ( CachedExample::D_INTEGRALCOLOR );
+
+    imgc.reInitFrom ( img );
+    for ( uint j = 0 ; j < img.channels(); j++ )
+    {
+      ImageT<double> tmp = imgc[j];
+      GenericImageTools::calcIntegralImage ( tmp, img[j], img.width(), img.height() );
+    }
 
-	Image visimg = imgc.getChannel(0);
-	showImage(visimg);
+    Image visimg = imgc.getChannel ( 0 );
+    showImage ( visimg );
 
-	ce.dropPreCached();
+    ce.dropPreCached();
 
 #ifndef NOVISUAL
-	getchar();
+    getchar();
 #endif
-	
-	imgc = ce.getDChannel ( CachedExample::D_INTEGRALCOLOR );
-	
-	visimg = imgc.getChannel(0);
-	showImage(visimg);
-	
-
-	i++;
-    }
-    
-    
-    return 0;
+
+    imgc = ce.getDChannel ( CachedExample::D_INTEGRALCOLOR );
+
+    visimg = imgc.getChannel ( 0 );
+    showImage ( visimg );
+
+
+    i++;
+  }
+
+
+  return 0;
 }

+ 51 - 57
cbaselib/progs/testLabeledSet.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file testLabeledSet.cpp
 * @brief test multidataset
 * @author Erik Rodner
@@ -15,65 +15,59 @@
 #include <vislearning/cbaselib/MultiDataset.h>
 
 using namespace OBJREC;
-
-
-
-// refactor-nice.pl: check this substitution
-// old: using namespace ice;
 using namespace NICE;
 using namespace std;
 
 
-/** 
-    
-    test multidataset 
-    
+/**
+
+    test multidataset
+
 */
-int main (int argc, char **argv)
-{   
-    std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
-
-    char configfile [300];
-
-    struct CmdLineOption options[] = {
-	{"config", "use config file", NULL, "%s", configfile},
-	{NULL, NULL, NULL, NULL, NULL} 
-    };
-    int ret;
-    char *more_options[argc];
-    ret = parse_arguments( argc, (const char**)argv, options, more_options);
-
-    if ( ret != 0 )
-    {
-	if ( ret != 1 ) fprintf (stderr, "Error parsing command line !\n");
-	exit (-1);
-    }
-
-    Config conf ( configfile );
-    
-    
-    MultiDataset md ( &conf );
-
-    const LabeledSet *train = md["train"];
-    const LabeledSet *test = md["test"];
-    const ClassNames & cn = md.getClassNames ( "train" );
-    
-    
-    fprintf (stderr, "Training Dataset\n");
-    LOOP_ALL_S( *train )
-    {
-	EACH_S(classno, fn);
-	fprintf (stderr, "%s %s\n", cn.text(classno).c_str(), fn.c_str() );
-    }
- 
-    fprintf (stderr, "Test Dataset\n");
-    LOOP_ALL_S( *test )
-    {
-	EACH_S(classno, fn);
-	fprintf (stderr, "%s %s\n", cn.text(classno).c_str(), fn.c_str() );
-    }
-   
-    
-    
-    return 0;
+int main ( int argc, char **argv )
+{
+  std::set_terminate ( __gnu_cxx::__verbose_terminate_handler );
+
+  char configfile [300];
+
+  struct CmdLineOption options[] = {
+    {"config", "use config file", NULL, "%s", configfile},
+    {NULL, NULL, NULL, NULL, NULL}
+  };
+  int ret;
+  char *more_options[argc];
+  ret = parse_arguments ( argc, ( const char** ) argv, options, more_options );
+
+  if ( ret != 0 )
+  {
+    if ( ret != 1 ) fprintf ( stderr, "Error parsing command line !\n" );
+    exit ( -1 );
+  }
+
+  Config conf ( configfile );
+
+  MultiDataset md ( &conf );
+
+  const LabeledSet *train = md["train"];
+  const LabeledSet *test = md["test"];
+  const ClassNames & cn = md.getClassNames ( "train" );
+
+
+  fprintf ( stderr, "Training Dataset\n" );
+  LOOP_ALL_S ( *train )
+  {
+    EACH_S ( classno, fn );
+    fprintf ( stderr, "%s %s\n", cn.text ( classno ).c_str(), fn.c_str() );
+  }
+
+  fprintf ( stderr, "Test Dataset\n" );
+  LOOP_ALL_S ( *test )
+  {
+    EACH_S ( classno, fn );
+    fprintf ( stderr, "%s %s\n", cn.text ( classno ).c_str(), fn.c_str() );
+  }
+
+
+
+  return 0;
 }

+ 58 - 52
classifier/classifierbase/KernelClassifier.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file KernelClassifier.h
 * @brief classifier interface for kernel based methods
 * @author Erik Rodner
@@ -16,78 +16,84 @@
 #include "vislearning/cbaselib/LabeledSet.h"
 #include "vislearning/classifier/classifierbase/VecClassifier.h"
 
-namespace OBJREC {
-  
+namespace OBJREC
+{
+
 /** classifier interface for kernel based methods */
 class KernelClassifier : public VecClassifier
 {
-	public:
-		enum {
-			KERNELCLASSIFIER_NORMALIZATION_EUCLIDEAN = 0,
-			KERNELCLASSIFIER_NORMALIZATION_NONE
-		};
+  public:
+    enum
+    {
+      KERNELCLASSIFIER_NORMALIZATION_EUCLIDEAN = 0,
+      KERNELCLASSIFIER_NORMALIZATION_NONE
+    };
+
+  protected:
+
+    /** This variable might be NULL, if you do not specify a kernel function */
+    Kernel *kernelFunction;
+
+    /** This is the training set, if you specify a kernel function */
+    NICE::VVector vecSet;
+
+    /** These are the labels of the training set, if you specify a kernel function */
+    NICE::Vector vecSetLabels;
 
-    protected:
+    /** Maybe you want to normalize feature vectors before training */
+    int normalizationType;
 
-		/** This variable might be NULL, if you do not specify a kernel function */
-		Kernel *kernelFunction;
-		
-		/** This is the training set, if you specify a kernel function */
-		NICE::VVector vecSet;
+    /** stored config to initialize KernelData with noiseSigma, cholesky method etc. */
+    NICE::Config conf;
 
-		/** These are the labels of the training set, if you specify a kernel function */
-		NICE::Vector vecSetLabels;
+  public:
+    /** simple constructor */
+    KernelClassifier() {};
 
-		/** Maybe you want to normalize feature vectors before training */
-		int normalizationType;
+    /** specify a kernel function which works on vectors and a normalization method ( use the enum defined in KernelClassifier ) */
+    KernelClassifier ( const NICE::Config *conf, Kernel *kernelFunction = NULL, int normalizationType = KERNELCLASSIFIER_NORMALIZATION_EUCLIDEAN );
 
-		/** stored config to initialize KernelData with noiseSigma, cholesky method etc. */
-		NICE::Config conf;
+    /** copy constructor which you should also call in subclasses */
+    KernelClassifier ( const KernelClassifier & src );
 
-    public:
-  		/** simple constructor */
-		KernelClassifier(){};
-	    
-		/** specify a kernel function which works on vectors and a normalization method ( use the enum defined in KernelClassifier ) */
-		KernelClassifier( const NICE::Config *conf, Kernel *kernelFunction = NULL, int normalizationType = KERNELCLASSIFIER_NORMALIZATION_EUCLIDEAN );
+    /** simple destructor */
+    virtual ~KernelClassifier();
 
-		/** copy constructor which you should also call in subclasses */
-		KernelClassifier ( const KernelClassifier & src );
 
-		/** simple destructor */
-		virtual ~KernelClassifier();
+    // interface function
 
+    /** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
+    virtual void teach ( KernelData *kernelData, const NICE::Vector & y ) = 0;
 
-		// interface function
+    /** classify an example by using its kernel values with the training set,
+     be careful with the order in @param kernelVector */
+    virtual ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const = 0;
 
-		/** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
-		virtual void teach ( KernelData *kernelData, const NICE::Vector & y ) = 0;
 
-		/** classify an example by using its kernel values with the training set,
-			be careful with the order in @param kernelVector */
-		virtual ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const = 0;
+    // functions to build an interface to VecClassifier
 
+    /** classify using simple vector, this works only if you specify a kernel function */
+    ClassificationResult classify ( const NICE::Vector & x ) const;
 
-		// functions to build an interface to VecClassifier
+    /** teach classifier with a labeled set of feature vectors, this works only if you specify a kernel function */
+    virtual void teach ( const LabeledSetVector & teachSet );
 
-		/** classify using simple vector, this works only if you specify a kernel function */
-		ClassificationResult classify ( const NICE::Vector & x ) const;
+    /** calculate classifier stuff as the last training step, pretty useless, deprecated */
+    void finishTeaching() {};
 
-		/** teach classifier with a labeled set of feature vectors, this works only if you specify a kernel function */
-		virtual void teach ( const LabeledSetVector & teachSet );
-		
-		/** calculate classifier stuff as the last training step, pretty useless, deprecated */
-		void finishTeaching() {};
+    /** clone this object */
+    KernelClassifier *clone ( void ) const
+    {
+      fthrow ( NICE::Exception, "clone() not yet implemented." );
+    }
 
-		/** clone this object */
-		KernelClassifier *clone(void) const {
-			fthrow(Exception, "clone() not yet implemented.");
-		}
+    Kernel *getKernelFunction () const
+    {
+      return kernelFunction;
+    };
 
-		Kernel *getKernelFunction () const { return kernelFunction; }; 
-		
-		virtual void restore(std::istream&, int);
-		virtual void store(std::ostream&, int) const;
+    virtual void restore ( std::istream&, int );
+    virtual void store ( std::ostream&, int ) const;
 };
 
 }

+ 31 - 24
classifier/classifierbase/VecClassifier.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file VecClassifier.h
 * @brief Simple classification interface
 * @author Erik Rodner
@@ -14,41 +14,48 @@
 #include "vislearning/cbaselib/LabeledSet.h"
 #include "vislearning/cbaselib/ClassificationResult.h"
 
-#define ROADWORKS fthrow(Exception, "clone(): not yet implemented!");
+#define ROADWORKS fthrow(NICE::Exception, "clone(): not yet implemented!");
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 /** Simple classification interface */
 class VecClassifier : public NICE::Persistent
 {
-    protected:
-		int maxClassNo;
+  protected:
+    int maxClassNo;
+
+  public:
+
+    VecClassifier()
+    {
+      maxClassNo = 0;
+    };
+
+    /** simple constructor */
+    VecClassifier ( const NICE::Config *conf );
 
-    public:
- 
-		VecClassifier() { maxClassNo = 0; };
+    /** simple destructor */
+    virtual ~VecClassifier();
 
-		/** simple constructor */
-		VecClassifier( const NICE::Config *conf );
+    virtual void setMaxClassNo ( int maxClassNo );
 
-		/** simple destructor */
-		virtual ~VecClassifier();
+    virtual int getMaxClassNo () const;
 
-		virtual void setMaxClassNo ( int maxClassNo );
-		
-		virtual int getMaxClassNo () const;
+    /** classify using simple vector */
+    virtual ClassificationResult classify ( const NICE::Vector & x ) const = 0;
 
-		/** classify using simple vector */
-		virtual ClassificationResult classify ( const NICE::Vector & x ) const = 0;
+    /** teach classifier with a labeled set of feature vectors */
+    virtual void teach ( const LabeledSetVector & teachSet ) = 0;
 
-		/** teach classifier with a labeled set of feature vectors */
-		virtual void teach ( const LabeledSetVector & teachSet ) = 0;
-		
-		/** calculate classifier stuff as the last training step */
-		virtual void finishTeaching() = 0;
+    /** calculate classifier stuff as the last training step */
+    virtual void finishTeaching() = 0;
 
-		/** clone this object */
-		virtual VecClassifier *clone(void) const { ROADWORKS; };
+    /** clone this object */
+    virtual VecClassifier *clone ( void ) const
+    {
+      ROADWORKS;
+    };
 };
 
 #undef ROADWORKS

+ 2 - 0
classifier/classifiercombination/VCPreRandomForest.cpp

@@ -12,6 +12,8 @@
 
 #include <vislearning/cbaselib/VectorFeature.h>
 
+#include "core/image/ImageT.h"
+//#include "core/imagedisplay/ImageDisplay.h"
 
 using namespace OBJREC;
 using namespace std;

+ 0 - 2
classifier/classifiercombination/VCPreRandomForest.h

@@ -9,8 +9,6 @@
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
 
 #include <map>
 

+ 2 - 0
classifier/classifierinterfaces/VCFeaturePool.cpp

@@ -9,6 +9,8 @@
 
 #include "VCFeaturePool.h"
 #include "vislearning/cbaselib/VectorFeature.h"
+#include "core/image/ImageT.h"
+//#include "core/imagedisplay/ImageDisplay.h"
 
 using namespace OBJREC;
 

+ 0 - 2
classifier/classifierinterfaces/VCFeaturePool.h

@@ -10,8 +10,6 @@
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
 
 #include <string>
 

+ 94 - 91
classifier/fpclassifier/boosting/FPCBoosting.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file FPCBoosting.h
 * @brief implementation of boosting algorithms
 * @author Erik Rodner
@@ -16,102 +16,105 @@
 #include "vislearning/cbaselib/FeaturePool.h"
 #include "core/basics/triplet.h"
 
-
-
-namespace OBJREC {
+namespace OBJREC
+{
 
 /** @brief a strong classifier is a collection of weighted classifiers: \f$a \cdot h_t(\mathbf{x}) + b\f$ */
-class StrongClassifier : public std::vector< triplet<double, double, FeaturePoolClassifier *> >
-{};
+class StrongClassifier : public std::vector< NICE::triplet<double, double, FeaturePoolClassifier *> >
+  {};
 
 /** @brief implementation of boosting algorithms */
 class FPCBoosting : public FeaturePoolClassifier
 {
-    protected:
-	const NICE::Config *conf;
-
-	/** @brief normalize weights for each class independently */
-	bool classwise_normalization;
-
-	/** @brief boosting method ( select one value from the enum-type ) */
-	int boosting_method;
-
-	/** @brief class no corresponding to the positive class */
-	int positive_class;
-
-	/** @brief maximum number of rounds */
-	int maxRounds;
-
-	/** @brief memory efficiency by caching and storing of features on the hard disc */
-	bool memory_efficient;
-
-	/** @brief prototype of a weak classifier
-	    
-	    The generation of a new weak classifier is done by the clone method
-	    of this object.
-	*/
-	FeaturePoolClassifier *weakClassifier;
-
-	/** @brief final strong classifier */
-	StrongClassifier strongClassifier;
-
-	/** @brief perform boosting and build strongClassifier 
-	    @param featureStorage pre calculated features
-	    @param fp pool of features
-	    @param examples training examples */
-	void boosting ( const FeatureStorage & featureStorage,
-			FeaturePool & fp,
-			Examples & examples );
-
-	/** @brief normalize weights of examples
-	    @param examples training examples
-	*/
-	void normalizeWeights ( Examples & examples ) const;
-
-    public:
-	
-	enum {
-		BOOSTINGMETHOD_ADABOOST = 0,
-		BOOSTINGMETHOD_REAL_ADABOOST,
-		BOOSTINGMETHOD_GENTLEBOOST
-	};
-
-	/** @brief for cloning only */
-	FPCBoosting() {};
-
-	/** @brief constructor for training */
-	FPCBoosting( const NICE::Config *conf, 
-		  // refactor-nice.pl: check this substitution
-		  // old: string section = "Boost" );
-		  std::string section = "Boost" );
-    
-	/** @brief simple destructor */
-	virtual ~FPCBoosting();
-
-	/** @brief classify an unseen example */
-	ClassificationResult classify ( Example & pce );
-	
-	/** @brief train this classifier 
-	    @param fp pool of features
-	    @param examples training examples
-	*/
-	virtual void train ( FeaturePool & fp,
-		     Examples & examples );
-
-	/** @{ methods for persistency */
-	void restore (std::istream & is, int format = 0);
-	void store (std::ostream & os, int format = 0) const;
-	void clear ();
-	/** @} */
-
-	/** @brief creates a copy of this object */
-	FeaturePoolClassifier *clone () const;
-
-	/** @brief direct access to the classifier parameters */
-	StrongClassifier & getStrongClassifier () { return strongClassifier; };
-
-	/** @brief sets the maximum number of rounds */
-	void setComplexity ( int size );
+  protected:
+    const NICE::Config *conf;
+
+    /** @brief normalize weights for each class independently */
+    bool classwise_normalization;
+
+    /** @brief boosting method ( select one value from the enum-type ) */
+    int boosting_method;
+
+    /** @brief class no corresponding to the positive class */
+    int positive_class;
+
+    /** @brief maximum number of rounds */
+    int maxRounds;
+
+    /** @brief memory efficiency by caching and storing of features on the hard disc */
+    bool memory_efficient;
+
+    /** @brief prototype of a weak classifier
+
+        The generation of a new weak classifier is done by the clone method
+        of this object.
+    */
+    FeaturePoolClassifier *weakClassifier;
+
+    /** @brief final strong classifier */
+    StrongClassifier strongClassifier;
+
+    /** @brief perform boosting and build strongClassifier
+        @param featureStorage pre calculated features
+        @param fp pool of features
+        @param examples training examples */
+    void boosting ( const FeatureStorage & featureStorage,
+                    FeaturePool & fp,
+                    Examples & examples );
+
+    /** @brief normalize weights of examples
+        @param examples training examples
+    */
+    void normalizeWeights ( Examples & examples ) const;
+
+  public:
+
+    enum
+    {
+      BOOSTINGMETHOD_ADABOOST = 0,
+      BOOSTINGMETHOD_REAL_ADABOOST,
+      BOOSTINGMETHOD_GENTLEBOOST
+    };
+
+    /** @brief for cloning only */
+    FPCBoosting() {};
+
+    /** @brief constructor for training */
+    FPCBoosting ( const NICE::Config *conf,
+                  // refactor-nice.pl: check this substitution
+                  // old: string section = "Boost" );
+                  std::string section = "Boost" );
+
+    /** @brief simple destructor */
+    virtual ~FPCBoosting();
+
+    /** @brief classify an unseen example */
+    ClassificationResult classify ( Example & pce );
+
+    /** @brief train this classifier
+        @param fp pool of features
+        @param examples training examples
+    */
+    virtual void train ( FeaturePool & fp,
+                         Examples & examples );
+
+    /** @{ methods for persistency */
+    void restore ( std::istream & is, int format = 0 );
+    void store ( std::ostream & os, int format = 0 ) const;
+    void clear ();
+    /** @} */
+
+    /** @brief creates a copy of this object */
+    FeaturePoolClassifier *clone () const;
+
+    /** @brief direct access to the classifier parameters */
+    StrongClassifier & getStrongClassifier ()
+    {
+      return strongClassifier;
+    };
+
+    /** @brief sets the maximum number of rounds */
+    void setComplexity ( int size );
 };
 
 

+ 3 - 0
classifier/fpclassifier/logisticregression/FPCSMLR.cpp

@@ -1,6 +1,9 @@
 #include "vislearning/classifier/fpclassifier/logisticregression/FPCSMLR.h"
 #include "vislearning/cbaselib/FeaturePool.h"
 
+#include "core/image/ImageT.h"
+//#include "core/imagedisplay/ImageDisplay.h"
+
 #include <iostream>
 
 using namespace OBJREC;

+ 68 - 69
classifier/fpclassifier/logisticregression/FPCSMLR.h

@@ -1,4 +1,4 @@
-/** 
+/**
  * @file FPCSMLR.h
  * @brief implementation of Sparse Multinomial Logistic Regression (SMLR) Classififier, it uses a SLR for each class and combines the results
  * @author Björn Fröhlich
@@ -10,83 +10,82 @@
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
 
 #include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
 #include "vislearning/classifier/fpclassifier/logisticregression/SLR.h"
 #include "vislearning/cbaselib/FeaturePool.h"
 #include "core/algebra/GMSparseVectorMatrix.h"
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 class FPCSMLR : public FeaturePoolClassifier
 {
-    protected:
-	//! the configuration file
-	const NICE::Config *conf;
-
-	//! section in the configfile
-	std::string confsection;
-	
-	//! the featurepool
-	FeaturePool fp;
-	
-	//! the one vs all sparse logistic classifiers
-	std::vector<SLR> classifiers;
-	
-	//! just use the features from pictures, which the class contains
-	bool inpic;
-		
-    public:
-	/**
-	 * standard constructor
-	 * @param conf configfile
-	 * @param section section name in configfile for classifier
-	 */
-	FPCSMLR( const NICE::Config *conf, std::string section="SMLR");
-      
-	
-	/**
-	 * simple constructor -> does nothing
-	 */
-	FPCSMLR ();
-
-	/**
-	 * simple destructor
-	 */
-	~FPCSMLR();
-
-	/**
-	 * main classification function
-	 * @param pce input feature
-	 * @return a classification result
-	 */
-	ClassificationResult classify ( Example & pce );
-
-	/**
-	 * start training
-	 * @param fp a featurepool (how to handle which features...)
-	 * @param examples input features
-	 */
-	void train ( FeaturePool & _fp, Examples & examples );
-
-	/**
-	 * clone this object
-	 * @return a copy of this object
-	 */
-	FeaturePoolClassifier *clone () const;
-
-	/**
-	 * set complexity for the next training process e.g. number of weak classifiers
-	 * @param size new complexity
-	 */
-	void setComplexity ( int size );
-
-	/** IO functions */
-	void restore (std::istream & is, int format = 0);
-	void store (std::ostream & os, int format = 0) const;
-	void clear ();
+  protected:
+    //! the configuration file
+    const NICE::Config *conf;
+
+    //! section in the configfile
+    std::string confsection;
+
+    //! the featurepool
+    FeaturePool fp;
+
+    //! the one vs all sparse logistic classifiers
+    std::vector<SLR> classifiers;
+
+    //! just use the features from pictures, which the class contains
+    bool inpic;
+
+  public:
+    /**
+     * standard constructor
+     * @param conf configfile
+     * @param section section name in configfile for classifier
+     */
+    FPCSMLR ( const NICE::Config *conf, std::string section="SMLR" );
+
+
+    /**
+     * simple constructor -> does nothing
+     */
+    FPCSMLR ();
+
+    /**
+     * simple destructor
+     */
+    ~FPCSMLR();
+
+    /**
+     * main classification function
+     * @param pce input feature
+     * @return a classification result
+     */
+    ClassificationResult classify ( Example & pce );
+
+    /**
+     * start training
+     * @param fp a featurepool (how to handle which features...)
+     * @param examples input features
+     */
+    void train ( FeaturePool & _fp, Examples & examples );
+
+    /**
+     * clone this object
+     * @return a copy of this object
+     */
+    FeaturePoolClassifier *clone () const;
+
+    /**
+     * set complexity for the next training process e.g. number of weak classifiers
+     * @param size new complexity
+     */
+    void setComplexity ( int size );
+
+    /** IO functions */
+    void restore ( std::istream & is, int format = 0 );
+    void store ( std::ostream & os, int format = 0 ) const;
+    void clear ();
 };
 
 } // namespace

+ 3 - 0
classifier/fpclassifier/logisticregression/SLR.cpp

@@ -5,6 +5,9 @@
 #include "vislearning/classifier/fpclassifier/logisticregression/SLR.h"
 #include "vislearning/cbaselib/FeaturePool.h"
 
+#include "core/image/ImageT.h"
+//#include "core/imagedisplay/ImageDisplay.h"
+
 #include <iostream>
 
 #define SLRDEBUG

+ 1 - 3
classifier/fpclassifier/logisticregression/SLR.h

@@ -9,8 +9,6 @@
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
 
 #include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
 #include "vislearning/cbaselib/FeaturePool.h"
@@ -29,7 +27,7 @@ class SLR : public NICE::Persistent
     std::string confsection;
 
     //! weight vectors
-    SparseVector weight;
+    NICE::SparseVector weight;
 
     //! the featurepool
     FeaturePool fp;

+ 3 - 0
classifier/fpclassifier/randomforest/DecisionNode.cpp

@@ -7,6 +7,9 @@
 */
 #include <iostream>
 
+#include "core/image/ImageT.h"
+#include "core/imagedisplay/ImageDisplay.h"
+
 #include "vislearning/classifier/fpclassifier/randomforest/DecisionNode.h"
 
 using namespace OBJREC;

+ 1 - 2
classifier/fpclassifier/randomforest/DecisionNode.h

@@ -10,8 +10,7 @@
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
+
 #include <map>
 #include <limits>
 

+ 42 - 26
classifier/fpclassifier/randomforest/FPCDecisionTree.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file FPCDecisionTree.h
 * @brief simple decision tree classifier
 * @author Erik Rodner
@@ -20,38 +20,54 @@
 #include "DecisionTree.h"
 
 #undef ROADWORKS
-#define ROADWORKS fthrow( Exception, "Persistent interface not yet implemented.");
+#define ROADWORKS fthrow( NICE::Exception, "Persistent interface not yet implemented.");
 
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 /** simple decision tree classifier */
 class FPCDecisionTree : public FeaturePoolClassifier
 {
 
-    protected:
-		const NICE::Config *conf;
-		DecisionTree *dt;
-		DecisionTreeBuilder *builder;
-
-    public:
-  
-		/** simple constructor */
-		FPCDecisionTree( const NICE::Config *conf, std::string section );
-		  
-		/** simple destructor */
-		virtual ~FPCDecisionTree();
-		 
-		virtual ClassificationResult classify ( Example & pce );
-
-		virtual void train ( FeaturePool & fp, Examples & examples );
-
-		DecisionTree & getTree () { return *dt; };
-
-		void restore (std::istream & is, int format = 0) { ROADWORKS };
-		void store (std::ostream & os, int format = 0) const { ROADWORKS };
-		void clear () { ROADWORKS };
-		FeaturePoolClassifier *clone () const { ROADWORKS };
+  protected:
+    const NICE::Config *conf;
+    DecisionTree *dt;
+    DecisionTreeBuilder *builder;
+
+  public:
+
+    /** simple constructor */
+    FPCDecisionTree ( const NICE::Config *conf, std::string section );
+
+    /** simple destructor */
+    virtual ~FPCDecisionTree();
+
+    virtual ClassificationResult classify ( Example & pce );
+
+    virtual void train ( FeaturePool & fp, Examples & examples );
+
+    DecisionTree & getTree ()
+    {
+      return *dt;
+    };
+
+    void restore ( std::istream & is, int format = 0 )
+    {
+      ROADWORKS
+    };
+    void store ( std::ostream & os, int format = 0 ) const
+    {
+      ROADWORKS
+    };
+    void clear ()
+    {
+      ROADWORKS
+    };
+    FeaturePoolClassifier *clone () const
+    {
+      ROADWORKS
+    };
 
 
 

+ 3 - 0
classifier/fpclassifier/randomforest/FPCRandomForests.cpp

@@ -12,6 +12,9 @@
 
 #include <iostream>
 
+#include "core/image/ImageT.h"
+#include "core/imagedisplay/ImageDisplay.h"
+
 #include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
 #include "vislearning/classifier/fpclassifier/randomforest/DTBStandard.h"
 #include "vislearning/classifier/fpclassifier/randomforest/DTBRandom.h"

+ 118 - 110
classifier/fpclassifier/randomforest/FPCRandomForests.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file FPCRandomForests.h
 * @brief implementation of random set forests
 * @author Erik Rodner
@@ -12,8 +12,6 @@
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
 
 #include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
 #include "vislearning/cbaselib/FeaturePool.h"
@@ -22,117 +20,127 @@
 #include "DecisionTreeBuilder.h"
 
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 /** implementation of random set forests */
 class FPCRandomForests : public FeaturePoolClassifier
 {
-    protected:
-		/** vector containing all decision trees */
-		std::vector<DecisionTree *> forest;	
-		
-		/** number of trees which will be generated in the
-		    during training */
-		int number_of_trees;
-
-		/** fraction of features used for each tree */
-		double features_per_tree;
-
-		/** fraction of training examples used for each tree */
-		double samples_per_tree;
-
-		/** use an equal number of training examples of each class
-		    to build a single tree */
-		bool use_simple_balancing;
-
-		/** weight examples according to a priori class probabilities
-		    as estimated using the distribution contained in the training data */
-		bool weight_examples;
-
-		/** if >0 then prune the trees using pruneTreeEntropy */
-		double minimum_entropy;
-
-		/** clear all examples after building a tree, this deletes
-		    all cached images contained in CachedExample etc. */
-		bool memory_efficient;
-
-		/** stored config to initialize a tree */
-		const NICE::Config *conf;
-
-		/** config section containing important config values */
-		std::string confsection;
-
-		/** pointer to the tree builder method */
-		DecisionTreeBuilder *builder;
-
-		/** out-of-bag statistics */
-		bool enableOutOfBagEstimates;
-		std::vector<std::pair<double, int> > oobResults;
-
-		/** classify using only a subset of all trees */
-		ClassificationResult classify ( Example & pce,
-							const std::vector<int> & outofbagtrees );
-
-		/** calculate out-of-bag statistics */
-		void calcOutOfBagEstimates ( std::vector< std::vector<int> > & outofbagtrees, 
-						 Examples & examples );
-		
-		/** save example selection per tree */
-		std::vector<std::vector<int> > exselection;
-
-    public:
-  
-		/** initialize the classifier */
-		FPCRandomForests( const NICE::Config *conf, 
-				  std::string section );
-		  
-		/** do nothing */
-		FPCRandomForests ();
-
-		/** simple destructor */
-		virtual ~FPCRandomForests();
-
-		/** main classification function */
-		ClassificationResult classify ( Example & pce );
-		int classify_optimize ( Example & pce );
-
-		/** get all leaf nodes for an given example (or inner nodes if depth is set to the level) */
-		void getLeafNodes ( Example & pce,
-					std::vector<DecisionNode *> & leafNodes,
-					int depth = 100000 );
-		/** get all leaf nodes (or inner nodes if depth is set to the level) */
-		void getAllLeafNodes ( std::vector<DecisionNode *> & leafNodes);
-		
-		/** perform training using a given feature pool and some training data */
-		virtual void train ( FeaturePool & fp,
-				 Examples & examples );
-
-		/** enumerate all nodes within the trees */
-		void indexDescendants ( std::map<DecisionNode *, std::pair<long, int> > & index ) const;
-
-		/** reset all counters in all nodes contained in the forest */
-		void resetCounters ();
-
-		/** direct access to all trees */
-		const std::vector<DecisionTree *> & getForest () const { return forest; };
-
-		/** direct write access to all trees */
-		std::vector<DecisionTree *> & getForestNonConst () { return forest; };
-
-		/** clone this object */
-		FeaturePoolClassifier *clone () const;
-		
-		/** get out of bag estimates */
-		std::vector<std::pair<double, int> > & getOutOfBagResults () { return oobResults; };
-
-		/** set the number of trees */
-		void setComplexity ( int size );
-
-		/** IO functions */
-		void restore (std::istream & is, int format = 0);
-		void store (std::ostream & os, int format = 0) const;
-		void clear ();
-	
+  protected:
+    /** vector containing all decision trees */
+    std::vector<DecisionTree *> forest;
+
+    /** number of trees which will be generated in the
+        during training */
+    int number_of_trees;
+
+    /** fraction of features used for each tree */
+    double features_per_tree;
+
+    /** fraction of training examples used for each tree */
+    double samples_per_tree;
+
+    /** use an equal number of training examples of each class
+        to build a single tree */
+    bool use_simple_balancing;
+
+    /** weight examples according to a priori class probabilities
+        as estimated using the distribution contained in the training data */
+    bool weight_examples;
+
+    /** if >0 then prune the trees using pruneTreeEntropy */
+    double minimum_entropy;
+
+    /** clear all examples after building a tree, this deletes
+        all cached images contained in CachedExample etc. */
+    bool memory_efficient;
+
+    /** stored config to initialize a tree */
+    const NICE::Config *conf;
+
+    /** config section containing important config values */
+    std::string confsection;
+
+    /** pointer to the tree builder method */
+    DecisionTreeBuilder *builder;
+
+    /** out-of-bag statistics */
+    bool enableOutOfBagEstimates;
+    std::vector<std::pair<double, int> > oobResults;
+
+    /** classify using only a subset of all trees */
+    ClassificationResult classify ( Example & pce,
+                                    const std::vector<int> & outofbagtrees );
+
+    /** calculate out-of-bag statistics */
+    void calcOutOfBagEstimates ( std::vector< std::vector<int> > & outofbagtrees,
+                                 Examples & examples );
+
+    /** save example selection per tree */
+    std::vector<std::vector<int> > exselection;
+
+  public:
+
+    /** initialize the classifier */
+    FPCRandomForests ( const NICE::Config *conf,
+                       std::string section );
+
+    /** do nothing */
+    FPCRandomForests ();
+
+    /** simple destructor */
+    virtual ~FPCRandomForests();
+
+    /** main classification function */
+    ClassificationResult classify ( Example & pce );
+    int classify_optimize ( Example & pce );
+
+    /** get all leaf nodes for an given example (or inner nodes if depth is set to the level) */
+    void getLeafNodes ( Example & pce,
+                        std::vector<DecisionNode *> & leafNodes,
+                        int depth = 100000 );
+    /** get all leaf nodes (or inner nodes if depth is set to the level) */
+    void getAllLeafNodes ( std::vector<DecisionNode *> & leafNodes );
+
+    /** perform training using a given feature pool and some training data */
+    virtual void train ( FeaturePool & fp,
+                         Examples & examples );
+
+    /** enumerate all nodes within the trees */
+    void indexDescendants ( std::map<DecisionNode *, std::pair<long, int> > & index ) const;
+
+    /** reset all counters in all nodes contained in the forest */
+    void resetCounters ();
+
+    /** direct access to all trees */
+    const std::vector<DecisionTree *> & getForest () const
+    {
+      return forest;
+    };
+
+    /** direct write access to all trees */
+    std::vector<DecisionTree *> & getForestNonConst ()
+    {
+      return forest;
+    };
+
+    /** clone this object */
+    FeaturePoolClassifier *clone () const;
+
+    /** get out of bag estimates */
+    std::vector<std::pair<double, int> > & getOutOfBagResults ()
+    {
+      return oobResults;
+    };
+
+    /** set the number of trees */
+    void setComplexity ( int size );
+
+    /** IO functions */
+    void restore ( std::istream & is, int format = 0 );
+    void store ( std::ostream & os, int format = 0 ) const;
+    void clear ();
+
 
 };
 

+ 18 - 16
classifier/genericClassifierSelection.h

@@ -4,6 +4,7 @@
 #include "core/basics/StringTools.h"
 
 #include "vislearning/classifier/vclassifier/VCAmitSVM.h"
+#include "vislearning/classifier/vclassifier/VCNearestClassMean.h"
 #include "vislearning/classifier/vclassifier/VCSimpleGaussian.h"
 #include "vislearning/classifier/vclassifier/VCNearestNeighbour.h"
 #include "vislearning/classifier/vclassifier/VCCrossGeneralization.h"
@@ -60,12 +61,13 @@ class GenericClassifierSelection
 
       if ( classifier_type == "amit" ) {
         classifier = new VCAmitSVM ( conf );
-
-      } else if ( classifier_type == "nn" ) {
-        classifier = new VCNearestNeighbour ( conf, new NICE::EuclidianDistance<double>() );
-#ifdef NICE_USELIB_ICE
-      } else if ( classifier_type == "gauss" ) {
-        classifier = new VCSimpleGaussian ( conf );
+     } else if ( classifier_type == "nn" ) {
+	classifier = new VCNearestNeighbour( conf, new NICE::EuclidianDistance<double>() );
+#ifdef NICE_USELIB_ICE 
+     } else if ( classifier_type == "gauss" ) {
+        classifier = new VCSimpleGaussian( conf );
+     } else if ( classifier_type == "nearest_classmean" ) {
+        classifier = new VCNearestClassMean( conf, new NICE::EuclidianDistance<double>() );
 #endif
       } else if ( classifier_type == "random_forest" ) {
         FeaturePoolClassifier *fpc = new FPCRandomForests ( conf, "RandomForest" );
@@ -107,31 +109,31 @@ class GenericClassifierSelection
       } else if ( ( classifier_type == "dtgp" ) ) {
         classifier = new VCDTSVM ( conf );
       } else if ( ( classifier_type == "minimum_enclosing_ball" ) ) {
-        string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
+        std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
         classifier = new KCMinimumEnclosingBall ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
       } else if ( ( classifier_type == "gp_one_class" ) ) {
-        string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
+        std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
         classifier = new KCGPOneClass ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
       } else if ( ( classifier_type == "gp_regression_rbf" ) ) {
-        string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
+        std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
         classifier = new KCGPRegression ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
       } else if ( ( classifier_type == "gp_laplace_rbf" ) ) {
-        string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
+        std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
         classifier = new KCGPLaplace ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
       } else if ( ( classifier_type == "gp_regression_rbf_onevsall" ) ) {
-        string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
+        std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
         classifier = new KCGPRegOneVsAll ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
       } else if ( ( classifier_type == "gp_laplace_rbf_onevsall" ) ) {
-        string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
+        std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
         classifier = new KCGPLaplaceOneVsAll ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
-      } else if ( StringTools::regexMatch ( classifier_type, "^one_vs_one\\(([^\\)]+)\\)$", submatches ) && ( submatches.size() == 2 ) ) {
+      } else if ( NICE::StringTools::regexMatch ( classifier_type, "^one_vs_one\\(([^\\)]+)\\)$", submatches ) && ( submatches.size() == 2 ) ) {
         classifier = new VCOneVsOne ( conf, selectVecClassifier ( conf, submatches[1] ) );
-      } else if ( StringTools::regexMatch ( classifier_type, "^one_vs_all\\(([^\\)]+)\\)$", submatches ) && ( submatches.size() == 2 ) ) {
+      } else if ( NICE::StringTools::regexMatch ( classifier_type, "^one_vs_all\\(([^\\)]+)\\)$", submatches ) && ( submatches.size() == 2 ) ) {
         classifier = new VCOneVsAll ( conf, selectVecClassifier ( conf, submatches[1] ) );
-      } else if ( StringTools::regexMatch ( classifier_type, "^random_forest\\(([^\\)]+)\\)$", submatches ) && ( submatches.size() == 2 ) ) {
+      } else if ( NICE::StringTools::regexMatch ( classifier_type, "^random_forest\\(([^\\)]+)\\)$", submatches ) && ( submatches.size() == 2 ) ) {
         classifier = new VCPreRandomForest ( conf, "VCPreRandomForest", selectVecClassifier ( conf, submatches[1] ) );
       } else {
-        fthrow ( Exception, "Classifier type " << classifier_type << " not (yet) supported." << endl <<
+        fthrow ( NICE::Exception, "Classifier type " << classifier_type << " not (yet) supported." << std::endl <<
                  "(genericClassifierSelection.h contains a list of classifiers to choose from)" );
       }
 

+ 71 - 67
classifier/kernelclassifier/GPLaplaceOptimizationProblem.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file GPLaplaceOptimizationProblem.h
 * @author Erik Rodner
 * @date 12/09/2009
@@ -16,8 +16,9 @@
 #include "LaplaceApproximation.h"
 #include "LikelihoodFunction.h"
 
-namespace OBJREC {
-  
+namespace OBJREC
+{
+
 /** @class GPLaplaceOptimizationProblem
  * Hyperparameter Optimization Problem for GP with Laplace Approximation
  *
@@ -26,70 +27,73 @@ namespace OBJREC {
 class GPLaplaceOptimizationProblem : public NICE::OptimizationProblemFirst
 {
 
-    protected:
-		KernelData *kernelData;
-		
-		NICE::VVector y;
-
-		double bestAvgLooError;
-		NICE::Vector bestLooParameters;
-		
-		ParameterizedKernel *kernel;
-
-		bool verbose;
-
-		const LikelihoodFunction *likelihoodFunction;
-		
-		std::vector<LaplaceApproximation *> laplaceApproximation;
-
-    public:
-  
-  
-  		/** initialize the optimization problem of laplace approximation integrated in
-		 *  GP
-		 *  @param kernelData object containing kernel matrix and other stuff
-		 *  @param y labels which have to -1 or 1
-		 *  @param kernel a parameterized kernel which provides derivations
-		 *  @param likelihoodFunction the type of the likelihood p(y_i|f_i), e.g. cumulative gaussian
-		 *  @param laplaceApproximation object containing cached matrices of the laplaceApproximation
-		 *  @param verbose print some status messages for debugging and boring work days
-		 **/
-     	GPLaplaceOptimizationProblem ( KernelData *kernelData, const NICE::Vector & y, 
-			ParameterizedKernel *kernel, const LikelihoodFunction *likelihoodFunction,
-			LaplaceApproximation *laplaceApproximation,
-			bool verbose );
-
-		/** initialize the multi-task optimization problem of laplace approximation 
-		 * integrated in GP
-		 *  @param kernelData object containing kernel matrix and other stuff
-		 *  @param y vector of labels which have to -1 or 1
-		 *  @param kernel a parameterized kernel which provides derivations
-		 *  @param likelihoodFunction the type of the likelihood p(y_i|f_i), e.g. cumulative gaussian
-		 *  @param laplaceApproximation object containing cached matrices of the laplaceApproximation
-		 *  @param verbose print some status messages for debugging and boring work days
-		 **/
-     	GPLaplaceOptimizationProblem ( KernelData *kernelData, const NICE::VVector & y, 
-			ParameterizedKernel *kernel, const LikelihoodFunction *likelihoodFunction,
-			const std::vector<LaplaceApproximation *> & laplaceApproximation,
-			bool verbose );
-
-		/** R.I.P. */
-		~GPLaplaceOptimizationProblem();
-
-		/** compute the negative log likelihood of the laplace approximation integrated GP */
-		double computeObjective();
-
-		/** compute the gradient of the negative log likelihood of the laplace approximation */
-		void computeGradient( NICE::Vector& newGradient );
-
-		/** set hyperparameters of the current kernel */
-		void setParameters ( const NICE::Vector & newParameters ) { parameters() = newParameters; };
-
-		/** use loo parameters */
-		void useLooParameters ();
-		
-		/** update cached stuff like cholesky factorization (KernelData.h) */
-		void update();
+  protected:
+    KernelData *kernelData;
+
+    NICE::VVector y;
+
+    double bestAvgLooError;
+    NICE::Vector bestLooParameters;
+
+    ParameterizedKernel *kernel;
+
+    bool verbose;
+
+    const LikelihoodFunction *likelihoodFunction;
+
+    std::vector<LaplaceApproximation *> laplaceApproximation;
+
+  public:
+
+
+    /** initialize the optimization problem of laplace approximation integrated in
+    *  GP
+    *  @param kernelData object containing kernel matrix and other stuff
+    *  @param y labels which have to -1 or 1
+    *  @param kernel a parameterized kernel which provides derivations
+    *  @param likelihoodFunction the type of the likelihood p(y_i|f_i), e.g. cumulative gaussian
+    *  @param laplaceApproximation object containing cached matrices of the laplaceApproximation
+    *  @param verbose print some status messages for debugging and boring work days
+    **/
+    GPLaplaceOptimizationProblem ( KernelData *kernelData, const NICE::Vector & y,
+                                   ParameterizedKernel *kernel, const LikelihoodFunction *likelihoodFunction,
+                                   LaplaceApproximation *laplaceApproximation,
+                                   bool verbose );
+
+    /** initialize the multi-task optimization problem of laplace approximation
+     * integrated in GP
+     *  @param kernelData object containing kernel matrix and other stuff
+     *  @param y vector of labels which have to -1 or 1
+     *  @param kernel a parameterized kernel which provides derivations
+     *  @param likelihoodFunction the type of the likelihood p(y_i|f_i), e.g. cumulative gaussian
+     *  @param laplaceApproximation object containing cached matrices of the laplaceApproximation
+     *  @param verbose print some status messages for debugging and boring work days
+     **/
+    GPLaplaceOptimizationProblem ( KernelData *kernelData, const NICE::VVector & y,
+                                   ParameterizedKernel *kernel, const LikelihoodFunction *likelihoodFunction,
+                                   const std::vector<LaplaceApproximation *> & laplaceApproximation,
+                                   bool verbose );
+
+    /** R.I.P. */
+    ~GPLaplaceOptimizationProblem();
+
+    /** compute the negative log likelihood of the laplace approximation integrated GP */
+    double computeObjective();
+
+    /** compute the gradient of the negative log likelihood of the laplace approximation */
+    void computeGradient ( NICE::Vector& newGradient );
+
+    /** set hyperparameters of the current kernel */
+    void setParameters ( const NICE::Vector & newParameters )
+    {
+      parameters() = newParameters;
+    };
+
+    /** use loo parameters */
+    void useLooParameters ();
+
+    /** update cached stuff like cholesky factorization (KernelData.h) */
+    void update();
 };
 
 }

+ 57 - 46
classifier/kernelclassifier/KCGPLaplace.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file KCGPLaplace.h
 * @brief Gaussian Process Regression for Classification
 * @author Erik Rodner
@@ -14,55 +14,66 @@
 #include "vislearning/classifier/kernelclassifier/LikelihoodFunction.h"
 
 #undef ROADWORKS
-#define ROADWORKS fthrow(Exception, "Persistent interface not implemented!");
+#define ROADWORKS fthrow(NICE::Exception, "Persistent interface not implemented!");
+
+namespace OBJREC
+{
 
-namespace OBJREC {
- 
 /** Gaussian Process Regression for Classification */
 class KCGPLaplace : public KernelClassifier
 {
-	protected:
-	
-		enum {
-			OPTIMIZATION_METHOD_RASMUSSEN = 0,
-			OPTIMIZATION_METHOD_TRUSTREGION
-		};
-
-
-		int optimizationMethod;
-
-		bool verbose;
-		bool optimizeParameters;
-
-		NICE::Vector y;
-
-		LaplaceApproximation laplaceApproximation;
-		LikelihoodFunction *likelihoodFunction;
-
-    public:
-  
-	/** simple constructor */
-	KCGPLaplace( const NICE::Config *conf, Kernel *kernel = NULL, const std::string & section = "KCGPLaplace" );
-
-	/** copy constructor */
-	KCGPLaplace( const KCGPLaplace & src );
-      
-	/** simple destructor */
-	virtual ~KCGPLaplace();
-  	
-	/** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
-	void teach ( KernelData *kernelData, const NICE::Vector & y );
-  	
-	/** classify an example by using its kernel values with the training set,
-		be careful with the order in @param kernelVector */
-	virtual ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
-  
-  	/** clone this object */
-	KCGPLaplace *clone() const;
-
-	void restore(std::istream&, int) { ROADWORKS };
-	void store(std::ostream&, int) const { ROADWORKS };
-	void clear() { ROADWORKS };
+  protected:
+
+    enum
+    {
+      OPTIMIZATION_METHOD_RASMUSSEN = 0,
+      OPTIMIZATION_METHOD_TRUSTREGION
+    };
+
+
+    int optimizationMethod;
+
+    bool verbose;
+    bool optimizeParameters;
+
+    NICE::Vector y;
+
+    LaplaceApproximation laplaceApproximation;
+    LikelihoodFunction *likelihoodFunction;
+
+  public:
+
+    /** simple constructor */
+    KCGPLaplace ( const NICE::Config *conf, Kernel *kernel = NULL, const std::string & section = "KCGPLaplace" );
+
+    /** copy constructor */
+    KCGPLaplace ( const KCGPLaplace & src );
+
+    /** simple destructor */
+    virtual ~KCGPLaplace();
+
+    /** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
+    void teach ( KernelData *kernelData, const NICE::Vector & y );
+
+    /** classify an example by using its kernel values with the training set,
+     be careful with the order in @param kernelVector */
+    virtual ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
+
+    /** clone this object */
+    KCGPLaplace *clone() const;
+
+    void restore ( std::istream&, int )
+    {
+      ROADWORKS
+    };
+    void store ( std::ostream&, int ) const
+    {
+      ROADWORKS
+    };
+    void clear()
+    {
+      ROADWORKS
+    };
 };
 
 

+ 43 - 33
classifier/kernelclassifier/KCGPLaplaceOneVsAll.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file KCGPLaplaceOneVsAll.h
 * @author Erik Rodner
 * @date 12/10/2009
@@ -15,10 +15,11 @@
 #include "vislearning/regression/gpregression/modelselcrit/genericGPModelSelection.h"
 #include "vislearning/classifier/kernelclassifier/LikelihoodFunction.h"
 
-namespace OBJREC {
-  
+namespace OBJREC
+{
+
 #undef ROADWORKS
-#define ROADWORKS fthrow(Exception, "Persistent interface not implemented!");
+#define ROADWORKS fthrow(NICE::Exception, "Persistent interface not implemented!");
 
 /** @class KCGPLaplaceOneVsAll
  * One vs. All GP Laplace classifier with joint optimization
@@ -29,44 +30,53 @@ namespace OBJREC {
 class KCGPLaplaceOneVsAll : public KernelClassifier
 {
 
-    protected:
-		NICE::Config confCopy;
-		std::string confSection;
+  protected:
+    NICE::Config confCopy;
+    std::string confSection;
+
+    bool optimizeParameters;
+
+    bool verbose;
+
+    int maxIterations;
+
+    std::vector<LaplaceApproximation *> laplaceApproximations;
+    LikelihoodFunction *likelihoodFunction;
 
-		bool optimizeParameters;
+    NICE::VVector ySetZeroMean;
+    NICE::VectorT<int> classnos;
 
-		bool verbose;
+    //GPMSCLooLikelihoodRegression *modelselcrit;
 
-		int maxIterations;
-	
-		std::vector<LaplaceApproximation *> laplaceApproximations;
-		LikelihoodFunction *likelihoodFunction;
+    bool useLooParameters;
 
-		NICE::VVector ySetZeroMean;
-		NICE::VectorT<int> classnos;
+  public:
 
-		//GPMSCLooLikelihoodRegression *modelselcrit;
+    /** simple constructor */
+    KCGPLaplaceOneVsAll ( const NICE::Config *conf, Kernel *kernelFunction = NULL, const std::string & section = "KCGPLaplaceOneVsAll" );
 
-		bool useLooParameters;
+    /** simple destructor */
+    virtual ~KCGPLaplaceOneVsAll();
 
-    public:
-		
-		/** simple constructor */
-		KCGPLaplaceOneVsAll( const NICE::Config *conf, Kernel *kernelFunction = NULL, const std::string & section = "KCGPLaplaceOneVsAll" );
-		  
-		/** simple destructor */
-		virtual ~KCGPLaplaceOneVsAll();
-     
-	 	/** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
-		void teach ( KernelData *kernelData, const NICE::Vector & y );
+    /** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
+    void teach ( KernelData *kernelData, const NICE::Vector & y );
 
-		/** classify an example by using its kernel values with the training set,
-			be careful with the order in @param kernelVector */
-		ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
+    /** classify an example by using its kernel values with the training set,
+     be careful with the order in @param kernelVector */
+    ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
 
-		void restore(std::istream&, int) { ROADWORKS };
-		void store(std::ostream&, int) const { ROADWORKS };
-		void clear() { ROADWORKS };
+    void restore ( std::istream&, int )
+    {
+      ROADWORKS
+    };
+    void store ( std::ostream&, int ) const
+    {
+      ROADWORKS
+    };
+    void clear()
+    {
+      ROADWORKS
+    };
 
 };
 

+ 47 - 37
classifier/kernelclassifier/KCGPOneClass.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file KCGPOneClass.h
 * @brief One-Class Gaussian Process Regression for Classification
 * @author Erik Rodner + Mi.Ke.
@@ -14,50 +14,60 @@
 #include "vislearning/regression/regressionbase/RegressionAlgorithmKernel.h"
 
 #undef ROADWORKS
-#define ROADWORKS fthrow(Exception, "Persistent interface not implemented!");
+#define ROADWORKS fthrow(NICE::Exception, "Persistent interface not implemented!");
 
 #define VARIANCE_DETECTION_MODE 1
 #define MEAN_DETECTION_MODE 2
 
-namespace OBJREC {
- 
+namespace OBJREC
+{
+
 /** Gaussian Process Regression for One-Class Classification  (actually same as binary, don't use parameter optimization!!!)*/
 class KCGPOneClass : public KernelClassifier
 {
 
-    protected:
-		RegressionAlgorithmKernel *regressionAlgorithm;
-		NICE::Matrix InverseKernelMatrix; //only used when 'variance mode' is used and computeInverse=true
-		KernelData *kernelData; ////only used when 'variance mode' is used and computeInverse=false
-		NICE::Vector y;
-		int mode;
-		bool computeInverse;
-		double staticNoise;
-
-    public:
-  
-	/** simple constructor */
-	KCGPOneClass( const NICE::Config *conf, Kernel *kernel = NULL, const std::string & section = "OneClassGP" );
-
-	/** copy constructor */
-	KCGPOneClass( const KCGPOneClass & src );
-      
-	/** simple destructor */
-	virtual ~KCGPOneClass();
-  	
-	/** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
-	void teach ( KernelData *kernelData, const NICE::Vector & y );
-  	
-	/** classify an example by using its kernel values with the training set,
-		be careful with the order in @param kernelVector */
-	virtual ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
-  
-  	/** clone this object */
-	KCGPOneClass *clone() const;
-
-	void restore(std::istream&, int) { ROADWORKS };
-	void store(std::ostream&, int) const { ROADWORKS };
-	void clear() { ROADWORKS };
+  protected:
+    RegressionAlgorithmKernel *regressionAlgorithm;
+    NICE::Matrix InverseKernelMatrix; //only used when 'variance mode' is used and computeInverse=true
+    KernelData *kernelData; ////only used when 'variance mode' is used and computeInverse=false
+    NICE::Vector y;
+    int mode;
+    bool computeInverse;
+    double staticNoise;
+
+  public:
+
+    /** simple constructor */
+    KCGPOneClass ( const NICE::Config *conf, Kernel *kernel = NULL, const std::string & section = "OneClassGP" );
+
+    /** copy constructor */
+    KCGPOneClass ( const KCGPOneClass & src );
+
+    /** simple destructor */
+    virtual ~KCGPOneClass();
+
+    /** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
+    void teach ( KernelData *kernelData, const NICE::Vector & y );
+
+    /** classify an example by using its kernel values with the training set,
+     be careful with the order in @param kernelVector */
+    virtual ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
+
+    /** clone this object */
+    KCGPOneClass *clone() const;
+
+    void restore ( std::istream&, int )
+    {
+      ROADWORKS
+    };
+    void store ( std::ostream&, int ) const
+    {
+      ROADWORKS
+    };
+    void clear()
+    {
+      ROADWORKS
+    };
 };
 
 

+ 66 - 65
classifier/kernelclassifier/KCGPRegOneVsAll.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file KCGPRegOneVsAll.h
 * @author Erik Rodner
 * @date 12/10/2009
@@ -14,10 +14,11 @@
 
 #include <vector>
 
-namespace OBJREC {
-  
+namespace OBJREC
+{
+
 #undef ROADWORKS
-#define ROADWORKS fthrow(Exception, "Persistent interface not implemented!");
+#define ROADWORKS fthrow(NICE::Exception, "Persistent interface not implemented!");
 
 /** @class KCGPRegOneVsAll
  * One vs. All GP regression classifier with joint optimization
@@ -28,67 +29,67 @@ namespace OBJREC {
 class KCGPRegOneVsAll : public KernelClassifier
 {
 
-    protected:
-		/** set of classifiers with the corresponding class */
-		std::vector< std::pair<int, RegGaussianProcess *> > classifiers;
-	
-		/** clone from prototype to generate new classifiers */
-		const RegGaussianProcess *prototype;
-
-		/** whether to optimize hyper-parameters */
-		bool optimizeParameters;
-
-		/** tell us something about what you are doing */
-		bool verbose;
-
-		/** maximum number of iterations of the hyper-parameter estimation */
-		int maxIterations;
-
-		TraceApproximation *traceApproximation;
-		GPMSCLooLikelihoodRegression *modelselcrit;
-
-		/** use the hyperparameters which lead to the best leave-one-out criterion */
-		bool useLooParameters;
-
-		/** whether to invest some computation time to estimate the uncertainty of the prediction */
-		bool computeUncertainty;
-
-		/** for computing uncertainties we need the cholesky decomposition of the kernel matrix */
-		NICE::Matrix choleskyMatrix;
-
-		/** whether to calibrate the probabilities using uncertainty estimates */
-		bool calibrateProbabilities;
-
-		/** how many samples should we draw to estimate the probabilities */
-		uint numSamplesCalibration;
-
-    public:
-  		/** simplest constructor */
-		KCGPRegOneVsAll(){};
-	    	
-		/** simple constructor */
-		KCGPRegOneVsAll( const NICE::Config *conf, Kernel *kernelFunction = NULL, const std::string & section = "KCGPRegOneVsAll" );
-		  
-		/** copy constructor */
-		KCGPRegOneVsAll( const KCGPRegOneVsAll &vcova );
-		
-		/** simple destructor */
-		virtual ~KCGPRegOneVsAll();
-     
-	 	/** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
-		void teach ( KernelData *kernelData, const NICE::Vector & y );
-		void teach ( KernelData *kernelData, const std::vector<double> & y );
-
-		/** classify an example by using its kernel values with the training set,
-			be careful with the order in @param kernelVector */
-		ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
-
-		void restore(std::istream&, int);
-		void store(std::ostream&, int) const;
-		void clear();
-		
-		/** clone this object */
-		virtual KCGPRegOneVsAll *clone(void) const;
+  protected:
+    /** set of classifiers with the corresponding class */
+    std::vector< std::pair<int, RegGaussianProcess *> > classifiers;
+
+    /** clone from prototype to generate new classifiers */
+    const RegGaussianProcess *prototype;
+
+    /** whether to optimize hyper-parameters */
+    bool optimizeParameters;
+
+    /** tell us something about what you are doing */
+    bool verbose;
+
+    /** maximum number of iterations of the hyper-parameter estimation */
+    int maxIterations;
+
+    TraceApproximation *traceApproximation;
+    GPMSCLooLikelihoodRegression *modelselcrit;
+
+    /** use the hyperparameters which lead to the best leave-one-out criterion */
+    bool useLooParameters;
+
+    /** whether to invest some computation time to estimate the uncertainty of the prediction */
+    bool computeUncertainty;
+
+    /** for computing uncertainties we need the cholesky decomposition of the kernel matrix */
+    NICE::Matrix choleskyMatrix;
+
+    /** whether to calibrate the probabilities using uncertainty estimates */
+    bool calibrateProbabilities;
+
+    /** how many samples should we draw to estimate the probabilities */
+    uint numSamplesCalibration;
+
+  public:
+    /** simplest constructor */
+    KCGPRegOneVsAll() {};
+
+    /** simple constructor */
+    KCGPRegOneVsAll ( const NICE::Config *conf, Kernel *kernelFunction = NULL, const std::string & section = "KCGPRegOneVsAll" );
+
+    /** copy constructor */
+    KCGPRegOneVsAll ( const KCGPRegOneVsAll &vcova );
+
+    /** simple destructor */
+    virtual ~KCGPRegOneVsAll();
+
+    /** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
+    void teach ( KernelData *kernelData, const NICE::Vector & y );
+    void teach ( KernelData *kernelData, const std::vector<double> & y );
+
+    /** classify an example by using its kernel values with the training set,
+     be careful with the order in @param kernelVector */
+    ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
+
+    void restore ( std::istream&, int );
+    void store ( std::ostream&, int ) const;
+    void clear();
+
+    /** clone this object */
+    virtual KCGPRegOneVsAll *clone ( void ) const;
 
 };
 

+ 44 - 34
classifier/kernelclassifier/KCGPRegression.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file KCGPRegression.h
 * @brief Gaussian Process Regression for Classification
 * @author Erik Rodner
@@ -15,44 +15,54 @@
 #include "vislearning/regression/regressionbase/TeachWithInverseKernelMatrix.h"
 
 #undef ROADWORKS
-#define ROADWORKS fthrow(Exception, "Persistent interface not implemented!");
+#define ROADWORKS fthrow(NICE::Exception, "Persistent interface not implemented!");
+
+namespace OBJREC
+{
 
-namespace OBJREC {
- 
 /** Gaussian Process Regression for Classification */
 class KCGPRegression : public KernelClassifier
 {
 
-    protected:
-		RegressionAlgorithmKernel *regressionAlgorithm;
-		NICE::Vector y;
-
-    public:
-  
-	/** simple constructor */
-	KCGPRegression( const NICE::Config *conf, Kernel *kernel = NULL, const std::string & section = "KCGPRegression" );
-
-	/** copy constructor */
-	KCGPRegression( const KCGPRegression & src );
-      
-	/** simple destructor */
-	virtual ~KCGPRegression();
-  	
-	/** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
-	void teach ( KernelData *kernelData, const NICE::Vector & y );
-  	
-	/** classify an example by using its kernel values with the training set,
-		be careful with the order in @param kernelVector */
-	virtual ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
-  
-  	/** clone this object */
-	KCGPRegression *clone() const;
-
-	void restore(std::istream&, int) { ROADWORKS };
-	void store(std::ostream&, int) const { ROADWORKS };
-	void clear() { ROADWORKS };
-
-	bool getOptimizeKernelParameters () const;
+  protected:
+    RegressionAlgorithmKernel *regressionAlgorithm;
+    NICE::Vector y;
+
+  public:
+
+    /** simple constructor */
+    KCGPRegression ( const NICE::Config *conf, Kernel *kernel = NULL, const std::string & section = "KCGPRegression" );
+
+    /** copy constructor */
+    KCGPRegression ( const KCGPRegression & src );
+
+    /** simple destructor */
+    virtual ~KCGPRegression();
+
+    /** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
+    void teach ( KernelData *kernelData, const NICE::Vector & y );
+
+    /** classify an example by using its kernel values with the training set,
+     be careful with the order in @param kernelVector */
+    virtual ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
+
+    /** clone this object */
+    KCGPRegression *clone() const;
+
+    void restore ( std::istream&, int )
+    {
+      ROADWORKS
+    };
+    void store ( std::ostream&, int ) const
+    {
+      ROADWORKS
+    };
+    void clear()
+    {
+      ROADWORKS
+    };
+
+    bool getOptimizeKernelParameters () const;
 };
 
 

+ 46 - 36
classifier/kernelclassifier/KCMinimumEnclosingBall.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file KCGPOneClass.h
 * @brief One-Class Gaussian Process Regression for Classification
 * @author Erik Rodner + Mi.Ke.
@@ -12,7 +12,7 @@
 #include "vislearning/math/kernels/ParameterizedKernel.h"
 
 #undef ROADWORKS
-#define ROADWORKS fthrow(Exception, "Persistent interface not implemented!");
+#define ROADWORKS fthrow(NICE::Exception, "Persistent interface not implemented!");
 
 #define VARIANCE_DETECTION_MODE 1
 #define MEAN_DETECTION_MODE 2
@@ -21,44 +21,54 @@
 #include "vislearning/optimization/quadprog/Array.h"
 
 
-namespace OBJREC {
- 
+namespace OBJREC
+{
+
 /** Minimum Enclosing Ball Algorithm (For stationary kernels equal to 1-SVM)*/
 class KCMinimumEnclosingBall : public KernelClassifier
 {
 
-    protected:
-		int trainingSize;
-		double radius;
-		double aKa;
-		double nu;
-		QuadProgPP::Matrix<double> TwoK,Eye,Ones,ones;
-		QuadProgPP::Vector<double> alpha,b,minusDiagK,minusOne,zeros;
-
-    public:
-  
-	/** simple constructor */
-	KCMinimumEnclosingBall( const NICE::Config *conf, Kernel *kernel = NULL, const std::string & section = "KCGMinimumEnclosingBall" );
-
-	/** copy constructor */
-	KCMinimumEnclosingBall( const KCMinimumEnclosingBall & src );
-      
-	/** simple destructor */
-	virtual ~KCMinimumEnclosingBall();
-  	
-	/** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
-	void teach ( KernelData *kernelData, const NICE::Vector & y );
-  	
-	/** classify an example by using its kernel values with the training set,
-		be careful with the order in @param kernelVector */
-	virtual ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf  ) const;
-  
-  	/** clone this object */
-	KCMinimumEnclosingBall *clone() const;
-
-	void restore(std::istream&, int) { ROADWORKS };
-	void store(std::ostream&, int) const { ROADWORKS };
-	void clear() { ROADWORKS };
+  protected:
+    int trainingSize;
+    double radius;
+    double aKa;
+    double nu;
+    QuadProgPP::Matrix<double> TwoK,Eye,Ones,ones;
+    QuadProgPP::Vector<double> alpha,b,minusDiagK,minusOne,zeros;
+
+  public:
+
+    /** simple constructor */
+    KCMinimumEnclosingBall ( const NICE::Config *conf, Kernel *kernel = NULL, const std::string & section = "KCGMinimumEnclosingBall" );
+
+    /** copy constructor */
+    KCMinimumEnclosingBall ( const KCMinimumEnclosingBall & src );
+
+    /** simple destructor */
+    virtual ~KCMinimumEnclosingBall();
+
+    /** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
+    void teach ( KernelData *kernelData, const NICE::Vector & y );
+
+    /** classify an example by using its kernel values with the training set,
+     be careful with the order in @param kernelVector */
+    virtual ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
+
+    /** clone this object */
+    KCMinimumEnclosingBall *clone() const;
+
+    void restore ( std::istream&, int )
+    {
+      ROADWORKS
+    };
+    void store ( std::ostream&, int ) const
+    {
+      ROADWORKS
+    };
+    void clear()
+    {
+      ROADWORKS
+    };
 
 };
 

+ 39 - 29
classifier/kernelclassifier/KCOneVsAll.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file KCOneVsAll.h
 * @author Erik Rodner
 * @date 12/10/2009
@@ -9,43 +9,53 @@
 
 #include "vislearning/classifier/classifierbase/KernelClassifier.h"
 
-namespace OBJREC {
-  
+namespace OBJREC
+{
+
 #undef ROADWORKS
-#define ROADWORKS fthrow(Exception, "Persistent interface not implemented!");
+#define ROADWORKS fthrow(NICE::Exception, "Persistent interface not implemented!");
 
 /** @class KCOneVsAll
- * One vs. All interface for kernel classifiers 
+ * One vs. All interface for kernel classifiers
  *
  * @author Erik Rodner
  */
 class KCOneVsAll : public KernelClassifier
 {
 
-    protected:
-		std::vector< std::pair<int, KernelClassifier *> > classifiers;
-		const KernelClassifier *prototype;
-		double noiseSigma;
-		bool verbose;
-
-    public:
-  
-		/** simple constructor */
-		KCOneVsAll( const NICE::Config *conf, const KernelClassifier *prototype, const std::string & section = "KCOneVsAll" );
-		  
-		/** simple destructor */
-		virtual ~KCOneVsAll();
-     
-	 	/** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
-		void teach ( KernelData *kernelData, const NICE::Vector & y );
-
-		/** classify an example by using its kernel values with the training set,
-			be careful with the order in @param kernelVector */
-		ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
-
-		void restore(std::istream&, int) { ROADWORKS };
-		void store(std::ostream&, int) const { ROADWORKS };
-		void clear() { ROADWORKS };
+  protected:
+    std::vector< std::pair<int, KernelClassifier *> > classifiers;
+    const KernelClassifier *prototype;
+    double noiseSigma;
+    bool verbose;
+
+  public:
+
+    /** simple constructor */
+    KCOneVsAll ( const NICE::Config *conf, const KernelClassifier *prototype, const std::string & section = "KCOneVsAll" );
+
+    /** simple destructor */
+    virtual ~KCOneVsAll();
+
+    /** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
+    void teach ( KernelData *kernelData, const NICE::Vector & y );
+
+    /** classify an example by using its kernel values with the training set,
+     be careful with the order in @param kernelVector */
+    ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
+
+    void restore ( std::istream&, int )
+    {
+      ROADWORKS
+    };
+    void store ( std::ostream&, int ) const
+    {
+      ROADWORKS
+    };
+    void clear()
+    {
+      ROADWORKS
+    };
 
 };
 

+ 27 - 26
classifier/kernelclassifier/LHCumulativeGauss.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LHCumulativeGauss.h
 * @author Erik Rodner
 * @date 02/17/2010
@@ -9,38 +9,39 @@
 
 #include "LikelihoodFunction.h"
 
-namespace OBJREC {
-  
+namespace OBJREC
+{
+
 /** @class LHCumulativeGauss
- * cumulative gauss function 
+ * cumulative gauss function
  *
  * @author Erik Rodner
  */
 class LHCumulativeGauss : public LikelihoodFunction
 {
 
-    protected:
-		double lengthScale;
-		double bias;
-
-    public:
-
-		/** a length scale of the likelihood function correspondes
-		 * to a an inverse scaling of the gp prior, thus you
-		 * could optimize this parameter by optimizing a hyperparameter
-		 * of the kernel function */
-		LHCumulativeGauss( double lengthScale = 1.0, double bias = 0.0 );
- 
- 		/** needed for hyperparameter estimation */
-		double thirdgrad ( double y, double f ) const;
-		double hessian ( double y, double f ) const;
-		double gradient ( double y, double f ) const;
-		double logLike ( double y, double f ) const;
-		double likelihood ( double y, double f ) const;
-
-		double predictAnalytically ( double fmean, double fvariance ) const;
-		
-		static double stdNormPDF (double x);
+  protected:
+    double lengthScale;
+    double bias;
+
+  public:
+
+    /** a length scale of the likelihood function correspondes
+     * to a an inverse scaling of the gp prior, thus you
+     * could optimize this parameter by optimizing a hyperparameter
+     * of the kernel function */
+    LHCumulativeGauss ( double lengthScale = 1.0, double bias = 0.0 );
+
+    /** needed for hyperparameter estimation */
+    double thirdgrad ( double y, double f ) const;
+    double hessian ( double y, double f ) const;
+    double gradient ( double y, double f ) const;
+    double logLike ( double y, double f ) const;
+    double likelihood ( double y, double f ) const;
+
+    double predictAnalytically ( double fmean, double fvariance ) const;
+
+    static double stdNormPDF ( double x );
 };
 
 }

+ 66 - 47
classifier/kernelclassifier/LaplaceApproximation.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LaplaceApproximation.h
 * @author Erik Rodner
 * @date 02/17/2010
@@ -11,59 +11,78 @@
 #include "vislearning/classifier/kernelclassifier/LikelihoodFunction.h"
 #include "vislearning/math/kernels/KernelData.h"
 
-namespace OBJREC {
-  
+namespace OBJREC
+{
+
 /** @class LaplaceApproximation
- * some utility functions for laplace approximation 
+ * some utility functions for laplace approximation
  *
  * @author Erik Rodner
  */
 class LaplaceApproximation
 {
 
-    protected:
-		/** optimization settings */
-		uint maxiterations;
-		double minimumDelta;
-		bool verbose;
-
-		/** useful variables */
-		NICE::Vector mode;
-		NICE::Vector hessianW;
-		NICE::Vector gradientL;
-		NICE::Matrix cholB;
-
-		NICE::Vector a;
-
-		double objective;
-		double noiseTerm;
-
-		void updateCache ( const NICE::Matrix & kernelMatrix, const NICE::Vector & y, const LikelihoodFunction *likelihoodFunction );
-
-    public:
-  
-  		/** use standard settings */
-		LaplaceApproximation();
-
-		/** simple constructor using config values for numerical details */
-		LaplaceApproximation( const NICE::Config *conf, const std::string & section = "LaplaceApproximation" );
-		  
-		/** simple destructor */
-		virtual ~LaplaceApproximation();
-  
-  		void approximate ( KernelData *kernelData, const NICE::Vector & y,
-					   const LikelihoodFunction *likelihoodFunction );
-
-		double predict ( const NICE::Vector & kernelVector, double kernelSelf, const NICE::Vector & y, 
-				const LikelihoodFunction *likelihoodFunction ) const;
-
-		const NICE::Vector & getMode () const { return mode; };
-		const NICE::Vector & getHessian () const { return hessianW; };
-		const NICE::Vector & getGradient () const { return gradientL; };
-		const NICE::Vector & getAVector () const { return a; };
-		const NICE::Matrix & getCholeskyB () const { return cholB; };
-
-		double getObjective () const { return objective; };
+  protected:
+    /** optimization settings */
+    uint maxiterations;
+    double minimumDelta;
+    bool verbose;
+
+    /** useful variables */
+    NICE::Vector mode;
+    NICE::Vector hessianW;
+    NICE::Vector gradientL;
+    NICE::Matrix cholB;
+
+    NICE::Vector a;
+
+    double objective;
+    double noiseTerm;
+
+    void updateCache ( const NICE::Matrix & kernelMatrix, const NICE::Vector & y, const LikelihoodFunction *likelihoodFunction );
+
+  public:
+
+    /** use standard settings */
+    LaplaceApproximation();
+
+    /** simple constructor using config values for numerical details */
+    LaplaceApproximation ( const NICE::Config *conf, const std::string & section = "LaplaceApproximation" );
+
+    /** simple destructor */
+    virtual ~LaplaceApproximation();
+
+    void approximate ( KernelData *kernelData, const NICE::Vector & y,
+                       const LikelihoodFunction *likelihoodFunction );
+
+    double predict ( const NICE::Vector & kernelVector, double kernelSelf, const NICE::Vector & y,
+                     const LikelihoodFunction *likelihoodFunction ) const;
+
+    const NICE::Vector & getMode () const
+    {
+      return mode;
+    };
+    const NICE::Vector & getHessian () const
+    {
+      return hessianW;
+    };
+    const NICE::Vector & getGradient () const
+    {
+      return gradientL;
+    };
+    const NICE::Vector & getAVector () const
+    {
+      return a;
+    };
+    const NICE::Matrix & getCholeskyB () const
+    {
+      return cholB;
+    };
+
+    double getObjective () const
+    {
+      return objective;
+    };
 };
 
 }

+ 39 - 44
classifier/vclassifier/VCAmitSVM.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file VCAmitSVM.h
 * @brief interface to the svm generalization of Amit et al. 2007
 * @author Erik Rodner
@@ -10,57 +10,52 @@
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
- 
+
 #include "VCLearnFromSC.h"
 
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 /** interface to the svm generalization of Amit et al. 2007 */
 class VCAmitSVM : public VCLearnFromSC
 {
 
-    protected:
-	double C;
-	double gamma;
-
-	// refactor-nice.pl: check this substitution
-	// old: string amitDir;
-	std::string amitDir;
-	// refactor-nice.pl: check this substitution
-	// old: string matlabExec;
-	std::string matlabExec;
-	// refactor-nice.pl: check this substitution
-	// old: string matlabArgs;
-	std::string matlabArgs;
-	
-    public:
-	// refactor-nice.pl: check this substitution
-	// old: Matrix W;
-	NICE::Matrix W;
-  
-	/** simple constructor */
-	VCAmitSVM( const NICE::Config *conf );
-      
-	/** simple destructor */
-	virtual ~VCAmitSVM();
-     
-	/** classify using simple vector */
-	// refactor-nice.pl: check this substitution
-	// old: virtual ClassificationResult classify ( const ice::Vector & x ) const;
-	virtual ClassificationResult classify ( const NICE::Vector & x ) const;
-
-	virtual void preTeach ( const LabeledSetVector & teachSet );
-
-	virtual void teach ( const LabeledSetVector & teachSet );
-
-	virtual void finishTeaching() {};
-
-	void restore ( std::istream & is, int format = 0 );
-
-	void store ( std::ostream & is, int format = 0 ) const;
-
-	void clear ();
+  protected:
+    double C;
+    double gamma;
+
+    std::string amitDir;
+
+    std::string matlabExec;
+
+    std::string matlabArgs;
+
+  public:
+
+    NICE::Matrix W;
+
+    /** simple constructor */
+    VCAmitSVM ( const NICE::Config *conf );
+
+    /** simple destructor */
+    virtual ~VCAmitSVM();
+
+    /** classify using simple vector */
+
+    virtual ClassificationResult classify ( const NICE::Vector & x ) const;
+
+    virtual void preTeach ( const LabeledSetVector & teachSet );
+
+    virtual void teach ( const LabeledSetVector & teachSet );
+
+    virtual void finishTeaching() {};
+
+    void restore ( std::istream & is, int format = 0 );
+
+    void store ( std::ostream & is, int format = 0 ) const;
+
+    void clear ();
 
 };
 

+ 28 - 27
classifier/vclassifier/VCCrossGeneralization.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file VCCrossGeneralization.h
 * @brief Combination of Classifiers
 * @author Erik Rodner
@@ -9,7 +9,7 @@
 #define VCCrossGeneralizationINCLUDE
 
 #ifdef NICE_USELIB_ICE
- 
+
 #include "VCLearnFromSC.h"
 
 #ifdef NICE_USELIB_ICE
@@ -19,47 +19,48 @@
 #include "core/basics/Config.h"
 
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 /** Combination of Classifiers */
 class VCCrossGeneralization : public VCLearnFromSC
 {
 
-    protected:
-	bool useVotingNormalization;
+  protected:
+    bool useVotingNormalization;
+
+    VCSimpleGaussian gauss;
+
+    VCNearestNeighbour nnclassifier;
+
+    bool simpleGaussianFinished;
+
+    void normalizeVotings ( NICE::Vector & v ) const;
+
+  public:
 
-	VCSimpleGaussian gauss;
+    /** simple constructor */
+    VCCrossGeneralization ( const NICE::Config *conf );
 
-	VCNearestNeighbour nnclassifier;
+    /** simple destructor */
+    virtual ~VCCrossGeneralization();
 
-	bool simpleGaussianFinished;
-	
-	void normalizeVotings ( NICE::Vector & v ) const;
+    /** classify using simple vector */
 
-    public:
-  
-	/** simple constructor */
-	VCCrossGeneralization (const NICE::Config *conf);
-      
-	/** simple destructor */
-	virtual ~VCCrossGeneralization();
- 
-	/** classify using simple vector */
+    virtual ClassificationResult classify ( const NICE::Vector & x ) const;
 
-	virtual ClassificationResult classify ( const NICE::Vector & x ) const;
+    virtual void preTeach ( const LabeledSetVector & teachSet );
 
-	virtual void preTeach ( const LabeledSetVector & teachSet );
+    virtual void teach ( const LabeledSetVector & teachSet );
 
-	virtual void teach ( const LabeledSetVector & teachSet );
+    virtual void finishTeaching();
 
-	virtual void finishTeaching();
+    void restore ( std::istream & is, int format = 0 );
 
-	void restore ( std::istream & is, int format = 0 );
+    void store ( std::ostream & is, int format = 0 ) const;
 
-	void store ( std::ostream & is, int format = 0 ) const;
+    void clear ();
 
-	void clear ();
-    
 };
 
 

+ 2 - 0
classifier/vclassifier/VCDTSVM.cpp

@@ -2,6 +2,8 @@
 
 #include "vislearning/classifier/vclassifier/VCDTSVM.h"
 
+#include "core/image/ImageT.h"
+//#include "core/imagedisplay/ImageDisplay.h"
 #include "core/basics/StringTools.h"
 
 #undef WRITE

+ 0 - 2
classifier/vclassifier/VCDTSVM.h

@@ -9,8 +9,6 @@
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
 
 #include "vislearning/cbaselib/LabeledSet.h"
 #include "vislearning/classifier/classifierbase/VecClassifier.h"

+ 110 - 0
classifier/vclassifier/VCNearestClassMean.cpp

@@ -0,0 +1,110 @@
+#ifdef NICE_USELIB_ICE
+
+#include <iostream>
+
+#include "vislearning/classifier/vclassifier/VCNearestClassMean.h"
+
+using namespace OBJREC;
+
+using namespace std;
+
+using namespace NICE;
+
+VCNearestClassMean::VCNearestClassMean( const Config *_conf, NICE::VectorDistance<double> *_distancefunc  ) 
+: VecClassifier ( _conf ), distancefunc (_distancefunc)
+{    
+    if ( _distancefunc == NULL )
+		distancefunc = new EuclidianDistance<double>();
+}
+
+VCNearestClassMean::~VCNearestClassMean()
+{
+    clear();
+}
+
+/** classify using simple vector */
+
+ClassificationResult VCNearestClassMean::classify ( const NICE::Vector & x ) const
+{
+     double min_distance= std::numeric_limits<double>::max();
+     int min_class = -1;
+     FullVector scores ( classNo.size() );
+     
+     for(uint i=0;i<this->classNo.size();i++)
+     {
+          double distance = distancefunc->calculate ( x, means[i] );
+          scores[i] = - distance;
+          if ( distance < min_distance)
+          {
+               min_distance = distance;
+               min_class = classNo[i];
+          }
+     }
+     
+     return ClassificationResult ( min_class, scores );
+}
+
+
+void VCNearestClassMean::teach ( const LabeledSetVector & _teachSet )
+{
+
+    _teachSet.getClasses ( this->classNo );
+
+    //initialize means
+    NICE::Vector zero( _teachSet.dimension() );
+    for(uint d=0;d<zero.size();d++) zero[d]=0.0;
+    for(uint c=0;c<this->classNo.size();c++)
+    {
+	means.push_back(zero);
+    }
+
+    //add all class-specific vectors 
+    int index=0;
+    LOOP_ALL(_teachSet)
+    {
+	EACH(classno,x);
+	//determine index
+	for(uint c=0;c<this->classNo.size();c++)
+        {
+		if(classno==classNo[c]) index=c;
+        }
+	for(uint d=0;d<zero.size();d++)
+        {
+	   means[index][d]+=x[d];
+        }
+    }
+
+    //normalize vectors
+    for(uint c=0;c<this->classNo.size();c++)
+    {
+	for(uint d=0;d<zero.size();d++)
+        {
+	   means[c][d]/=_teachSet.count(this->classNo[c]);
+        }
+    }
+
+}
+
+void VCNearestClassMean::finishTeaching()
+{
+//nothing more to do
+}
+
+void VCNearestClassMean::clear ()
+{
+//nothing to do
+}
+
+void VCNearestClassMean::store ( std::ostream & os, int format ) const
+{
+    fprintf (stderr, "NOT YET IMPLEMENTED\n");
+    exit(-1);
+}
+
+void VCNearestClassMean::restore ( std::istream & is, int format )
+{
+    fprintf (stderr, "NOT YET IMPLEMENTED\n");
+    exit(-1);
+}
+
+#endif

+ 55 - 0
classifier/vclassifier/VCNearestClassMean.h

@@ -0,0 +1,55 @@
+/** 
+* @file VCNearestClassMean.h
+* @brief Nearest Class Mean Classifier (Naive Bayes with identity covariance matrix for all classes) -> code is based on VCSimpleGaussian and VCNearestNeighbor
+* @author Erik Rodner + Mi.Ke
+* @date 12/05/2007
+
+*/
+
+#ifndef VCNEARESTCLASSMEANINCLUDE
+#define VCNEARESTCLASSMEANINCLUDE
+
+#include "vislearning/classifier/classifierbase/VecClassifier.h"
+#include <core/vector/Distance.h>
+
+#include <image_nonvis.h>
+
+namespace OBJREC {
+
+/** Simple Gaussian Classifier */
+class VCNearestClassMean : public VecClassifier
+{
+    public:
+	std::vector<NICE::Vector> means;
+	std::vector<int> classNo;
+	NICE::VectorDistance<double> *distancefunc;
+	std::map<int, ice::Statistics *> statistics;
+
+    public:
+  
+	/** simple constructor */
+	VCNearestClassMean( const NICE::Config *conf, NICE::VectorDistance<double> *distancefunc = NULL );
+      
+	/** simple destructor */
+	virtual ~VCNearestClassMean();
+ 
+	/** classify using simple vector */
+	ClassificationResult classify ( const NICE::Vector & x ) const;
+
+	/** classify using a simple vector */
+	void teach ( const LabeledSetVector & teachSet );
+	
+	void finishTeaching();
+
+	void clear ();
+
+	void store ( std::ostream & os, int format = 0 ) const;
+
+	void restore ( std::istream & is, int format = 0 );
+
+};
+
+
+} // namespace
+
+#endif

+ 3 - 0
classifier/vclassifier/VCOneVsAll.cpp

@@ -6,6 +6,9 @@
 */
 #include <iostream>
 
+#include "core/image/ImageT.h"
+#include "core/imagedisplay/ImageDisplay.h"
+
 #include "vislearning/classifier/vclassifier/VCOneVsAll.h"
 
 

+ 0 - 2
classifier/vclassifier/VCOneVsAll.h

@@ -10,8 +10,6 @@
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
-#include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
 
 #include "vislearning/classifier/classifierbase/VecClassifier.h"
 #include "core/basics/triplet.h"

+ 35 - 31
classifier/vclassifier/VCOneVsOne.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file VCOneVsOne.h
 * @brief one-vs.-one svm voting
 * @author Erik Rodner
@@ -15,40 +15,44 @@
 #include "core/basics/triplet.h"
 
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 /** one-vs.-one svm voting */
 class VCOneVsOne : public VecClassifier
 {
-    protected:
-	
-	VecClassifier *prototype;
-	std::vector< triplet<int, int, VecClassifier *> > classifiers;
-	bool use_weighted_voting;
-
-    public:
-  
-	/** simple constructor */
-	VCOneVsOne( const NICE::Config *conf, VecClassifier *prototype );
-      
-	/** simple destructor */
-	virtual ~VCOneVsOne();
-     
-	/** classify using simple vector */
-	ClassificationResult classify ( const NICE::Vector & x ) const;
-
-	/** classify using a simple vector */
-	void teach ( const LabeledSetVector & teachSet );
-	
-	void finishTeaching();
-
-
-	void read (const std::string& s, int format = 0);
-	void save (const std::string& s, int format = 0) const;
-
-	void clear () { classifiers.clear(); };
-	void store ( std::ostream & os, int format = 0 ) const;
-	void restore ( std::istream & is, int format = 0 );
+  protected:
+
+    VecClassifier *prototype;
+    std::vector< NICE::triplet<int, int, VecClassifier *> > classifiers;
+    bool use_weighted_voting;
+
+  public:
+
+    /** simple constructor */
+    VCOneVsOne ( const NICE::Config *conf, VecClassifier *prototype );
+
+    /** simple destructor */
+    virtual ~VCOneVsOne();
+
+    /** classify using simple vector */
+    ClassificationResult classify ( const NICE::Vector & x ) const;
+
+    /** classify using a simple vector */
+    void teach ( const LabeledSetVector & teachSet );
+
+    void finishTeaching();
+
+
+    void read ( const std::string& s, int format = 0 );
+    void save ( const std::string& s, int format = 0 ) const;
+
+    void clear ()
+    {
+      classifiers.clear();
+    };
+    void store ( std::ostream & os, int format = 0 ) const;
+    void restore ( std::istream & is, int format = 0 );
 };
 
 

+ 98 - 102
features/fpfeatures/ColorHistogramFeature.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file ColorHistogramFeature.cpp
 * @brief histogram of oriented gradients ( dalal and triggs )
 * @author Erik Rodner
@@ -19,17 +19,17 @@ using namespace NICE;
 const double epsilon = 10e-8;
 
 /** simple constructor */
-ColorHistogramFeature::ColorHistogramFeature( const Config *conf )
+ColorHistogramFeature::ColorHistogramFeature ( const Config *conf )
 {
-    window_size_x = conf->gI("ColorHistogramFeature", "window_size_x", 21 );
-    window_size_y = conf->gI("ColorHistogramFeature", "window_size_y", 21 );
-    scaleStep = conf->gD("ColorHistogramFeature", "scale_step", sqrt(2) );
-    numScales = conf->gI("ColorHistogramFeature", "num_scales", 5 );
-
-    int numBinsH = conf->gI("ColorHistogramFeature", "num_bins_h", 4);
-    int numBinsS = conf->gI("ColorHistogramFeature", "num_bins_s", 2);
-    int numBinsV = conf->gI("ColorHistogramFeature", "num_bins_v", 2);
-    numBins = numBinsH*numBinsS*numBinsV;
+  window_size_x = conf->gI ( "ColorHistogramFeature", "window_size_x", 21 );
+  window_size_y = conf->gI ( "ColorHistogramFeature", "window_size_y", 21 );
+  scaleStep = conf->gD ( "ColorHistogramFeature", "scale_step", sqrt ( 2 ) );
+  numScales = conf->gI ( "ColorHistogramFeature", "num_scales", 5 );
+
+  int numBinsH = conf->gI ( "ColorHistogramFeature", "num_bins_h", 4 );
+  int numBinsS = conf->gI ( "ColorHistogramFeature", "num_bins_s", 2 );
+  int numBinsV = conf->gI ( "ColorHistogramFeature", "num_bins_v", 2 );
+  numBins = numBinsH * numBinsS * numBinsV;
 }
 
 /** simple destructor */
@@ -37,124 +37,120 @@ ColorHistogramFeature::~ColorHistogramFeature()
 {
 }
 
-double ColorHistogramFeature::val( const Example *example ) const
+double ColorHistogramFeature::val ( const Example *example ) const
 {
-    const NICE::MultiChannelImageT<double> & img = 
-	example->ce->getDChannel ( CachedExample::D_INTEGRALCOLOR );
-    int tm_xsize = img.xsize;
-    int tm_ysize = img.ysize;
-
-    int xsize;
-    int ysize;
-    example->ce->getImageSize ( xsize, ysize );
-
-    int wsx2, wsy2;
-    int exwidth = example->width;
-    if ( exwidth == 0 ) {
-	wsx2 = window_size_x * tm_xsize / (2*xsize);
-	wsy2 = window_size_y * tm_ysize / (2*ysize);
-    } else {
-	int exheight = example->height;
-	wsx2 = exwidth * tm_xsize / (2*xsize);
-	wsy2 = exheight * tm_ysize / (2*ysize);
-    }
-	
-    int xx, yy;
-    xx = ( example->x ) * tm_xsize / xsize;
-    yy = ( example->y ) * tm_ysize / ysize;
-
-    assert ( (wsx2 > 0) && (wsy2 > 0) );
-
-    int xtl = xx - wsx2;
-    int ytl = yy - wsy2;
-    int xrb = xx + wsx2;
-    int yrb = yy + wsy2;
+  const NICE::MultiChannelImageT<double> & img =
+    example->ce->getDChannel ( CachedExample::D_INTEGRALCOLOR );
+  int tm_xsize = img.width();
+  int tm_ysize = img.height();
+
+  int xsize;
+  int ysize;
+  example->ce->getImageSize ( xsize, ysize );
+
+  int wsx2, wsy2;
+  int exwidth = example->width;
+  if ( exwidth == 0 ) {
+    wsx2 = window_size_x * tm_xsize / ( 2 * xsize );
+    wsy2 = window_size_y * tm_ysize / ( 2 * ysize );
+  } else {
+    int exheight = example->height;
+    wsx2 = exwidth * tm_xsize / ( 2 * xsize );
+    wsy2 = exheight * tm_ysize / ( 2 * ysize );
+  }
+
+  int xx, yy;
+  xx = ( example->x ) * tm_xsize / xsize;
+  yy = ( example->y ) * tm_ysize / ysize;
+
+  assert ( ( wsx2 > 0 ) && ( wsy2 > 0 ) );
+
+  int xtl = xx - wsx2;
+  int ytl = yy - wsy2;
+  int xrb = xx + wsx2;
+  int yrb = yy + wsy2;
 
 #define BOUND(x,min,max) (((x)<(min))?(min):((x)>(max)?(max):(x)))
-    xtl = BOUND ( xtl, 0, tm_xsize - 1 );
-    ytl = BOUND ( ytl, 0, tm_ysize - 1 );
-    xrb = BOUND ( xrb, 0, tm_xsize - 1 );
-    yrb = BOUND ( yrb, 0, tm_ysize - 1 );
+  xtl = BOUND ( xtl, 0, tm_xsize - 1 );
+  ytl = BOUND ( ytl, 0, tm_ysize - 1 );
+  xrb = BOUND ( xrb, 0, tm_xsize - 1 );
+  yrb = BOUND ( yrb, 0, tm_ysize - 1 );
 #undef BOUND
 
-    assert ( bin < (int)img.numChannels );
-    assert ( img.data[bin] != NULL );
-
-    long kA = xtl + ytl * tm_xsize;
-    long kB = xrb + ytl * tm_xsize;
-    long kC = xtl + yrb * tm_xsize;
-    long kD = xrb + yrb * tm_xsize;
-    double A,B,C,D;
-    A = img.data[bin][ kA ];
-    B = img.data[bin][ kB ];
-    C = img.data[bin][ kC ];
-    D = img.data[bin][ kD ];
-
-    double val1 =  (D - B - C + A);
-    double sum = val1*val1;
-    for ( int b = 0 ; b < (int)img.numChannels ; b++)
-    {
-	if ( b == bin ) continue;
-	A = img.data[b][ kA ];
-	B = img.data[b][ kB ];
-	C = img.data[b][ kC ];
-	D = img.data[b][ kD ];
-	double val = ( D - B - C + A );
-	sum += val*val;
-    }
-    sum = sqrt(sum);
-    return ( val1 + epsilon ) / ( sum + epsilon );
+  assert ( bin < ( int ) img.channels() );
+
+  double A, B, C, D;
+  A = img.get ( xtl, ytl, bin );
+  B = img.get ( xrb, ytl, bin );
+  C = img.get ( xtl, yrb, bin );
+  D = img.get ( xrb, yrb, bin );
+
+  double val1 = ( D - B - C + A );
+  double sum = val1 * val1;
+  for ( int b = 0 ; b < ( int ) img.channels() ; b++ )
+  {
+    if ( b == bin ) 
+      continue;
+    A = img.get ( xtl, ytl, b );
+    B = img.get ( xrb, ytl, b );
+    C = img.get ( xtl, yrb, b );
+    D = img.get ( xrb, yrb, b );
+    double val = ( D - B - C + A );
+    sum += val * val;
+  }
+  sum = sqrt ( sum );
+  return ( val1 + epsilon ) / ( sum + epsilon );
 }
 
 void ColorHistogramFeature::explode ( FeaturePool & featurePool, bool variableWindow ) const
 {
-    int nScales = (variableWindow ? numScales : 1 );
+  int nScales = ( variableWindow ? numScales : 1 );
 
-    for ( int i = 0 ; i < nScales ; i++ )
+  for ( int i = 0 ; i < nScales ; i++ )
+  {
+    int wsy = window_size_y;
+    int wsx = window_size_x;
+    for ( int _bin = 0 ; _bin < numBins ; _bin++ )
     {
-	int wsy = window_size_y;
-	int wsx = window_size_x;
-	for ( int _bin = 0 ; _bin < numBins ; _bin++ )
-	{
-	    ColorHistogramFeature *f = new ColorHistogramFeature();
-	    f->window_size_x = wsx;
-	    f->window_size_y = wsy;
-	    f->bin = _bin;
-	    featurePool.addFeature ( f, 1.0 / ( numBins * nScales ) ); 
-	}
-	wsx = (int) (scaleStep * wsx);
-	wsy = (int) (scaleStep * wsy);
+      ColorHistogramFeature *f = new ColorHistogramFeature();
+      f->window_size_x = wsx;
+      f->window_size_y = wsy;
+      f->bin = _bin;
+      featurePool.addFeature ( f, 1.0 / ( numBins * nScales ) );
     }
+    wsx = ( int ) ( scaleStep * wsx );
+    wsy = ( int ) ( scaleStep * wsy );
+  }
 }
 
 Feature *ColorHistogramFeature::clone() const
 {
-    ColorHistogramFeature *f = new ColorHistogramFeature();
-    f->window_size_x = window_size_x;
-    f->window_size_y = window_size_y;
-    f->bin = bin;
+  ColorHistogramFeature *f = new ColorHistogramFeature();
+  f->window_size_x = window_size_x;
+  f->window_size_y = window_size_y;
+  f->bin = bin;
 
-    return f;
+  return f;
 }
 
 Feature *ColorHistogramFeature::generateFirstParameter () const
 {
-    return clone();
+  return clone();
 }
 
-void ColorHistogramFeature::restore (istream & is, int format)
+void ColorHistogramFeature::restore ( istream & is, int format )
 {
-    is >> window_size_x;
-    is >> window_size_y;
-    is >> bin;
+  is >> window_size_x;
+  is >> window_size_y;
+  is >> bin;
 }
 
-void ColorHistogramFeature::store (ostream & os, int format) const
+void ColorHistogramFeature::store ( ostream & os, int format ) const
 {
-    os << "ColorHistogramFeature "
-       << window_size_x << " "
-       << window_size_y << " "
-       << bin;
+  os << "ColorHistogramFeature "
+  << window_size_x << " "
+  << window_size_y << " "
+  << bin;
 }
 
 void ColorHistogramFeature::clear ()

+ 34 - 37
features/fpfeatures/ColorHistogramFeature.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file ColorHistogramFeature.h
 * @brief simple color histograms
 * @author Erik Rodner
@@ -10,7 +10,7 @@
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
- 
+
 #include "core/basics/Config.h"
 #include "vislearning/cbaselib/Feature.h"
 
@@ -21,44 +21,41 @@ namespace OBJREC {
 class ColorHistogramFeature : public Feature
 {
 
-    protected:
-
-	/** @{ feature parameter */
-	int window_size_x;
-	int window_size_y;
-
-	int bin;
-	/** @} */
-
-	/** @{ parameter for feature generation */
-	int numScales;
-	int numBins;
-	double scaleStep;
-	/** @} */
-
-    public:
-  
-	/** simple constructor */
-	ColorHistogramFeature( const NICE::Config *conf );
-
-	/** internally used by ColorHistogramFeature::explode */
-	ColorHistogramFeature () {};
-      
-	/** simple destructor */
-	virtual ~ColorHistogramFeature();
-     
-	double val( const Example *example ) const;
-	void explode ( FeaturePool & featurePool, bool variableWindow = true ) const;
-	Feature *clone() const;
-	Feature *generateFirstParameter () const;
-
-	void restore (std::istream & is, int format = 0);
-	void store (std::ostream & os, int format = 0) const;
-	void clear ();
-};
+  protected:
+
+    /** @{ feature parameter */
+    int window_size_x;
+    int window_size_y;
+
+    int bin;
+    /** @} */
+
+    /** @{ parameter for feature generation */
+    int numScales;
+    int numBins;
+    double scaleStep;
+    /** @} */
 
+  public:
 
+    /** simple constructor */
+    ColorHistogramFeature ( const NICE::Config *conf );
 
+    /** internally used by ColorHistogramFeature::explode */
+    ColorHistogramFeature () {};
+
+    /** simple destructor */
+    virtual ~ColorHistogramFeature();
+
+    double val ( const Example *example ) const;
+    void explode ( FeaturePool & featurePool, bool variableWindow = true ) const;
+    Feature *clone() const;
+    Feature *generateFirstParameter () const;
+
+    void restore ( std::istream & is, int format = 0 );
+    void store ( std::ostream & os, int format = 0 ) const;
+    void clear ();
+};
 
 } // namespace
 

+ 162 - 174
features/fpfeatures/EOHFeature.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file EOHFeature.cpp
 * @brief edge orientation histograms (Levi and Weiss 2004)
 * @author Erik Rodner
@@ -19,17 +19,17 @@ using namespace NICE;
 
 
 /** simple constructor */
-EOHFeature::EOHFeature( const Config *conf )
+EOHFeature::EOHFeature ( const Config *conf )
 {
-    window_size_x = conf->gI("EOHFeature", "window_size_x", 21 );
-    window_size_y = conf->gI("EOHFeature", "window_size_y", 21 );
-    scaleStep = conf->gD("EOHFeature", "scale_step", sqrt(2) );
-    numScales = conf->gI("EOHFeature", "num_scales", 5 );
-    numBins = conf->gI("EOHFeature", "num_bins", 9 );
-
-    bin  = 0;
-    bin2 = 0;
-    type = EOH_VALUE;
+  window_size_x = conf->gI ( "EOHFeature", "window_size_x", 21 );
+  window_size_y = conf->gI ( "EOHFeature", "window_size_y", 21 );
+  scaleStep = conf->gD ( "EOHFeature", "scale_step", sqrt ( 2 ) );
+  numScales = conf->gI ( "EOHFeature", "num_scales", 5 );
+  numBins = conf->gI ( "EOHFeature", "num_bins", 9 );
+
+  bin  = 0;
+  bin2 = 0;
+  type = EOH_VALUE;
 }
 
 /** simple destructor */
@@ -37,197 +37,185 @@ EOHFeature::~EOHFeature()
 {
 }
 
-double EOHFeature::val( const Example *example ) const
+double EOHFeature::val ( const Example *example ) const
 {
-    const NICE::MultiChannelImageT<double> & img = example->ce->getDChannel (
-	CachedExample::D_INTEGRALEOH );
-
-    int xsize;
-    int ysize;
-    example->ce->getImageSize ( xsize, ysize );
-    int tm_xsize = img.xsize;
-    int tm_ysize = img.ysize;
-
-#if 0
-    int xtl = example->x - window_size_x/2;
-    int ytl = example->y - window_size_y/2;
-    int xrb = example->x + window_size_x/2;
-    int yrb = example->y + window_size_y/2;
-
-    xtl = xtl * tm_xsize / xsize;
-    ytl = ytl * tm_ysize / ysize;
-    xrb = xrb * tm_xsize / xsize;
-    yrb = yrb * tm_ysize / ysize;
-#endif
-
-    
-    int wsx2, wsy2;
-    int xx, yy;
-
-    int exwidth = example->width;
-    if ( exwidth == 0 ) {
-	wsx2 = window_size_x * tm_xsize / (2*xsize);
-	wsy2 = window_size_y * tm_ysize / (2*ysize);
-    } else {
-	int exheight = example->height;
-	wsx2 = exwidth * tm_xsize / (2*xsize);
-	wsy2 = exheight * tm_ysize / (2*ysize);
-    }
-	
-    xx = ( example->x ) * tm_xsize / xsize;
-    yy = ( example->y ) * tm_ysize / ysize;
-    
-    int xtl = xx - wsx2;
-    int ytl = yy - wsy2;
-    int xrb = xx + wsx2;
-    int yrb = yy + wsy2;
+  const NICE::MultiChannelImageT<double> & img = example->ce->getDChannel (
+        CachedExample::D_INTEGRALEOH );
+
+  int xsize;
+  int ysize;
+  example->ce->getImageSize ( xsize, ysize );
+  int tm_xsize = img.width();
+  int tm_ysize = img.height();
+
+  int wsx2, wsy2;
+  int xx, yy;
+
+  int exwidth = example->width;
+  if ( exwidth == 0 ) {
+    wsx2 = window_size_x * tm_xsize / ( 2 * xsize );
+    wsy2 = window_size_y * tm_ysize / ( 2 * ysize );
+  } else {
+    int exheight = example->height;
+    wsx2 = exwidth * tm_xsize / ( 2 * xsize );
+    wsy2 = exheight * tm_ysize / ( 2 * ysize );
+  }
+
+  xx = ( example->x ) * tm_xsize / xsize;
+  yy = ( example->y ) * tm_ysize / ysize;
+
+  int xtl = xx - wsx2;
+  int ytl = yy - wsy2;
+  int xrb = xx + wsx2;
+  int yrb = yy + wsy2;
 
 #define BOUND(x,min,max) (((x)<(min))?(min):((x)>(max)?(max):(x)))
-    xtl = BOUND ( xtl, 0, tm_xsize - 1 );
-    ytl = BOUND ( ytl, 0, tm_ysize - 1 );
-    xrb = BOUND ( xrb, 0, tm_xsize - 1 );
-    yrb = BOUND ( yrb, 0, tm_ysize - 1 );
+  xtl = BOUND ( xtl, 0, tm_xsize - 1 );
+  ytl = BOUND ( ytl, 0, tm_ysize - 1 );
+  xrb = BOUND ( xrb, 0, tm_xsize - 1 );
+  yrb = BOUND ( yrb, 0, tm_ysize - 1 );
 #undef BOUND
 
-    double A,B,C,D;
-
-    assert ( bin < (int)img.numChannels );
-    assert ( img.data[bin] != NULL );
-
-    int kA = xtl + ytl * tm_xsize;
-    int kB = xrb + ytl * tm_xsize;
-    int kC = xtl + yrb * tm_xsize;
-    int kD = xrb + yrb * tm_xsize;
-    A = img.data[bin][ kA ];
-    B = img.data[bin][ kB ];
-    C = img.data[bin][ kC ];
-    D = img.data[bin][ kD ];
-
-    if ( type == EOH_VALUE ) { 
-	int area = (xrb - xtl)*(yrb - ytl);
-	
-	if ( area == 0 ) 
-	    return 0.0;
-	else {        
-	   /* A B 
-	      C D  */
-	    double value = (D - B - C + A) / area;
-
-	    return value;
-	}
-    } else if ( type == EOH_RATIO ) {
-	assert ( bin2 < (int)img.numChannels );
-
-	double val1 =  (D - B - C + A);
-	A = img.data[bin2][ kA ];
-	B = img.data[bin2][ kB ];
-	C = img.data[bin2][ kC ];
-	D = img.data[bin2][ kD ];
-
-	double val2 = ( D - B - C + A );
-
-	return ( val1 + epsilon ) / ( val2 + epsilon );
-    } else if ( type == EOH_DOMINANT_ORIENTATION ) {
-	double val1 =  (D - B - C + A);
-	double sum = val1;
-	for ( int b = 0 ; b < (int)img.numChannels ; b++)
-	{
-	    if ( b == bin ) continue;
-	    A = img.data[b][ kA ];
-	    B = img.data[b][ kB ];
-	    C = img.data[b][ kC ];
-	    D = img.data[b][ kD ];
-	    sum += ( D - B - C + A );
-	}
-
-	return ( val1 + epsilon ) / ( sum + epsilon );
+  double A, B, C, D;
+
+  assert ( bin < ( int ) img.channels() );
+
+  A = img.get ( xtl, ytl, bin );
+  B = img.get ( xrb, ytl, bin );
+  C = img.get ( xtl, yrb, bin );
+  D = img.get ( xrb, yrb, bin );
+
+  if ( type == EOH_VALUE )
+  {
+    int area = ( xrb - xtl ) * ( yrb - ytl );
+
+    if ( area == 0 )
+      return 0.0;
+    else {
+      /* A B
+         C D  */
+      double value = ( D - B - C + A ) / area;
+
+      return value;
+    }
+  }
+  else if ( type == EOH_RATIO )
+  {
+    assert ( bin2 < ( int ) img.channels() );
+
+    double val1 = ( D - B - C + A );
+    A = img.get ( xtl, ytl, bin2 );
+    B = img.get ( xrb, ytl, bin2 );
+    C = img.get ( xtl, yrb, bin2 );
+    D = img.get ( xrb, yrb, bin2 );
+
+    double val2 = ( D - B - C + A );
+
+    return ( val1 + epsilon ) / ( val2 + epsilon );
+  }
+  else if ( type == EOH_DOMINANT_ORIENTATION )
+  {
+    double val1 = ( D - B - C + A );
+    double sum = val1;
+    for ( int b = 0 ; b < ( int ) img.channels() ; b++ )
+    {
+      if ( b == bin ) 
+        continue;
+      A = img.get ( xtl, ytl, b );
+      B = img.get ( xrb, ytl, b );
+      C = img.get ( xtl, yrb, b );
+      D = img.get ( xrb, yrb, b );
+      sum += ( D - B - C + A );
     }
 
-    assert ( 1 == 0 );
+    return ( val1 + epsilon ) / ( sum + epsilon );
+  }
+
+  assert ( 1 == 0 );
 }
 
 void EOHFeature::explode ( FeaturePool & featurePool, bool variableWindow ) const
 {
-    int nScales = (variableWindow ? numScales : 1 );
+  int nScales = ( variableWindow ? numScales : 1 );
 
-    for ( int i = 0 ; i < nScales ; i++ )
+  for ( int i = 0 ; i < nScales ; i++ )
+  {
+    int wsy = window_size_y;
+    int wsx = window_size_x;
+    for ( int _type = 0 ; _type < EOH_NUMTYPES; _type++ )
     {
-	int wsy = window_size_y;
-	int wsx = window_size_x;
-	for ( int _type = 0 ; _type < EOH_NUMTYPES; _type++ )
-	{
-	    if ( (_type == EOH_VALUE) || (_type == EOH_DOMINANT_ORIENTATION) )
-	    {
-		for ( int _bin = 0 ; _bin < numBins ; _bin++ )
-		{
-		    EOHFeature *f = new EOHFeature();
-		    f->window_size_x = wsx;
-		    f->window_size_y = wsy;
-		    f->bin = _bin;
-		    f->type = _type;
-		    featurePool.addFeature ( f, 1.0 / ( EOH_NUMTYPES * numBins * nScales ) ); 
-		}
-	    }
-	    
-	    if ( (_type == EOH_RATIO) )
-	    {
-		for ( int _bin = 0 ; _bin < numBins ; _bin++ )
-		{
-		    for ( int _bin2 = 0 ; _bin2 < numBins ; _bin2++ )
-		    {
-			if ( bin == bin2 ) continue;
-
-			EOHFeature *f = new EOHFeature();
-			f->window_size_x = wsx;
-			f->window_size_y = wsy;
-			f->bin = _bin;
-			f->bin2 = _bin2;
-			f->type = _type;
-			featurePool.addFeature ( f, 1.0 / (EOH_NUMTYPES * (numBins - 1) * numBins * nScales ) ); 
-		    }
-		}
-	    }
-	}
-
-	wsx = (int) (scaleStep * wsx);
-	wsy = (int) (scaleStep * wsy);
+      if ( ( _type == EOH_VALUE ) || ( _type == EOH_DOMINANT_ORIENTATION ) )
+      {
+        for ( int _bin = 0 ; _bin < numBins ; _bin++ )
+        {
+          EOHFeature *f = new EOHFeature();
+          f->window_size_x = wsx;
+          f->window_size_y = wsy;
+          f->bin = _bin;
+          f->type = _type;
+          featurePool.addFeature ( f, 1.0 / ( EOH_NUMTYPES * numBins * nScales ) );
+        }
+      }
+
+      if ( ( _type == EOH_RATIO ) )
+      {
+        for ( int _bin = 0 ; _bin < numBins ; _bin++ )
+        {
+          for ( int _bin2 = 0 ; _bin2 < numBins ; _bin2++ )
+          {
+            if ( bin == bin2 ) continue;
+
+            EOHFeature *f = new EOHFeature();
+            f->window_size_x = wsx;
+            f->window_size_y = wsy;
+            f->bin = _bin;
+            f->bin2 = _bin2;
+            f->type = _type;
+            featurePool.addFeature ( f, 1.0 / ( EOH_NUMTYPES * ( numBins - 1 ) * numBins * nScales ) );
+          }
+        }
+      }
     }
+
+    wsx = ( int ) ( scaleStep * wsx );
+    wsy = ( int ) ( scaleStep * wsy );
+  }
 }
 
 Feature *EOHFeature::clone() const
 {
-    EOHFeature *f = new EOHFeature();
-    f->window_size_x = window_size_x;
-    f->window_size_y = window_size_y;
-    f->bin = bin;
-    f->bin2 = bin2;
-    f->type = type;
-
-    return f;
+  EOHFeature *f = new EOHFeature();
+  f->window_size_x = window_size_x;
+  f->window_size_y = window_size_y;
+  f->bin = bin;
+  f->bin2 = bin2;
+  f->type = type;
+
+  return f;
 }
 
 Feature *EOHFeature::generateFirstParameter () const
 {
-    return clone();
+  return clone();
 }
 
-void EOHFeature::restore (istream & is, int format)
+void EOHFeature::restore ( istream & is, int format )
 {
-    is >> window_size_x;
-    is >> window_size_y;
-    is >> type;
-    is >> bin;
-    is >> bin2;
+  is >> window_size_x;
+  is >> window_size_y;
+  is >> type;
+  is >> bin;
+  is >> bin2;
 }
 
-void EOHFeature::store (ostream & os, int format) const
+void EOHFeature::store ( ostream & os, int format ) const
 {
-    os << "EOHFEATURE "
-       << window_size_x << " "
-       << window_size_y << " "
-       << type << " "
-       << bin << " "
-       << bin2;
+  os << "EOHFEATURE "
+  << window_size_x << " "
+  << window_size_y << " "
+  << type << " "
+  << bin << " "
+  << bin2;
 }
 
 void EOHFeature::clear ()

+ 49 - 46
features/fpfeatures/EOHFeature.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file EOHFeature.h
 * @brief edge orientation histogram (Levi and Weiss, 2004)
 * @author Erik Rodner
@@ -10,7 +10,7 @@
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
- 
+
 #include "core/basics/Config.h"
 #include "vislearning/cbaselib/Feature.h"
 
@@ -21,50 +21,53 @@ namespace OBJREC {
 class EOHFeature : public Feature
 {
 
-    protected:
-
-	enum {
-	    EOH_VALUE = 0,
-	    EOH_RATIO,
-	    EOH_DOMINANT_ORIENTATION,
-	    EOH_NUMTYPES
-	};
-
-	/** @{ feature parameter */
-	int window_size_x;
-	int window_size_y;
-	int bin;
-	int bin2; // used for EOH_RATIO
-	int type;
-	/** @} */
-
-
-	/** @{ parameter for feature generation */
-	int numScales;
-	int numBins;
-	double scaleStep;
-	int maxdepth;
-	/** @} */
-
-    public:
-  
-	/** simple constructor */
-	EOHFeature( const NICE::Config *conf );
-
-	/** internally used by EOHFeature::explode */
-	EOHFeature () { bin = bin2 = 0; type = EOH_VALUE; };
-      
-	/** simple destructor */
-	virtual ~EOHFeature();
-     
-	double val( const Example *example ) const;
-	void explode ( FeaturePool & featurePool, bool variableWindow = true ) const;
-	Feature *clone() const;
-	Feature *generateFirstParameter () const;
-
-	void restore (std::istream & is, int format = 0);
-	void store (std::ostream & os, int format = 0) const;
-	void clear ();
+  protected:
+
+    enum {
+      EOH_VALUE = 0,
+      EOH_RATIO,
+      EOH_DOMINANT_ORIENTATION,
+      EOH_NUMTYPES
+    };
+
+    /** @{ feature parameter */
+    int window_size_x;
+    int window_size_y;
+    int bin;
+    int bin2; // used for EOH_RATIO
+    int type;
+    /** @} */
+
+
+    /** @{ parameter for feature generation */
+    int numScales;
+    int numBins;
+    double scaleStep;
+    int maxdepth;
+    /** @} */
+
+  public:
+
+    /** simple constructor */
+    EOHFeature ( const NICE::Config *conf );
+
+    /** internally used by EOHFeature::explode */
+    EOHFeature () {
+      bin = bin2 = 0;
+      type = EOH_VALUE;
+    };
+
+    /** simple destructor */
+    virtual ~EOHFeature();
+
+    double val ( const Example *example ) const;
+    void explode ( FeaturePool & featurePool, bool variableWindow = true ) const;
+    Feature *clone() const;
+    Feature *generateFirstParameter () const;
+
+    void restore ( std::istream & is, int format = 0 );
+    void store ( std::ostream & os, int format = 0 ) const;
+    void clear ();
 };
 
 

+ 57 - 51
features/fpfeatures/FIGradients.cpp

@@ -8,67 +8,73 @@ using namespace NICE;
 using namespace std;
 
 void FIGradients::buildEOHMap ( CachedExample *ce,
-				int subsamplex, int subsampley,
-				int numBins, bool usesigned )
+                                int subsamplex, int subsampley,
+                                int numBins, bool usesigned )
 {
-    int xsize;
-    int ysize;
-    ce->getImageSize ( xsize, ysize );
-    int xsize_s = xsize / subsamplex;
-    int ysize_s = ysize / subsampley;
+  int xsize;
+  int ysize;
+  ce->getImageSize ( xsize, ysize );
+  int xsize_s = xsize / subsamplex;
+  int ysize_s = ysize / subsampley;
 
-    NICE::MultiChannelImageT<double> & eohimg = ce->getDChannel ( CachedExample::D_EOH );
-    eohimg.reInit ( xsize_s, ysize_s, numBins, true );
-    
-    double *gradient = new double[xsize*ysize];
-    int *dir = new int[xsize*ysize];
+  NICE::MultiChannelImageT<double> & eohimg = ce->getDChannel ( CachedExample::D_EOH );
+  eohimg.reInit ( xsize_s, ysize_s, numBins);
 
-    if ( ce->colorInformationAvailable() ) {
-	NICE::MultiChannelImageT<int> & colorimg = ce->getIChannel ( CachedExample::I_COLOR );
-	const int *r = colorimg.data[0];
-	const int *g = colorimg.data[1];
-	const int *b = colorimg.data[2];
-	FastFilter::calcColorGradient ( r,g,b,xsize,ysize,
-			    gradient, dir, numBins, usesigned );
-    } else {
-	NICE::MultiChannelImageT<int> & grayvalues = ce->getIChannel ( CachedExample::I_GRAYVALUES );
-	const int *gr = grayvalues.data[0];
-	FastFilter::calcGradient ( gr, xsize, ysize, gradient, dir, numBins, usesigned );
-    }
+  double *gradient = new double[xsize*ysize];
+  int *dir = new int[xsize*ysize];
+
+  if ( ce->colorInformationAvailable() ) {
+    NICE::MultiChannelImageT<int> & colorimg = ce->getIChannel ( CachedExample::I_COLOR );
+    int **data = colorimg.getDataPointer();
+    const int *r = data[0];
+    const int *g = data[1];
+    const int *b = data[2];
+    FastFilter::calcColorGradient ( r, g, b, xsize, ysize,
+                                    gradient, dir, numBins, usesigned );
+  } else {
+    NICE::MultiChannelImageT<int> & grayvalues = ce->getIChannel ( CachedExample::I_GRAYVALUES );
+    int **data = grayvalues.getDataPointer();
+    const int *gr = data[0];
+    FastFilter::calcGradient ( gr, xsize, ysize, gradient, dir, numBins, usesigned );
+  }
 
-    eohimg.setAll ( 0 );
+  eohimg.setAll ( 0 );
+  double **data = eohimg.getDataPointer();
+  long korig = 0;
+  for ( int y = 0 ; y < ysize ; y++ )
+    for ( int x = 0 ; x < xsize ; x++, korig++ )
+    {
+      int xs = x / subsamplex;
+      int ys = y / subsampley;
 
-    long korig = 0;
-    for ( int y = 0 ; y < ysize ; y++ )
-	for ( int x = 0 ; x < xsize ; x++,korig++ )
-	{
-	    int xs = x / subsamplex;
-	    int ys = y / subsampley;
+      if ( xs >= xsize_s ) xs = xsize_s - 1;
+      if ( xs < 0 ) xs = 0;
+      if ( ys >= ysize_s ) ys = ysize_s - 1;
+      if ( ys < 0 ) ys = 0;
+      int k = xs + ys * xsize_s;
+      int val = dir[korig];
+      double strength = gradient[korig];
 
-	    if ( xs >= xsize_s ) xs = xsize_s-1;
-	    if ( xs < 0 ) xs = 0;
-	    if ( ys >= ysize_s ) ys = ysize_s-1;
-	    if ( ys < 0 ) ys = 0;
-	    int k = xs + ys*xsize_s;
-	    int val = dir[korig];
-	    double strength = gradient[korig];
+      assert ( val < eohimg.channels() );
 
-	    assert ( val < eohimg.numChannels );
-	    eohimg.data[val][k] += strength;
+      data[val][k] += strength;
 
-	    if ( !finite(eohimg.data[val][k]) ) {
-		fprintf (stderr, "EOH Image failed: %f\n", eohimg.data[val][k]);
-		exit(-1);
-	    }
-	}
+      if ( !finite ( data[val][k] ) ) {
+        fprintf ( stderr, "EOH Image failed: %f\n", data[val][k] );
+        exit ( -1 );
+      }
+    }
 
-    delete [] gradient;
-    delete [] dir;
+  delete [] gradient;
+  delete [] dir;
 
-    NICE::MultiChannelImageT<double> & eohintimg = ce->getDChannel ( CachedExample::D_INTEGRALEOH );
-    eohintimg.reInit ( xsize_s, ysize_s, numBins, true );
-    for ( uint i = 0 ; i < (uint)numBins ; i++ )
-	GenericImageTools::calcIntegralImage ( eohintimg.data[i], eohimg.data[i], xsize_s, ysize_s );
+  NICE::MultiChannelImageT<double> & eohintimg = ce->getDChannel ( CachedExample::D_INTEGRALEOH );
+  eohintimg.reInit ( xsize_s, ysize_s, numBins );
+  for ( uint i = 0 ; i < ( uint ) numBins ; i++ )
+  {
+    ImageT<double> tmp = eohimg[i];
+    GenericImageTools::calcIntegralImage ( tmp, tmp, xsize_s, ysize_s );
+  }
 
 }
 

+ 8 - 8
features/fpfeatures/FIGradients.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file FIGradients.h
 * @brief feature images storing gradient information
 * @author Erik Rodner
@@ -15,14 +15,14 @@ namespace OBJREC {
 
 class FIGradients {
 
-    public:
+  public:
 
-    static void buildEOHMap ( 
-	    CachedExample *ce,
-	    int subsamplex, 
-	    int subsampley,
-	    int numBins, 
-	    bool usesigned );
+    static void buildEOHMap (
+      CachedExample *ce,
+      int subsamplex,
+      int subsampley,
+      int numBins,
+      bool usesigned );
 
 };
 

+ 80 - 80
features/fpfeatures/FIHistograms.cpp

@@ -9,102 +9,102 @@ using namespace OBJREC;
 using namespace NICE;
 using namespace std;
 
-void FIHistograms::buildHSVMap ( 
-	    CachedExample *ce,
-	    int subsamplex, 
-	    int subsampley,
-	    int numBinsH, 
-	    int numBinsS,
-	    int numBinsV )
+void FIHistograms::buildHSVMap (
+  CachedExample *ce,
+  int subsamplex,
+  int subsampley,
+  int numBinsH,
+  int numBinsS,
+  int numBinsV )
 {
-    // build HSV image
-    // discrete !!
-    // build integral images
-
-    int numBins = numBinsH*numBinsS*numBinsV;
-    int xsize;
-    int ysize;
-    ce->getImageSize ( xsize, ysize );
-    
-    int xsize_s = xsize / subsamplex;
-    int ysize_s = ysize / subsampley;
-
-    if ( ! ce->colorInformationAvailable() ) {
-	fprintf (stderr, "FIHistograms: No color information available !\n");
-	exit(-1);
-    }
-
-    NICE::MultiChannelImageT<int> & colorimg = ce->getIChannel ( CachedExample::I_COLOR );
-    assert ( colorimg.numChannels == 3 );
-
-    NICE::MultiChannelImageT<double> hsvimg ( xsize, ysize, colorimg.numChannels, true );
+  // build HSV image
+  // discrete !!
+  // build integral images
 
-    ColorSpace::convert ( hsvimg, colorimg, 
-			  ColorSpace::COLORSPACE_HSL, 
-			  ColorSpace::COLORSPACE_RGB,
-			  1.0, 255.0 );
+  int numBins = numBinsH * numBinsS * numBinsV;
+  int xsize;
+  int ysize;
+  ce->getImageSize ( xsize, ysize );
 
-    int *discretecolor = new int [ xsize * ysize ];
+  int xsize_s = xsize / subsamplex;
+  int ysize_s = ysize / subsampley;
 
-    long k = 0;
-    for ( int y = 0 ; y < hsvimg.ysize ; y++ )
-	for ( int x = 0 ; x < hsvimg.xsize ; x++,k++ )
-	{
-	    double h = hsvimg.data[0][k];
-	    double s = hsvimg.data[1][k];
-	    double v = hsvimg.data[2][k];
+  if ( ! ce->colorInformationAvailable() ) {
+    fprintf ( stderr, "FIHistograms: No color information available !\n" );
+    exit ( -1 );
+  }
 
-	    int hbin = (int)(numBinsH * h);
-	    if ( hbin >= numBinsH ) hbin = numBinsH - 1;
-	    int sbin = (int)(numBinsS * s);
-	    if ( sbin >= numBinsS ) sbin = numBinsS - 1;
-	    int vbin = (int)(numBinsV * v);
-	    if ( vbin >= numBinsV ) vbin = numBinsV - 1;
+  NICE::MultiChannelImageT<int> & colorimg = ce->getIChannel ( CachedExample::I_COLOR );
+  assert ( colorimg.channels() == 3 );
 
-	    int bin = ( hbin*numBinsS + sbin )*numBinsV + vbin;
+  NICE::MultiChannelImageT<double> hsvimg ( xsize, ysize, colorimg.channels() );
 
-	    discretecolor[k] = bin;
-	}
+  ColorSpace::convert ( hsvimg, colorimg,
+                        ColorSpace::COLORSPACE_HSL,
+                        ColorSpace::COLORSPACE_RGB,
+                        1.0, 255.0 );
 
-    hsvimg.freeData();
+  int *discretecolor = new int [ xsize * ysize ];
 
-    NICE::MultiChannelImageT<double> & colorhist = ce->getDChannel ( CachedExample::D_INTEGRALCOLOR );
-    colorhist.reInit ( xsize_s, ysize_s, numBins, true );
-    colorhist.setAll ( 0 );
+  long k = 0;
+  for ( int y = 0 ; y < hsvimg.height() ; y++ )
+    for ( int x = 0 ; x < hsvimg.width() ; x++, k++ )
+    {
+      double h = hsvimg.get(x,y,0);
+      double s = hsvimg.get(x,y,1);
+      double v = hsvimg.get(x,y,2);
 
-    long korig = 0;
-    for ( int y = 0 ; y < ysize ; y++ )
-	for ( int x = 0 ; x < xsize ; x++,korig++ )
-	{
-	    int xs = x / subsamplex;
-	    int ys = y / subsampley;
+      int hbin = ( int ) ( numBinsH * h );
+      if ( hbin >= numBinsH ) hbin = numBinsH - 1;
+      int sbin = ( int ) ( numBinsS * s );
+      if ( sbin >= numBinsS ) sbin = numBinsS - 1;
+      int vbin = ( int ) ( numBinsV * v );
+      if ( vbin >= numBinsV ) vbin = numBinsV - 1;
 
-	    if ( xs >= xsize_s ) xs = xsize_s-1;
-	    if ( xs < 0 ) xs = 0;
-	    if ( ys >= ysize_s ) ys = ysize_s-1;
-	    if ( ys < 0 ) ys = 0;
-	    int k = xs + ys*xsize_s;
-	    int val = discretecolor[korig];
+      int bin = ( hbin * numBinsS + sbin ) * numBinsV + vbin;
 
-	    if ( val >= colorhist.numChannels )
-	    {
-		fprintf (stderr, "v %d nc %d\n", val, colorhist.numChannels );
-	    }
-	    colorhist.data[val][k] += 1;
+      discretecolor[k] = bin;
+    }
 
-	    if ( !finite(colorhist.data[val][k]) ) {
-		fprintf (stderr, "EOH Image failed: %f\n", colorhist.data[val][k]);
-		exit(-1);
-	    }
-	}
+  hsvimg.freeData();
+
+  NICE::MultiChannelImageT<double> & colorhist = ce->getDChannel ( CachedExample::D_INTEGRALCOLOR );
+  colorhist.reInit ( xsize_s, ysize_s, numBins);
+  colorhist.setAll ( 0 );
+
+  long korig = 0;
+  for ( int y = 0 ; y < ysize ; y++ )
+    for ( int x = 0 ; x < xsize ; x++, korig++ )
+    {
+      int xs = x / subsamplex;
+      int ys = y / subsampley;
+
+      if ( xs >= xsize_s ) xs = xsize_s - 1;
+      if ( xs < 0 ) xs = 0;
+      if ( ys >= ysize_s ) ys = ysize_s - 1;
+      if ( ys < 0 ) ys = 0;
+      int k = xs + ys * xsize_s;
+      int val = discretecolor[korig];
+
+      if ( val >= colorhist.channels() )
+      {
+        fprintf ( stderr, "v %d nc %d\n", val, colorhist.channels() );
+      }
+      colorhist[val](x,y) += 1;
+
+      if ( !finite ( colorhist[val](x,y) ) ) {
+        fprintf ( stderr, "EOH Image failed: %f\n", colorhist[val](x,y) );
+        exit ( -1 );
+      }
+    }
 
-    delete [] discretecolor;
+  delete [] discretecolor;
 
-    fprintf (stderr, "Calculating Integral Images\n");
+  fprintf ( stderr, "Calculating Integral Images\n" );
 
-    for ( uint i = 0 ; i < colorhist.numChannels ; i++ )
-	colorhist.calcIntegral ( i );
+  for ( uint i = 0 ; i < colorhist.channels() ; i++ )
+    colorhist.calcIntegral ( i );
 
-    fprintf (stderr, "FIGradients: finished\n");
+  fprintf ( stderr, "FIGradients: finished\n" );
 
 }

+ 191 - 187
features/fpfeatures/HOGFeature.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file HOGFeature.cpp
 * @brief histogram of oriented gradients ( dalal and triggs )
 * @author Erik Rodner
@@ -19,17 +19,17 @@ using namespace NICE;
 const double epsilon = 10e-8;
 
 /** simple constructor */
-HOGFeature::HOGFeature( const Config *conf )
+HOGFeature::HOGFeature ( const Config *conf )
 {
-    window_size_x = conf->gI("HOGFeature", "window_size_x", 21 );
-    window_size_y = conf->gI("HOGFeature", "window_size_y", 21 );
-    scaleStep = conf->gD("HOGFeature", "scale_step", sqrt(2) );
-    numScales = conf->gI("HOGFeature", "num_scales", 5 );
-    flexibleGrid = conf->gB("HOGFeature", "flexible_grid", false );
-
-    numBins = conf->gI("HOGFeature", "num_bins", 9 );
-    cellcountx = conf->gI("HOGFeature", "cellcountx", 10 );
-    cellcounty = conf->gI("HOGFeature", "cellcounty", 10 );
+  window_size_x = conf->gI ( "HOGFeature", "window_size_x", 21 );
+  window_size_y = conf->gI ( "HOGFeature", "window_size_y", 21 );
+  scaleStep = conf->gD ( "HOGFeature", "scale_step", sqrt ( 2 ) );
+  numScales = conf->gI ( "HOGFeature", "num_scales", 5 );
+  flexibleGrid = conf->gB ( "HOGFeature", "flexible_grid", false );
+
+  numBins = conf->gI ( "HOGFeature", "num_bins", 9 );
+  cellcountx = conf->gI ( "HOGFeature", "cellcountx", 10 );
+  cellcounty = conf->gI ( "HOGFeature", "cellcounty", 10 );
 }
 
 /** simple destructor */
@@ -37,207 +37,211 @@ HOGFeature::~HOGFeature()
 {
 }
 
-double HOGFeature::val( const Example *example ) const
+double HOGFeature::val ( const Example *example ) const
 {
-    const NICE::MultiChannelImageT<double> & img = 
-	example->ce->getDChannel ( CachedExample::D_INTEGRALEOH );
-    int tm_xsize = img.xsize;
-    int tm_ysize = img.ysize;
-
-    int xsize;
-    int ysize;
-    example->ce->getImageSize ( xsize, ysize );
-
-    /** without overlap: normalized cell and bin **/
-
-    int wsx2, wsy2;
-    int exwidth = example->width;
-    if ( exwidth == 0 ) {
-	wsx2 = window_size_x * tm_xsize / (2*xsize);
-	wsy2 = window_size_y * tm_ysize / (2*ysize);
-    } else {
-	int exheight = example->height;
-	wsx2 = exwidth * tm_xsize / (2*xsize);
-	wsy2 = exheight * tm_ysize / (2*ysize);
-    }
-	
-    int xx, yy;
-    xx = ( example->x ) * tm_xsize / xsize;
-    yy = ( example->y ) * tm_ysize / ysize;
-
-    assert ( (wsx2 > 0) && (wsy2 > 0) );
-
-    int xtl = xx - wsx2;
-    int ytl = yy - wsy2;
-    int xrb = xx + wsx2;
-    int yrb = yy + wsy2;
+  const NICE::MultiChannelImageT<double> & img =
+    example->ce->getDChannel ( CachedExample::D_INTEGRALEOH );
+  int tm_xsize = img.width();
+  int tm_ysize = img.height();
+
+  int xsize;
+  int ysize;
+  example->ce->getImageSize ( xsize, ysize );
+
+  /** without overlap: normalized cell and bin **/
+
+  int wsx2, wsy2;
+  int exwidth = example->width;
+  if ( exwidth == 0 ) 
+  {
+    wsx2 = window_size_x * tm_xsize / ( 2 * xsize );
+    wsy2 = window_size_y * tm_ysize / ( 2 * ysize );
+  } 
+  else 
+  {
+    int exheight = example->height;
+    wsx2 = exwidth * tm_xsize / ( 2 * xsize );
+    wsy2 = exheight * tm_ysize / ( 2 * ysize );
+  }
+
+  int xx, yy;
+  xx = ( example->x ) * tm_xsize / xsize;
+  yy = ( example->y ) * tm_ysize / ysize;
+
+  assert ( ( wsx2 > 0 ) && ( wsy2 > 0 ) );
+
+  int xtl = xx - wsx2;
+  int ytl = yy - wsy2;
+  int xrb = xx + wsx2;
+  int yrb = yy + wsy2;
 
 #define BOUND(x,min,max) (((x)<(min))?(min):((x)>(max)?(max):(x)))
-    xtl = BOUND ( xtl, 0, tm_xsize - 1 );
-    ytl = BOUND ( ytl, 0, tm_ysize - 1 );
-    xrb = BOUND ( xrb, 0, tm_xsize - 1 );
-    yrb = BOUND ( yrb, 0, tm_ysize - 1 );
+  xtl = BOUND ( xtl, 0, tm_xsize - 1 );
+  ytl = BOUND ( ytl, 0, tm_ysize - 1 );
+  xrb = BOUND ( xrb, 0, tm_xsize - 1 );
+  yrb = BOUND ( yrb, 0, tm_ysize - 1 );
 #undef BOUND
 
-    double stepx = (xrb - xtl) / (double)( cellcountx );
-    double stepy = (yrb - ytl) / (double)( cellcounty );
-    int cxtl = (int)(xtl + stepx*cellx1);
-    int cytl = (int)(ytl + stepy*celly1);
-    int cxrb = (int)(xtl + stepx*cellx2);
-    int cyrb = (int)(ytl + stepy*celly2);
-
-    if ( cxrb <= cxtl ) cxrb = cxtl+1;
-    if ( cyrb <= cytl ) cyrb = cytl+1;
-
-    double A,B,C,D;
-
-    assert ( bin < (int)img.numChannels );
-    assert ( img.data[bin] != NULL );
-
-    if ( (cxtl < 0) || (cxtl >= tm_xsize) )
-    {
-	fprintf (stderr, "cellcountx %d cellcounty %d\n", cellcountx, cellcounty );
-	fprintf (stderr, "cxtl %d tm_xsize %d xsize %d\n", cxtl, tm_xsize, xsize );
-	fprintf (stderr, "cellx1 %d stepx %f xtl %d xrb %d\n", cellx1, stepx, xtl, xrb );
-    }
-    if ( (cxrb < 0) || (cxrb >= tm_xsize) )
-    {
-	fprintf (stderr, "cellcountx %d cellcounty %d\n", cellcountx, cellcounty );
-	fprintf (stderr, "cxrb %d tm_xsize %d xsize %d\n", cxrb, tm_xsize, xsize );
-	fprintf (stderr, "cellx1 %d stepx %f xtl %d xrb %d\n", cellx1, stepx, xtl, xrb );
-    }
-    if ( (cytl < 0) || (cytl >= tm_ysize) )
-    {
-	fprintf (stderr, "cellcountx %d cellcounty %d\n", cellcountx, cellcounty );
-	fprintf (stderr, "cytl %d tm_ysize %d ysize %d\n", cytl, tm_ysize, ysize );
-	fprintf (stderr, "celly1 %d stepy %f ytl %d yrb %d\n", celly1, stepy, ytl, yrb );
-    }
-    if ( (cyrb < 0) || (cyrb >= tm_ysize) )
-    {
-	fprintf (stderr, "cellcountx %d cellcounty %d\n", cellcountx, cellcounty );
-	fprintf (stderr, "cyrb %d tm_ysize %d ysize %d\n", cyrb, tm_ysize, ysize );
-	fprintf (stderr, "celly1 %d stepy %f ytl %d yrb %d\n", celly1, stepy, ytl, yrb );
-    }
-
-    long kA = cxtl + cytl * tm_xsize;
-    long kB = cxrb + cytl * tm_xsize;
-    long kC = cxtl + cyrb * tm_xsize;
-    long kD = cxrb + cyrb * tm_xsize;
-    A = img.data[bin][ kA ];
-    B = img.data[bin][ kB ];
-    C = img.data[bin][ kC ];
-    D = img.data[bin][ kD ];
-
-    double val1 =  (D - B - C + A);
-    double sum = val1*val1;
-	for ( int b = 0 ; b < (int)img.numChannels ; b++)
-	{
-		if ( b == bin ) continue;
-		A = img.data[b][ kA ];
-		B = img.data[b][ kB ];
-		C = img.data[b][ kC ];
-		D = img.data[b][ kD ];
-		double val = ( D - B - C + A );
-		sum += val*val;
-	}
-    // FIXME: maybe L_1 normalization is sufficient
-    sum = sqrt(sum);
-    return ( val1 + epsilon ) / ( sum + epsilon );
+  double stepx = ( xrb - xtl ) / ( double ) ( cellcountx );
+  double stepy = ( yrb - ytl ) / ( double ) ( cellcounty );
+  int cxtl = ( int ) ( xtl + stepx * cellx1 );
+  int cytl = ( int ) ( ytl + stepy * celly1 );
+  int cxrb = ( int ) ( xtl + stepx * cellx2 );
+  int cyrb = ( int ) ( ytl + stepy * celly2 );
+
+  if ( cxrb <= cxtl ) cxrb = cxtl + 1;
+  if ( cyrb <= cytl ) cyrb = cytl + 1;
+
+  double A, B, C, D;
+
+  assert ( bin < ( int ) img.channels() );
+
+  if ( ( cxtl < 0 ) || ( cxtl >= tm_xsize ) )
+  {
+    fprintf ( stderr, "cellcountx %d cellcounty %d\n", cellcountx, cellcounty );
+    fprintf ( stderr, "cxtl %d tm_xsize %d xsize %d\n", cxtl, tm_xsize, xsize );
+    fprintf ( stderr, "cellx1 %d stepx %f xtl %d xrb %d\n", cellx1, stepx, xtl, xrb );
+  }
+  if ( ( cxrb < 0 ) || ( cxrb >= tm_xsize ) )
+  {
+    fprintf ( stderr, "cellcountx %d cellcounty %d\n", cellcountx, cellcounty );
+    fprintf ( stderr, "cxrb %d tm_xsize %d xsize %d\n", cxrb, tm_xsize, xsize );
+    fprintf ( stderr, "cellx1 %d stepx %f xtl %d xrb %d\n", cellx1, stepx, xtl, xrb );
+  }
+  if ( ( cytl < 0 ) || ( cytl >= tm_ysize ) )
+  {
+    fprintf ( stderr, "cellcountx %d cellcounty %d\n", cellcountx, cellcounty );
+    fprintf ( stderr, "cytl %d tm_ysize %d ysize %d\n", cytl, tm_ysize, ysize );
+    fprintf ( stderr, "celly1 %d stepy %f ytl %d yrb %d\n", celly1, stepy, ytl, yrb );
+  }
+  if ( ( cyrb < 0 ) || ( cyrb >= tm_ysize ) )
+  {
+    fprintf ( stderr, "cellcountx %d cellcounty %d\n", cellcountx, cellcounty );
+    fprintf ( stderr, "cyrb %d tm_ysize %d ysize %d\n", cyrb, tm_ysize, ysize );
+    fprintf ( stderr, "celly1 %d stepy %f ytl %d yrb %d\n", celly1, stepy, ytl, yrb );
+  }
+
+  long kA = cxtl + cytl * tm_xsize;
+  long kB = cxrb + cytl * tm_xsize;
+  long kC = cxtl + cyrb * tm_xsize;
+  long kD = cxrb + cyrb * tm_xsize;
+
+  A = img.get ( cxtl, cytl, bin );
+  B = img.get ( cxrb, cytl, bin );
+  C = img.get ( cxtl, cyrb, bin );
+  D = img.get ( cxrb, cyrb, bin );
+
+  double val1 = ( D - B - C + A );
+  double sum = val1 * val1;
+  for ( int b = 0 ; b < ( int ) img.channels() ; b++ )
+  {
+    if ( b == bin ) 
+      continue;
+    A = img.get ( cxtl, cytl, b );
+    B = img.get ( cxrb, cytl, b );
+    C = img.get ( cxtl, cyrb, b );
+    D = img.get ( cxrb, cyrb, b );
+    double val = ( D - B - C + A );
+    sum += val * val;
+  }
+  // FIXME: maybe L_1 normalization is sufficient
+  sum = sqrt ( sum );
+  return ( val1 + epsilon ) / ( sum + epsilon );
 }
 
 void HOGFeature::explode ( FeaturePool & featurePool, bool variableWindow ) const
 {
-    int nScales = (variableWindow ? numScales : 1 );
-
-    double weight = 1.0 / ( numBins * nScales );
-
-    if ( flexibleGrid ) 
-	weight *= 4.0 / ( cellcountx * (cellcountx - 1) * (cellcounty - 1) * cellcounty );
-    else
-	weight *= 1.0 / (cellcountx * cellcounty);
-
-    for ( int i = 0 ; i < nScales ; i++ )
-    {
-	int wsy = window_size_y;
-	int wsx = window_size_x;
-	for ( int _cellx1 = 0 ; _cellx1 < cellcountx ; _cellx1++ )
-	    for ( int _celly1 = 0 ; _celly1 < cellcounty ; _celly1++ )
-		for ( int _cellx2 = _cellx1+1 ; 
-			  _cellx2 < (flexibleGrid ? cellcountx : _cellx1+2) ; 
-			  _cellx2++ )
-		    for ( int _celly2 = _celly1+1 ; 
-			      _celly2 < (flexibleGrid ? cellcounty : 
-			      _celly1+2) ; _celly2++ )
-			for ( int _bin = 0 ; _bin < numBins ; _bin++ )
-			{
-			    HOGFeature *f = new HOGFeature();
-			    f->window_size_x = wsx;
-			    f->window_size_y = wsy;
-			    f->bin = _bin;
-			    f->cellx1 = _cellx1;
-			    f->celly1 = _celly1;
-			    f->cellx2 = _cellx2;
-			    f->celly2 = _celly2;
-			    f->cellcountx = cellcountx;
-			    f->cellcounty = cellcounty;
-			    featurePool.addFeature ( f, weight ); 
-			}
-	wsx = (int) (scaleStep * wsx);
-	wsy = (int) (scaleStep * wsy);
-    }
+  int nScales = ( variableWindow ? numScales : 1 );
+
+  double weight = 1.0 / ( numBins * nScales );
+
+  if ( flexibleGrid )
+    weight *= 4.0 / ( cellcountx * ( cellcountx - 1 ) * ( cellcounty - 1 ) * cellcounty );
+  else
+    weight *= 1.0 / ( cellcountx * cellcounty );
+
+  for ( int i = 0 ; i < nScales ; i++ )
+  {
+    int wsy = window_size_y;
+    int wsx = window_size_x;
+    for ( int _cellx1 = 0 ; _cellx1 < cellcountx ; _cellx1++ )
+      for ( int _celly1 = 0 ; _celly1 < cellcounty ; _celly1++ )
+        for ( int _cellx2 = _cellx1 + 1 ;
+              _cellx2 < ( flexibleGrid ? cellcountx : _cellx1 + 2 ) ;
+              _cellx2++ )
+          for ( int _celly2 = _celly1 + 1 ;
+                _celly2 < ( flexibleGrid ? cellcounty :
+                            _celly1 + 2 ) ; _celly2++ )
+            for ( int _bin = 0 ; _bin < numBins ; _bin++ )
+            {
+              HOGFeature *f = new HOGFeature();
+              f->window_size_x = wsx;
+              f->window_size_y = wsy;
+              f->bin = _bin;
+              f->cellx1 = _cellx1;
+              f->celly1 = _celly1;
+              f->cellx2 = _cellx2;
+              f->celly2 = _celly2;
+              f->cellcountx = cellcountx;
+              f->cellcounty = cellcounty;
+              featurePool.addFeature ( f, weight );
+            }
+    wsx = ( int ) ( scaleStep * wsx );
+    wsy = ( int ) ( scaleStep * wsy );
+  }
 }
 
 Feature *HOGFeature::clone() const
 {
-    HOGFeature *f = new HOGFeature();
-    f->window_size_x = window_size_x;
-    f->window_size_y = window_size_y;
-    f->bin = bin;
-    f->cellx1 = cellx1;
-    f->celly1 = celly1;
-    f->cellx2 = cellx2;
-    f->celly2 = celly2;
-    f->cellcountx = cellcountx;
-    f->cellcounty = cellcounty;
-    f->flexibleGrid = flexibleGrid;
-
-    return f;
+  HOGFeature *f = new HOGFeature();
+  f->window_size_x = window_size_x;
+  f->window_size_y = window_size_y;
+  f->bin = bin;
+  f->cellx1 = cellx1;
+  f->celly1 = celly1;
+  f->cellx2 = cellx2;
+  f->celly2 = celly2;
+  f->cellcountx = cellcountx;
+  f->cellcounty = cellcounty;
+  f->flexibleGrid = flexibleGrid;
+
+  return f;
 }
 
 Feature *HOGFeature::generateFirstParameter () const
 {
-    return clone();
+  return clone();
 }
 
-void HOGFeature::restore (istream & is, int format)
+void HOGFeature::restore ( istream & is, int format )
 {
-    is >> window_size_x;
-    is >> window_size_y;
-    is >> bin;
-    is >> cellx1;
-    is >> celly1;
+  is >> window_size_x;
+  is >> window_size_y;
+  is >> bin;
+  is >> cellx1;
+  is >> celly1;
 
-    is >> cellx2;
-    is >> celly2;
+  is >> cellx2;
+  is >> celly2;
 
-    is >> cellcountx;
-    is >> cellcounty;
+  is >> cellcountx;
+  is >> cellcounty;
 }
 
-void HOGFeature::store (ostream & os, int format) const
+void HOGFeature::store ( ostream & os, int format ) const
 {
-    os << "HOGFEATURE "
-       << window_size_x << " "
-       << window_size_y << " "
-       << bin << " "
-       << cellx1 << " "
-       << celly1 << " ";
-
-   os << cellx2 << " "
-      << celly2 << " ";
-
-    os << cellcountx << " "
-       << cellcounty;
+  os << "HOGFEATURE "
+  << window_size_x << " "
+  << window_size_y << " "
+  << bin << " "
+  << cellx1 << " "
+  << celly1 << " ";
+
+  os << cellx2 << " "
+  << celly2 << " ";
+
+  os << cellcountx << " "
+  << cellcounty;
 }
 
 void HOGFeature::clear ()

+ 8 - 4
features/fpfeatures/HaarFeature.cpp

@@ -89,9 +89,9 @@ 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;
+  //const long *integralImage = img.data[0];
+  int xsize = img.width();
+  int ysize = img.height();
 
   int x = example->x;
   int y = example->y;
@@ -127,6 +127,7 @@ double HaarFeature::val ( const Example *example ) const
   assert ( pos1 >= 0 );
   assert ( pos2 >= 0 );
 
+#if 0
   double value;
   if ( type == HaarFeature::HAARTYPE_HORIZONTAL )
   {
@@ -193,7 +194,10 @@ double HaarFeature::val ( const Example *example ) const
   }
 
   assert ( finite ( value ) );
-
+#else
+  throw("not yet adapted for new MultiChannelImageT!");
+  double value = 0.0;
+#endif
   return value;
 }
 

+ 163 - 168
features/fpfeatures/HistFeature.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file HistFeature.cpp
 * @brief histogram integral feature
 * @author Erik Rodner
@@ -21,22 +21,22 @@ using namespace NICE;
 const double epsilon = 10e-8;
 
 /** simple constructor */
-HistFeature::HistFeature( const Config *conf, 
-			  const std::string & section, 
-			  int _histtype,
-			  int _numBins )
+HistFeature::HistFeature ( const Config *conf,
+                           const std::string & section,
+                           int _histtype,
+                           int _numBins )
 {
-    window_size_x = conf->gI(section, "window_size_x", 21 );
-    window_size_y = conf->gI(section, "window_size_y", 21 );
-    scaleStep = conf->gD(section, "scale_step", sqrt(2) );
-    numScales = conf->gI(section, "num_scales", 5 );
+  window_size_x = conf->gI ( section, "window_size_x", 21 );
+  window_size_y = conf->gI ( section, "window_size_y", 21 );
+  scaleStep = conf->gD ( section, "scale_step", sqrt ( 2 ) );
+  numScales = conf->gI ( section, "num_scales", 5 );
 
-    flexibleGrid = conf->gB(section, "flexible_grid", false );
+  flexibleGrid = conf->gB ( section, "flexible_grid", false );
 
-    cellcountx = conf->gI(section, "cellcountx", 10 );
-    cellcounty = conf->gI(section, "cellcounty", 10 );
+  cellcountx = conf->gI ( section, "cellcountx", 10 );
+  cellcounty = conf->gI ( section, "cellcounty", 10 );
 
-    histtype = _histtype;
+  histtype = _histtype;
 }
 
 /** simple destructor */
@@ -44,185 +44,180 @@ HistFeature::~HistFeature()
 {
 }
 
-double HistFeature::val( const Example *example ) const
+double HistFeature::val ( const Example *example ) const
 {
-    const NICE::MultiChannelImageT<double> & img = example->ce->getDChannel ( histtype );
-    int tm_xsize = img.xsize;
-    int tm_ysize = img.ysize;
-
-    int xsize;
-    int ysize;
-    example->ce->getImageSize ( xsize, ysize );
-
-    /** without overlap: normalized cell and bin **/
-
-    int wsx2, wsy2;
-    int exwidth = example->width;
-    if ( exwidth == 0 ) {
-	wsx2 = window_size_x * tm_xsize / (2*xsize);
-	wsy2 = window_size_y * tm_ysize / (2*ysize);
-    } else {
-	int exheight = example->height;
-	wsx2 = exwidth * tm_xsize / (2*xsize);
-	wsy2 = exheight * tm_ysize / (2*ysize);
-    }
-	
-    int xx, yy;
-    xx = ( example->x ) * tm_xsize / xsize;
-    yy = ( example->y ) * tm_ysize / ysize;
-
-    assert ( (wsx2 > 0) && (wsy2 > 0) );
-
-    int xtl = xx - wsx2;
-    int ytl = yy - wsy2;
-    int xrb = xx + wsx2;
-    int yrb = yy + wsy2;
+  const NICE::MultiChannelImageT<double> & img = example->ce->getDChannel ( histtype );
+  int tm_xsize = img.width();
+  int tm_ysize = img.height();
+
+  int xsize;
+  int ysize;
+  example->ce->getImageSize ( xsize, ysize );
+
+  /** without overlap: normalized cell and bin **/
+
+  int wsx2, wsy2;
+  int exwidth = example->width;
+  if ( exwidth == 0 ) {
+    wsx2 = window_size_x * tm_xsize / ( 2 * xsize );
+    wsy2 = window_size_y * tm_ysize / ( 2 * ysize );
+  } else {
+    int exheight = example->height;
+    wsx2 = exwidth * tm_xsize / ( 2 * xsize );
+    wsy2 = exheight * tm_ysize / ( 2 * ysize );
+  }
+
+  int xx, yy;
+  xx = ( example->x ) * tm_xsize / xsize;
+  yy = ( example->y ) * tm_ysize / ysize;
+
+  assert ( ( wsx2 > 0 ) && ( wsy2 > 0 ) );
+
+  int xtl = xx - wsx2;
+  int ytl = yy - wsy2;
+  int xrb = xx + wsx2;
+  int yrb = yy + wsy2;
 
 #define BOUND(x,min,max) (((x)<(min))?(min):((x)>(max)?(max):(x)))
-    xtl = BOUND ( xtl, 0, tm_xsize - 1 );
-    ytl = BOUND ( ytl, 0, tm_ysize - 1 );
-    xrb = BOUND ( xrb, 0, tm_xsize - 1 );
-    yrb = BOUND ( yrb, 0, tm_ysize - 1 );
+  xtl = BOUND ( xtl, 0, tm_xsize - 1 );
+  ytl = BOUND ( ytl, 0, tm_ysize - 1 );
+  xrb = BOUND ( xrb, 0, tm_xsize - 1 );
+  yrb = BOUND ( yrb, 0, tm_ysize - 1 );
 #undef BOUND
 
-    double stepx = (xrb - xtl) / (double)( cellcountx );
-    double stepy = (yrb - ytl) / (double)( cellcounty );
-    int cxtl = (int)(xtl + stepx*cellx1);
-    int cytl = (int)(ytl + stepy*celly1);
-    int cxrb = (int)(xtl + stepx*cellx2);
-    int cyrb = (int)(ytl + stepy*celly2);
-
-    if ( cxrb <= cxtl ) cxrb = cxtl+1;
-    if ( cyrb <= cytl ) cyrb = cytl+1;
-
-    double A,B,C,D;
-
-    assert ( bin < (int)img.numChannels );
-    assert ( img.data[bin] != NULL );
-
-    long kA = cxtl + cytl * tm_xsize;
-    long kB = cxrb + cytl * tm_xsize;
-    long kC = cxtl + cyrb * tm_xsize;
-    long kD = cxrb + cyrb * tm_xsize;
-    A = img.data[bin][ kA ];
-    B = img.data[bin][ kB ];
-    C = img.data[bin][ kC ];
-    D = img.data[bin][ kD ];
-
-    double val1 =  (D - B - C + A);
-    double sum = val1*val1;
-    for ( int b = 0 ; b < (int)img.numChannels ; b++)
-    {
-	if ( b == bin ) continue;
-	A = img.data[b][ kA ];
-	B = img.data[b][ kB ];
-	C = img.data[b][ kC ];
-	D = img.data[b][ kD ];
-	double val = ( D - B - C + A );
-
-	if ( normalizationMethod == HISTFEATURE_NORMMETHOD_L2 )
-	    sum += val*val;
-	else if ( normalizationMethod == HISTFEATURE_NORMMETHOD_L1 )
-	    sum += val;
-    }
-    if ( normalizationMethod == HISTFEATURE_NORMMETHOD_L2 )
-	sum = sqrt(sum);
+  double stepx = ( xrb - xtl ) / ( double ) ( cellcountx );
+  double stepy = ( yrb - ytl ) / ( double ) ( cellcounty );
+  int cxtl = ( int ) ( xtl + stepx * cellx1 );
+  int cytl = ( int ) ( ytl + stepy * celly1 );
+  int cxrb = ( int ) ( xtl + stepx * cellx2 );
+  int cyrb = ( int ) ( ytl + stepy * celly2 );
+
+  if ( cxrb <= cxtl ) cxrb = cxtl + 1;
+  if ( cyrb <= cytl ) cyrb = cytl + 1;
+
+  double A, B, C, D;
+
+  assert ( bin < ( int ) img.channels() );
 
-    return ( val1 + epsilon ) / ( sum + epsilon );
+  A = img.get ( cxtl, cytl, bin );
+  B = img.get ( cxrb, cytl, bin );
+  C = img.get ( cxtl, cyrb, bin );
+  D = img.get ( cxrb, cyrb, bin );
+
+  double val1 = ( D - B - C + A );
+  double sum = val1 * val1;
+  for ( int b = 0 ; b < ( int ) img.channels() ; b++ )
+  {
+    if ( b == bin ) continue;
+    A = img.get ( cxtl, cytl, b );
+    B = img.get ( cxrb, cytl, b );
+    C = img.get ( cxtl, cyrb, b );
+    D = img.get ( cxrb, cyrb, b );
+    double val = ( D - B - C + A );
+
+    if ( normalizationMethod == HISTFEATURE_NORMMETHOD_L2 )
+      sum += val * val;
+    else if ( normalizationMethod == HISTFEATURE_NORMMETHOD_L1 )
+      sum += val;
+  }
+  if ( normalizationMethod == HISTFEATURE_NORMMETHOD_L2 )
+    sum = sqrt ( sum );
+
+  return ( val1 + epsilon ) / ( sum + epsilon );
 }
 
 void HistFeature::explode ( FeaturePool & featurePool, bool variableWindow ) const
 {
-    int nScales = (variableWindow ? numScales : 1 );
-
-    double weight = 1.0 / ( numBins * nScales );
-
-    if ( flexibleGrid ) 
-	weight *= 4.0 / ( cellcountx * (cellcountx - 1) * (cellcounty - 1) * cellcounty );
-    else
-	weight *= 1.0 / (cellcountx * cellcounty);
-
-    for ( int i = 0 ; i < nScales ; i++ )
-    {
-	int wsy = window_size_y;
-	int wsx = window_size_x;
-	for ( int _cellx1 = 0 ; _cellx1 < cellcountx ; _cellx1++ )
-	    for ( int _celly1 = 0 ; _celly1 < cellcounty ; _celly1++ )
-		for ( int _cellx2 = _cellx1+1 ; 
-			  _cellx2 < (flexibleGrid ? cellcountx : _cellx1+2) ; 
-			  _cellx2++ )
-		    for ( int _celly2 = _celly1+1 ; 
-			      _celly2 < (flexibleGrid ? cellcounty : 
-			      _celly1+2) ; _celly2++ )
-			for ( int _bin = 0 ; _bin < numBins ; _bin++ )
-			{
-			    HistFeature *f = new HistFeature();
-			    f->histtype = histtype;
-			    f->window_size_x = wsx;
-			    f->window_size_y = wsy;
-			    f->bin = _bin;
-			    f->cellx1 = _cellx1;
-			    f->celly1 = _celly1;
-			    f->cellx2 = _cellx2;
-			    f->celly2 = _celly2;
-			    f->cellcountx = cellcountx;
-			    f->cellcounty = cellcounty;
-			    featurePool.addFeature ( f, weight ); 
-			}
-	wsx = (int) (scaleStep * wsx);
-	wsy = (int) (scaleStep * wsy);
-    }
+  int nScales = ( variableWindow ? numScales : 1 );
+
+  double weight = 1.0 / ( numBins * nScales );
+
+  if ( flexibleGrid )
+    weight *= 4.0 / ( cellcountx * ( cellcountx - 1 ) * ( cellcounty - 1 ) * cellcounty );
+  else
+    weight *= 1.0 / ( cellcountx * cellcounty );
+
+  for ( int i = 0 ; i < nScales ; i++ )
+  {
+    int wsy = window_size_y;
+    int wsx = window_size_x;
+    for ( int _cellx1 = 0 ; _cellx1 < cellcountx ; _cellx1++ )
+      for ( int _celly1 = 0 ; _celly1 < cellcounty ; _celly1++ )
+        for ( int _cellx2 = _cellx1 + 1 ;
+              _cellx2 < ( flexibleGrid ? cellcountx : _cellx1 + 2 ) ;
+              _cellx2++ )
+          for ( int _celly2 = _celly1 + 1 ;
+                _celly2 < ( flexibleGrid ? cellcounty :
+                            _celly1 + 2 ) ; _celly2++ )
+            for ( int _bin = 0 ; _bin < numBins ; _bin++ )
+            {
+              HistFeature *f = new HistFeature();
+              f->histtype = histtype;
+              f->window_size_x = wsx;
+              f->window_size_y = wsy;
+              f->bin = _bin;
+              f->cellx1 = _cellx1;
+              f->celly1 = _celly1;
+              f->cellx2 = _cellx2;
+              f->celly2 = _celly2;
+              f->cellcountx = cellcountx;
+              f->cellcounty = cellcounty;
+              featurePool.addFeature ( f, weight );
+            }
+    wsx = ( int ) ( scaleStep * wsx );
+    wsy = ( int ) ( scaleStep * wsy );
+  }
 }
 
 Feature *HistFeature::clone() const
 {
-    HistFeature *f = new HistFeature();
-    f->histtype = histtype;
-    f->window_size_x = window_size_x;
-    f->window_size_y = window_size_y;
-    f->bin = bin;
-    f->cellx1 = cellx1;
-    f->celly1 = celly1;
-    f->cellx2 = cellx2;
-    f->celly2 = celly2;
-    f->cellcountx = cellcountx;
-    f->cellcounty = cellcounty;
-
-    return f;
+  HistFeature *f = new HistFeature();
+  f->histtype = histtype;
+  f->window_size_x = window_size_x;
+  f->window_size_y = window_size_y;
+  f->bin = bin;
+  f->cellx1 = cellx1;
+  f->celly1 = celly1;
+  f->cellx2 = cellx2;
+  f->celly2 = celly2;
+  f->cellcountx = cellcountx;
+  f->cellcounty = cellcounty;
+
+  return f;
 }
 
 Feature *HistFeature::generateFirstParameter () const
 {
-    return clone();
+  return clone();
 }
 
-void HistFeature::restore (istream & is, int format)
+void HistFeature::restore ( istream & is, int format )
 {
-    is >> histtype;
-    is >> window_size_x;
-    is >> window_size_y;
-    is >> bin;
-    is >> cellx1;
-    is >> celly1;
-    is >> cellx2;
-    is >> celly2;
-    is >> cellcountx;
-    is >> cellcounty;
+  is >> histtype;
+  is >> window_size_x;
+  is >> window_size_y;
+  is >> bin;
+  is >> cellx1;
+  is >> celly1;
+  is >> cellx2;
+  is >> celly2;
+  is >> cellcountx;
+  is >> cellcounty;
 }
 
-void HistFeature::store (ostream & os, int format) const
+void HistFeature::store ( ostream & os, int format ) const
 {
-    os << "HistFeature "
-       << histtype << " "
-       << window_size_x << " "
-       << window_size_y << " "
-       << bin << " "
-       << cellx1 << " "
-       << celly1 << " "
-       << cellx2 << " "
-       << celly2 << " "
-       << cellcountx << " "
-       << cellcounty;
+  os << "HistFeature "
+  << histtype << " "
+  << window_size_x << " "
+  << window_size_y << " "
+  << bin << " "
+  << cellx1 << " "
+  << celly1 << " "
+  << cellx2 << " "
+  << celly2 << " "
+  << cellcountx << " "
+  << cellcounty;
 }
 
 void HistFeature::clear ()

+ 53 - 58
features/fpfeatures/HistFeature.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file HistFeature.h
 * @brief histogram integral feature
 * @author Erik Rodner
@@ -10,7 +10,7 @@
 
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
- 
+
 #include "core/basics/Config.h"
 #include "vislearning/cbaselib/Feature.h"
 
@@ -21,65 +21,60 @@ namespace OBJREC {
 class HistFeature : public Feature
 {
 
-    protected:
-
-	enum {
-	    HISTFEATURE_NORMMETHOD_L1 = 0,
-	    HISTFEATURE_NORMMETHOD_L2
-	};
-
-	/** @{ feature parameter */
-	int window_size_x;
-	int window_size_y;
-
-	int histtype;
-	int bin;
-	int cellx1;
-	int celly1;
-	int cellx2;
-	int celly2;
-	int cellcountx;
-	int cellcounty;
-	int normalizationMethod;
-
-	bool flexibleGrid;
-
-	/** @} */
-
-	/** @{ parameter for feature generation */
-	int numScales;
-	int numBins;
-	double scaleStep;
-	/** @} */
-
-    public:
-  
-	/** simple constructor */
-	HistFeature( const NICE::Config *conf, 
-		     // refactor-nice.pl: check this substitution
-		     // old: const std::string & section, 
-		     const std::string & section, 
-		     int _histtype,
-		     int _numBins);
-
-	/** internally used by HistFeature::explode */
-	HistFeature () {};
-      
-	/** simple destructor */
-	virtual ~HistFeature();
-     
-	double val( const Example *example ) const;
-	void explode ( FeaturePool & featurePool, bool variableWindow = true ) const;
-	Feature *clone() const;
-	Feature *generateFirstParameter () const;
-
-	void restore (std::istream & is, int format = 0);
-	void store (std::ostream & os, int format = 0) const;
-	void clear ();
-};
+  protected:
+
+    enum {
+      HISTFEATURE_NORMMETHOD_L1 = 0,
+      HISTFEATURE_NORMMETHOD_L2
+    };
+
+    /** @{ feature parameter */
+    int window_size_x;
+    int window_size_y;
+
+    int histtype;
+    int bin;
+    int cellx1;
+    int celly1;
+    int cellx2;
+    int celly2;
+    int cellcountx;
+    int cellcounty;
+    int normalizationMethod;
+
+    bool flexibleGrid;
 
+    /** @} */
 
+    /** @{ parameter for feature generation */
+    int numScales;
+    int numBins;
+    double scaleStep;
+    /** @} */
 
+  public:
+
+    /** simple constructor */
+    HistFeature ( const NICE::Config *conf,
+                  const std::string & section,
+                  int _histtype,
+                  int _numBins );
+
+    /** internally used by HistFeature::explode */
+    HistFeature () {};
+
+    /** simple destructor */
+    virtual ~HistFeature();
+
+    double val ( const Example *example ) const;
+    void explode ( FeaturePool & featurePool, bool variableWindow = true ) const;
+    Feature *clone() const;
+    Feature *generateFirstParameter () const;
+
+    void restore ( std::istream & is, int format = 0 );
+    void store ( std::ostream & os, int format = 0 ) const;
+    void clear ();
+};
 
 } // namespace
 

+ 180 - 173
features/fpfeatures/PixelPairFeature.cpp

@@ -14,219 +14,226 @@ const int lastColorchannel = 2;
 
 void PixelPairFeature::explode ( FeaturePool & featurePool, bool variableWindow ) const
 {
-	PixelPairFeature *f = new PixelPairFeature ( *this );
-	int firstchannel = ( imagetype == CachedExample::I_COLOR ) ? firstColorchannel : 0;
-	int lastchannel = ( imagetype == CachedExample::I_COLOR ) ? lastColorchannel : 0;
-
-	int wsx = window_size_x / 2;
-	int wsy = window_size_y / 2;
-	
-	int numberOfPairFeatures = (lastchannel - firstchannel + 1) * 
-		(2*wsx / step_x) * (2*wsy / step_y);
-
-	numberOfPairFeatures *= numberOfPairFeatures;
-
-	for ( int _type = PPTYPE_DIFF ; _type < PPTYPE_VALUE ; _type++ )
-	for ( int _x1 = -wsx ; _x1 < wsx ; _x1 += step_x )
-	for ( int _y1 = -wsy ; _y1 < wsy ; _y1 += step_y )
-	for ( int _b1 = firstchannel ; _b1 <= lastchannel ; _b1++ ) 
-	for ( int _x2 = -wsx ; _x2 < wsx ; _x2 += step_x )
-	for ( int _y2 = -wsy ; _y2 < wsy ; _y2 += step_y )
-	for ( int _b2 = firstchannel ; _b2 <= lastchannel ; _b2++ ) 
-	{
-		if ( (_b1 == _b2) && (_x1 == _x2) && (_y1 == _y2) ) continue;
-		f->x1 = _x1; f->y1 = _y1; f->b1 = _b1;
-		f->x2 = _x2; f->y2 = _y2; f->b2 = _b2;
-		f->type = _type;
-		featurePool.addFeature ( f->clone(), 1.0 / ((PPTYPE_VALUE - PPTYPE_DIFF) * numberOfPairFeatures) );
-	}
-
-	f->type = PPTYPE_VALUE;
-	for ( int _x1 = -wsx ; _x1 < wsx ; _x1 += step_x )
-	for ( int _y1 = -wsy ; _y1 < wsy ; _y1 += step_y )
-	for ( int _b1 = firstchannel ; _b1 <= lastchannel ; _b1++ ) 
-	{
-		f->x1 = _x1; f->y1 = _y1; f->b1 = _b1;
-		featurePool.addFeature ( f->clone(), 1.0 / numberOfPairFeatures );
-	}
-
-	delete f;
+  PixelPairFeature *f = new PixelPairFeature ( *this );
+  int firstchannel = ( imagetype == CachedExample::I_COLOR ) ? firstColorchannel : 0;
+  int lastchannel = ( imagetype == CachedExample::I_COLOR ) ? lastColorchannel : 0;
+
+  int wsx = window_size_x / 2;
+  int wsy = window_size_y / 2;
+
+  int numberOfPairFeatures = ( lastchannel - firstchannel + 1 ) *
+                             ( 2 * wsx / step_x ) * ( 2 * wsy / step_y );
+
+  numberOfPairFeatures *= numberOfPairFeatures;
+
+  for ( int _type = PPTYPE_DIFF ; _type < PPTYPE_VALUE ; _type++ )
+    for ( int _x1 = -wsx ; _x1 < wsx ; _x1 += step_x )
+      for ( int _y1 = -wsy ; _y1 < wsy ; _y1 += step_y )
+        for ( int _b1 = firstchannel ; _b1 <= lastchannel ; _b1++ )
+          for ( int _x2 = -wsx ; _x2 < wsx ; _x2 += step_x )
+            for ( int _y2 = -wsy ; _y2 < wsy ; _y2 += step_y )
+              for ( int _b2 = firstchannel ; _b2 <= lastchannel ; _b2++ )
+              {
+                if ( ( _b1 == _b2 ) && ( _x1 == _x2 ) && ( _y1 == _y2 ) ) continue;
+                f->x1 = _x1;
+                f->y1 = _y1;
+                f->b1 = _b1;
+                f->x2 = _x2;
+                f->y2 = _y2;
+                f->b2 = _b2;
+                f->type = _type;
+                featurePool.addFeature ( f->clone(), 1.0 / ( ( PPTYPE_VALUE - PPTYPE_DIFF ) * numberOfPairFeatures ) );
+              }
+
+  f->type = PPTYPE_VALUE;
+  for ( int _x1 = -wsx ; _x1 < wsx ; _x1 += step_x )
+    for ( int _y1 = -wsy ; _y1 < wsy ; _y1 += step_y )
+      for ( int _b1 = firstchannel ; _b1 <= lastchannel ; _b1++ )
+      {
+        f->x1 = _x1;
+        f->y1 = _y1;
+        f->b1 = _b1;
+        featurePool.addFeature ( f->clone(), 1.0 / numberOfPairFeatures );
+      }
+
+  delete f;
 }
 
 
 Feature *PixelPairFeature::clone() const
 {
-    PixelPairFeature *fp =  new PixelPairFeature(*this);
-    return fp;
+  PixelPairFeature *fp =  new PixelPairFeature ( *this );
+  return fp;
 }
 
 
 /************* PixelPairFeature **************/
-PixelPairFeature::PixelPairFeature( const Config *conf )
+PixelPairFeature::PixelPairFeature ( const Config *conf )
 {
-    window_size_x = conf->gI("PixelPairFeatures", "window_size_x", 24 );
-    window_size_y = conf->gI("PixelPairFeatures", "window_size_y", 24 );
-    step_x = conf->gI("PixelPairFeatures", "step_x", 1 );
-    step_y = conf->gI("PixelPairFeatures", "step_y", 1 );
-    bool use_color = conf->gB("PixelPairFeatures", "use_color", true );
-
-    if ( use_color ) {
-	imagetype = CachedExample::I_COLOR;
-    } else {
-	imagetype = CachedExample::I_GRAYVALUES;
-    }
+  window_size_x = conf->gI ( "PixelPairFeatures", "window_size_x", 24 );
+  window_size_y = conf->gI ( "PixelPairFeatures", "window_size_y", 24 );
+  step_x = conf->gI ( "PixelPairFeatures", "step_x", 1 );
+  step_y = conf->gI ( "PixelPairFeatures", "step_y", 1 );
+  bool use_color = conf->gB ( "PixelPairFeatures", "use_color", true );
+
+  if ( use_color ) {
+    imagetype = CachedExample::I_COLOR;
+  } else {
+    imagetype = CachedExample::I_GRAYVALUES;
+  }
 }
 
-PixelPairFeature::PixelPairFeature ( int _window_size_x,	
-			   int _window_size_y,
-			   int _step_x,
-			   int _step_y,
-			   int _imagetype )
+PixelPairFeature::PixelPairFeature ( int _window_size_x,
+                                     int _window_size_y,
+                                     int _step_x,
+                                     int _step_y,
+                                     int _imagetype )
 {
-    window_size_x = _window_size_x;
-    window_size_y = _window_size_y;
-    x1 = 0; y1 = 0; b1 = firstColorchannel;
-    x2 = 1; y1 = 0; b2 = firstColorchannel;
-    step_x = _step_x;
-    step_y = _step_y;
-    type = PixelPairFeature::PPTYPE_DIFF;
-    imagetype = _imagetype;
+  window_size_x = _window_size_x;
+  window_size_y = _window_size_y;
+  x1 = 0;
+  y1 = 0;
+  b1 = firstColorchannel;
+  x2 = 1;
+  y1 = 0;
+  b2 = firstColorchannel;
+  step_x = _step_x;
+  step_y = _step_y;
+  type = PixelPairFeature::PPTYPE_DIFF;
+  imagetype = _imagetype;
 }
 
 PixelPairFeature::~PixelPairFeature()
 {
 }
 
-double PixelPairFeature::val( const Example *example ) const
+double PixelPairFeature::val ( const Example *example ) const
 {
-    int xl = example->x;
-    int yl = example->y;
-    NICE::MultiChannelImageT<int> & img = example->ce->getIChannel ( imagetype );
-
-    int xx1 = x1;
-    int yy1 = y1;
-    int xx2 = x1;
-    int yy2 = x2;
-    int exwidth = example->width;
-    if ( exwidth != 0 )
-    {
-	int exheight = example->height;
-	xx1 = xx1 * exwidth / window_size_x;	
-	yy1 = yy1 * exheight / window_size_y;	
-	xx2 = xx2 * exwidth / window_size_x;	
-	yy2 = yy2 * exheight / window_size_y;	
-    }
-
-    int xsize = img.xsize;
-    int ysize = img.ysize;
-
-    const int *channel1 = img.data[b1];
-    int p1x = BOUND ( xl + xx1, 0, xsize-1 );
-    int p1y = BOUND ( yl + yy1, 0, ysize-1 );
-    long off1 = p1x + p1y*xsize;
-    int v1 = channel1[off1];
+  int xl = example->x;
+  int yl = example->y;
+  NICE::MultiChannelImageT<int> & img = example->ce->getIChannel ( imagetype );
+
+  int xx1 = x1;
+  int yy1 = y1;
+  int xx2 = x1;
+  int yy2 = x2;
+  int exwidth = example->width;
+  if ( exwidth != 0 )
+  {
+    int exheight = example->height;
+    xx1 = xx1 * exwidth / window_size_x;
+    yy1 = yy1 * exheight / window_size_y;
+    xx2 = xx2 * exwidth / window_size_x;
+    yy2 = yy2 * exheight / window_size_y;
+  }
+
+  int xsize = img.width();
+  int ysize = img.height();
+
+  int p1x = BOUND ( xl + xx1, 0, xsize - 1 );
+  int p1y = BOUND ( yl + yy1, 0, ysize - 1 );
+
+  int v1 = img.get(p1x,p1y,b1);
+
+  if ( type != PPTYPE_VALUE )
+  {
+    int p2x = BOUND ( xl + xx2, 0, xsize - 1 );
+    int p2y = BOUND ( yl + yy2, 0, ysize - 1 );
     
-    if ( type != PPTYPE_VALUE ) 
-    {
-	const int *channel2 = img.data[b2];
-
-	int p2x = BOUND ( xl + xx2, 0, xsize-1 );
-	int p2y = BOUND ( yl + yy2, 0, ysize-1 );
-	long off2 = p2x + p2y*xsize;
-	int v2 = channel2[off2];
-	
-	if ( type == PPTYPE_DIFF ) 
-	    return v1 - v2;
-	else if ( type == PPTYPE_ABSDIFF )
-	    return fabs(v1-v2);
-	else if ( type == PPTYPE_SUM )
-	    return v1 + v2;
-	else
-	    exit(-1);
-
-    } else {
-	return v1;
-    }
+    int v2 = img.get(p2x,p2y,b2);
+
+    if ( type == PPTYPE_DIFF )
+      return v1 - v2;
+    else if ( type == PPTYPE_ABSDIFF )
+      return fabs ( v1 -v2 );
+    else if ( type == PPTYPE_SUM )
+      return v1 + v2;
+    else
+      exit ( -1 );
+
+  } else {
+    return v1;
+  }
 }
 
-void PixelPairFeature::restore (istream & is, int format)
+void PixelPairFeature::restore ( istream & is, int format )
 {
-    is >> type;
-    is >> imagetype;
-    is >> window_size_x;
-    is >> window_size_y;
-    is >> x1;
-    is >> y1;
-    is >> b1;
-    is >> x2;
-    is >> y2;
-    is >> b2;
+  is >> type;
+  is >> imagetype;
+  is >> window_size_x;
+  is >> window_size_y;
+  is >> x1;
+  is >> y1;
+  is >> b1;
+  is >> x2;
+  is >> y2;
+  is >> b2;
 }
 
-void PixelPairFeature::store (ostream & os, int format) const
+void PixelPairFeature::store ( ostream & os, int format ) const
 {
-    os << "PIXELPAIRFEATURE" << " " << type << " " 
-       << imagetype << " "
-       << window_size_x << " " << window_size_y << " "
-       << " " << x1 << " " << y1 << " " << b1
-       << " " << x2 << " " << y2 << " " << b2;
+  os << "PIXELPAIRFEATURE" << " " << type << " "
+  << imagetype << " "
+  << window_size_x << " " << window_size_y << " "
+  << " " << x1 << " " << y1 << " " << b1
+  << " " << x2 << " " << y2 << " " << b2;
 }
 
 void PixelPairFeature::clear ()
 {
-    // nothing to do in my opinion
+  // nothing to do in my opinion
 }
 
 #if 0
 void PixelPairFeature::calcFeatureValues ( const Examples & examples,
-				    vector<int> & examples_selection,
-				    FeatureValuesUnsorted & values ) const
+    vector<int> & examples_selection,
+    FeatureValuesUnsorted & values ) const
 {
-    for ( vector<int>::const_iterator si = examples_selection.begin();
-				   si != examples_selection.end();
-				   si++ )
+  for ( vector<int>::const_iterator si = examples_selection.begin();
+        si != examples_selection.end();
+        si++ )
+  {
+    int index = *si;
+    const pair<int, Example> & p = examples[index];
+    int classno = p.first;
+    const Example & example = p.second;
+    double value = 0.0;
+
+    int xsize, ysize;
+    int xl = example.x - window_size_x / 2;
+    int yl = example.y - window_size_y / 2;
+
+    const double *channel1 = example.ce->getChannel ( b1, xsize, ysize );
+    int p1x = BOUND ( xl + x1, 0, xsize - 1 );
+    int p1y = BOUND ( yl + y1, 0, ysize - 1 );
+    long off1 = p1x + p1y * xsize;
+    double v1 = channel1[off1];
+
+
+    if ( type != PPTYPE_VALUE )
     {
-	int index = *si;
-	const pair<int, Example> & p = examples[index];
-	int classno = p.first;
-	const Example & example = p.second;
-	double value = 0.0;
-
-	int xsize, ysize;
-	int xl = example.x - window_size_x/2;
-        int yl = example.y - window_size_y/2;
-
-	const double *channel1 = example.ce->getChannel ( b1, xsize, ysize );
-	int p1x = BOUND ( xl + x1, 0, xsize-1 );
-	int p1y = BOUND ( yl + y1, 0, ysize-1 );
-	long off1 = p1x + p1y*xsize;
-	double v1 = channel1[off1];
-    
+      const double *channel2 = example.ce->getChannel ( b2, xsize, ysize );
+
+      int p2x = BOUND ( xl + x2, 0, xsize - 1 );
+      int p2y = BOUND ( yl + y2, 0, ysize - 1 );
+      long off2 = p2x + p2y * xsize;
+      double v2 = channel2[off2];
 
-	if ( type != PPTYPE_VALUE ) 
-	{
-	    const double *channel2 = example.ce->getChannel ( b2, xsize, ysize );
-
-	    int p2x = BOUND ( xl + x2, 0, xsize-1 );
-	    int p2y = BOUND ( yl + y2, 0, ysize-1 );
-	    long off2 = p2x + p2y*xsize;
-	    double v2 = channel2[off2];
-	    
-	    
-	    if ( type == PPTYPE_DIFF ) 
-		value = v1 - v2;
-	    else if ( type == PPTYPE_ABSDIFF )
-		value = fabs(v1-v2);
-	    else if ( type == PPTYPE_SUM )
-		value = v1 + v2;
-	} else {
-	    value = v1;
-	}
-
-	values.push_back ( quadruplet<double, int, int, double> ( 
-	    value, classno, index, example.weight ) );
+
+      if ( type == PPTYPE_DIFF )
+        value = v1 - v2;
+      else if ( type == PPTYPE_ABSDIFF )
+        value = fabs ( v1 - v2 );
+      else if ( type == PPTYPE_SUM )
+        value = v1 + v2;
+    } else {
+      value = v1;
     }
 
+    values.push_back ( quadruplet<double, int, int, double> (
+                         value, classno, index, example.weight ) );
+  }
+
 }
 #endif
 

+ 53 - 53
features/fpfeatures/PixelPairFeature.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file PixelPairFeature.h
 * @brief like in Shotton paper
 * @author Erik Rodner
@@ -22,60 +22,60 @@ namespace OBJREC {
 class PixelPairFeature : public Feature
 {
 
-    protected:
-	enum {
-	    PPTYPE_DIFF = 0,
-	    PPTYPE_ABSDIFF,
-	    PPTYPE_SUM,
-	    PPTYPE_VALUE
-	};
-
-	int type;
-	int imagetype;
-
-	int x1;
-	int y1;
-	int b1;
-
-	int x2;
-	int y2;
-	int b2;
-
-	int step_x;
-	int step_y;
-
-	int window_size_x;
-	int window_size_y;
-
-    public:
-  
-	/** simple constructor */
-	PixelPairFeature( const NICE::Config *conf );
-      
-	/** without memory wasting config */
-	PixelPairFeature ( int window_size_x,	
-		      int window_size_y,
-		      int step_x,
-		      int step_y,
-		      int imagetype );
-
-	/** simple destructor */
-	virtual ~PixelPairFeature();
-     
-	double val( const Example *example ) const;
-
-	void explode ( FeaturePool & featurePool, bool variableWindow = true ) const;
-
-	Feature *clone() const;
-	
-	void restore (std::istream & is, int format = 0);
-	void store (std::ostream & os, int format = 0) const;
-	void clear ();
+  protected:
+    enum {
+      PPTYPE_DIFF = 0,
+      PPTYPE_ABSDIFF,
+      PPTYPE_SUM,
+      PPTYPE_VALUE
+    };
+
+    int type;
+    int imagetype;
+
+    int x1;
+    int y1;
+    int b1;
+
+    int x2;
+    int y2;
+    int b2;
+
+    int step_x;
+    int step_y;
+
+    int window_size_x;
+    int window_size_y;
+
+  public:
+
+    /** simple constructor */
+    PixelPairFeature ( const NICE::Config *conf );
+
+    /** without memory wasting config */
+    PixelPairFeature ( int window_size_x,
+                       int window_size_y,
+                       int step_x,
+                       int step_y,
+                       int imagetype );
+
+    /** simple destructor */
+    virtual ~PixelPairFeature();
+
+    double val ( const Example *example ) const;
+
+    void explode ( FeaturePool & featurePool, bool variableWindow = true ) const;
+
+    Feature *clone() const;
+
+    void restore ( std::istream & is, int format = 0 );
+    void store ( std::ostream & os, int format = 0 ) const;
+    void clear ();
 
 #if 0
-	void calcFeatureValues ( const Examples & examples,
-				    std::vector<int> & examples_selection,
-				    FeatureValuesUnsorted & values ) const;
+    void calcFeatureValues ( const Examples & examples,
+                             std::vector<int> & examples_selection,
+                             FeatureValuesUnsorted & values ) const;
 #endif
 
 };

+ 121 - 117
features/fpfeatures/SemanticFeature.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file SemanticFeature.cpp
 * @brief texton feature similar to jamie shottons idea
 * @author Erik Rodner
@@ -18,26 +18,26 @@ using namespace NICE;
 
 
 /** simple constructor */
-SemanticFeature::SemanticFeature( const Config *conf, 
-				  const set<int> *_possibleClassNos )
+SemanticFeature::SemanticFeature ( const Config *conf,
+                                   const set<int> *_possibleClassNos )
     : possibleClassNos ( _possibleClassNos )
 {
-    window_size_x = conf->gI("SemanticFeature", "window_size_x", 21 );
-    window_size_y = conf->gI("SemanticFeature", "window_size_y", 21 );
-    scaleStep = conf->gD("SemanticFeature", "scale_step", sqrt(2) );
-    numScales = conf->gI("SemanticFeature", "num_scales", 5 );
-    end_shiftx = conf->gI("SemanticFeature", "end_shift_x", 40 );
-    end_shifty = conf->gI("SemanticFeature", "end_shift_y", 40 );
-    step_shiftx = conf->gI("SemanticFeature", "step_shift_x", 5 );
-    step_shifty = conf->gI("SemanticFeature", "step_shift_y", 5 );
-
-    shiftx = 0;
-    shifty = 0;
+  window_size_x = conf->gI ( "SemanticFeature", "window_size_x", 21 );
+  window_size_y = conf->gI ( "SemanticFeature", "window_size_y", 21 );
+  scaleStep = conf->gD ( "SemanticFeature", "scale_step", sqrt ( 2 ) );
+  numScales = conf->gI ( "SemanticFeature", "num_scales", 5 );
+  end_shiftx = conf->gI ( "SemanticFeature", "end_shift_x", 40 );
+  end_shifty = conf->gI ( "SemanticFeature", "end_shift_y", 40 );
+  step_shiftx = conf->gI ( "SemanticFeature", "step_shift_x", 5 );
+  step_shifty = conf->gI ( "SemanticFeature", "step_shift_y", 5 );
+
+  shiftx = 0;
+  shifty = 0;
 }
 
-SemanticFeature::SemanticFeature( const Config *conf )
+SemanticFeature::SemanticFeature ( const Config *conf )
 {
-    SemanticFeature ( conf, NULL );
+  SemanticFeature ( conf, NULL );
 }
 
 /** simple destructor */
@@ -45,137 +45,141 @@ SemanticFeature::~SemanticFeature()
 {
 }
 
-double SemanticFeature::val( const Example *example ) const
+double SemanticFeature::val ( const Example *example ) const
 {
-    const NICE::MultiChannelImageT<double> & img = example->ce->getDChannel (
-	CachedExample::D_INTEGRALPRIOR );
+  const NICE::MultiChannelImageT<double> & img = example->ce->getDChannel (
+        CachedExample::D_INTEGRALPRIOR );
 
-    int xsize;
-    int ysize;
-    example->ce->getImageSize ( xsize, ysize );
-    int tm_xsize = img.xsize;
-    int tm_ysize = img.ysize;
+  int xsize;
+  int ysize;
+  example->ce->getImageSize ( xsize, ysize );
+  int tm_xsize = img.width();
+  int tm_ysize = img.height();
 
 #if 0
-    int xtl = example->x - window_size_x/2;
-    int ytl = example->y - window_size_y/2;
-    int xrb = example->x + window_size_x/2;
-    int yrb = example->y + window_size_y/2;
-
-    xtl = xtl * tm_xsize / xsize;
-    ytl = ytl * tm_ysize / ysize;
-    xrb = xrb * tm_xsize / xsize;
-    yrb = yrb * tm_ysize / ysize;
+  int xtl = example->x - window_size_x / 2;
+  int ytl = example->y - window_size_y / 2;
+  int xrb = example->x + window_size_x / 2;
+  int yrb = example->y + window_size_y / 2;
+
+  xtl = xtl * tm_xsize / xsize;
+  ytl = ytl * tm_ysize / ysize;
+  xrb = xrb * tm_xsize / xsize;
+  yrb = yrb * tm_ysize / ysize;
 #endif
 
-    int wsx2 = window_size_x * tm_xsize / (2*xsize);
-    int wsy2 = window_size_y * tm_ysize / (2*ysize);
-    int xx = ( example->x + shiftx ) * tm_xsize / xsize;
-    int yy = ( example->y + shifty ) * tm_ysize / ysize;
-    int xtl = xx - wsx2;
-    int ytl = yy - wsy2;
-    int xrb = xx + wsx2;
-    int yrb = yy + wsy2;
+  int wsx2 = window_size_x * tm_xsize / ( 2 * xsize );
+  int wsy2 = window_size_y * tm_ysize / ( 2 * ysize );
+  int xx = ( example->x + shiftx ) * tm_xsize / xsize;
+  int yy = ( example->y + shifty ) * tm_ysize / ysize;
+  int xtl = xx - wsx2;
+  int ytl = yy - wsy2;
+  int xrb = xx + wsx2;
+  int yrb = yy + wsy2;
 
 #define BOUND(x,min,max) (((x)<(min))?(min):((x)>(max)?(max):(x)))
-    xtl = BOUND ( xtl, 0, tm_xsize - 1 );
-    ytl = BOUND ( ytl, 0, tm_ysize - 1 );
-    xrb = BOUND ( xrb, 0, tm_xsize - 1 );
-    yrb = BOUND ( yrb, 0, tm_ysize - 1 );
+  xtl = BOUND ( xtl, 0, tm_xsize - 1 );
+  ytl = BOUND ( ytl, 0, tm_ysize - 1 );
+  xrb = BOUND ( xrb, 0, tm_xsize - 1 );
+  yrb = BOUND ( yrb, 0, tm_ysize - 1 );
 #undef BOUND
 
-    double A,B,C,D;
-
-    A = img.data[classno][ xtl + ytl * tm_xsize ];
-    B = img.data[classno][ xrb + ytl * tm_xsize ];
-    C = img.data[classno][ xtl + yrb * tm_xsize ];
-    D = img.data[classno][ xrb + yrb * tm_xsize ];
-
-    int area = (xrb - xtl)*(yrb - ytl);
-    
-    /*******************************
-	    BE CAREFUL
-	THIS INCORPORATES POSTION
-	INFORMATION INDIRECTLY
-    ********************************/
-    
-    if ( area == 0 ) 
-	return 0.0;
-    else        
-       /* A B 
-	  C D  */
-	return (D - B - C + A) / area;
+  double A, B, C, D;
+
+  A = img.get(xtl,ytl,classno);
+  B = img.get(xrb,ytl,classno); 
+  C = img.get(xtl,yrb,classno);
+  D = img.get(xrb,yrb,classno);
+
+  int area = ( xrb - xtl ) * ( yrb - ytl );
+
+  /*******************************
+   BE CAREFUL
+  THIS INCORPORATES POSTION
+  INFORMATION INDIRECTLY
+  ********************************/
+
+  if ( area == 0 )
+  {
+    return 0.0;
+  }
+  else
+  {
+    /* A B
+    C D  */
+    return ( D - B - C + A ) / area;
+  }
 }
 
 void SemanticFeature::explode ( FeaturePool & featurePool, bool variableWindow ) const
 {
-    if ( possibleClassNos == NULL )
+  if ( possibleClassNos == NULL )
+  {
+    fprintf ( stderr, "SemanticFeature::explode: no classno set given !\n" );
+    exit ( -1 );
+  }
+  // use leaf nodes only !!
+  for ( set<int>::const_iterator k = possibleClassNos->begin();
+        k != possibleClassNos->end();
+        k++ )
+  {
+    for ( int sy = 0 ; sy <= end_shifty ; sy += step_shifty )
     {
-	fprintf (stderr, "SemanticFeature::explode: no classno set given !\n");
-	exit(-1);
-    }
-    // use leaf nodes only !!
-    for ( set<int>::const_iterator k = possibleClassNos->begin();
-				   k != possibleClassNos->end();
-				   k++ )
-    {
-	for ( int sy = 0 ; sy <= end_shifty ; sy += step_shifty )
-	{
-	    for ( int sx = 0 ; sx <= end_shiftx ; sx += step_shiftx )
-	    {
-		int wsy = window_size_y;
-		int wsx = window_size_x;
-		for ( int i = 0 ; i < numScales ; i++ )
-		{
-		    SemanticFeature *f = new SemanticFeature();
-		    f->classno = *k;
-		    f->window_size_x = wsx;
-		    f->window_size_y = wsy;
-		    f->shiftx = sx;
-		    f->shifty = sy;
-		    featurePool.addFeature ( f, step_shiftx * step_shifty / (double)( end_shiftx * end_shifty * possibleClassNos->size() ) ); 
-		    wsx = (int) (scaleStep * wsx);
-		    wsy = (int) (scaleStep * wsy);
-		}
-	    }
-	}
+      for ( int sx = 0 ; sx <= end_shiftx ; sx += step_shiftx )
+      {
+        int wsy = window_size_y;
+        int wsx = window_size_x;
+        for ( int i = 0 ; i < numScales ; i++ )
+        {
+          SemanticFeature *f = new SemanticFeature();
+          f->classno = *k;
+          f->window_size_x = wsx;
+          f->window_size_y = wsy;
+          f->shiftx = sx;
+          f->shifty = sy;
+          featurePool.addFeature ( f, step_shiftx * step_shifty / ( double ) ( end_shiftx * end_shifty * possibleClassNos->size() ) );
+          wsx = ( int ) ( scaleStep * wsx );
+          wsy = ( int ) ( scaleStep * wsy );
+        }
+      }
     }
+  }
 }
 
 Feature *SemanticFeature::clone() const
 {
-    SemanticFeature *f = new SemanticFeature();
-    f->window_size_x = window_size_x;
-    f->window_size_y = window_size_y;
-    f->classno = classno;
-    f->shiftx = shiftx;
-    f->shifty = shifty;
-
-    return f;
+  SemanticFeature *f = new SemanticFeature();
+  f->window_size_x = window_size_x;
+  f->window_size_y = window_size_y;
+  f->classno = classno;
+  f->shiftx = shiftx;
+  f->shifty = shifty;
+
+  return f;
 }
 
 Feature *SemanticFeature::generateFirstParameter () const
 {
-    return clone();
+  return clone();
 }
 
-void SemanticFeature::restore (istream & is, int format)
+void SemanticFeature::restore ( istream & is, int format )
 {
-    is >> window_size_x;
-    is >> window_size_y;
-    is >> shiftx;
-    is >> shifty;
-    is >> classno;
+  is >> window_size_x;
+  is >> window_size_y;
+  is >> shiftx;
+  is >> shifty;
+  is >> classno;
 }
 
-void SemanticFeature::store (ostream & os, int format) const
+void SemanticFeature::store ( ostream & os, int format ) const
 {
-    os << "SemanticFeature "
-       << window_size_x << " "
-       << window_size_y << " "
-       << shiftx << " "
-       << shifty << " "
-       << classno;
+  os << "SemanticFeature "
+  << window_size_x << " "
+  << window_size_y << " "
+  << shiftx << " "
+  << shifty << " "
+  << classno;
 }
 
 void SemanticFeature::clear ()

+ 47 - 47
features/fpfeatures/SemanticFeature.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file SemanticFeature.h
 * @brief texton feature similar to jamie shottons idea
 * @author Erik Rodner
@@ -21,52 +21,52 @@ namespace OBJREC {
 class SemanticFeature : public Feature
 {
 
-    protected:
-	/** @{ feature parameter */
-	int window_size_x;
-	int window_size_y;
-	int shiftx;
-	int shifty;
-	int classno;
-	/** @} */
-
-
-	/** @{ parameter for feature generation */
-	int numScales;
-	double scaleStep;
-	int maxdepth;
-
-	int end_shiftx;
-	int end_shifty;
-	int step_shiftx;
-	int step_shifty;
-	/** @} */
-
-	const std::set<int> *possibleClassNos;
-
-    public:
-  
-	/** simple constructor */
-	SemanticFeature( const NICE::Config *conf, 
-			 const std::set<int> *_possibleClassNos );
-
-	/** simple constructor */
-	SemanticFeature( const NICE::Config *conf );
-
-	/** internally used by SemanticFeature::explode */
-	SemanticFeature () {};
-      
-	/** simple destructor */
-	virtual ~SemanticFeature();
-     
-	double val( const Example *example ) const;
-	void explode ( FeaturePool & featurePool, bool variableWindow = true ) const;
-	Feature *clone() const;
-	Feature *generateFirstParameter () const;
-
-	void restore (std::istream & is, int format = 0);
-	void store (std::ostream & os, int format = 0) const;
-	void clear ();
+  protected:
+    /** @{ feature parameter */
+    int window_size_x;
+    int window_size_y;
+    int shiftx;
+    int shifty;
+    int classno;
+    /** @} */
+
+
+    /** @{ parameter for feature generation */
+    int numScales;
+    double scaleStep;
+    int maxdepth;
+
+    int end_shiftx;
+    int end_shifty;
+    int step_shiftx;
+    int step_shifty;
+    /** @} */
+
+    const std::set<int> *possibleClassNos;
+
+  public:
+
+    /** simple constructor */
+    SemanticFeature ( const NICE::Config *conf,
+                      const std::set<int> *_possibleClassNos );
+
+    /** simple constructor */
+    SemanticFeature ( const NICE::Config *conf );
+
+    /** internally used by SemanticFeature::explode */
+    SemanticFeature () {};
+
+    /** simple destructor */
+    virtual ~SemanticFeature();
+
+    double val ( const Example *example ) const;
+    void explode ( FeaturePool & featurePool, bool variableWindow = true ) const;
+    Feature *clone() const;
+    Feature *generateFirstParameter () const;
+
+    void restore ( std::istream & is, int format = 0 );
+    void store ( std::ostream & os, int format = 0 ) const;
+    void clear ();
 
 };
 

+ 1 - 1
features/localfeatures/GenericLFSelection.h

@@ -83,7 +83,7 @@ class GenericLFSelection
 
 	  // no correct localfeature_type was given
 	  if ( lfrep == NULL )
-		  fthrow(Exception, "Local feature type not found: " << localfeature_type );
+		  fthrow(NICE::Exception, "Local feature type not found: " << localfeature_type );
 
 	  if ( conf->gB(section, "localfeature_cache_save", false) )
 	  {

+ 1 - 1
features/localfeatures/GenericLocalFeatureSelection.h

@@ -55,7 +55,7 @@ class GenericLocalFeatureSelection
 
       // no correct localfeature_type was given
       if ( lf == NULL )
-        fthrow ( Exception, "Local feature type not found: " << localfeature_type );
+        fthrow ( NICE::Exception, "Local feature type not found: " << localfeature_type );
 
       return lf;
     }

+ 1 - 1
features/localfeatures/LFColorWeijer.cpp

@@ -462,7 +462,7 @@ void LFColorWeijer::getFeats( const ColorImage &img, MultiChannelImageT<double>
 {
   int width = ( int )img.width();
   int height = ( int )img.height();
-  feats.reInit( width, height, hist.size(), true );
+  feats.reInit( width, height, hist.size());
 
   NICE::MultiChannelImageT<double> genimg, imglab;
 

+ 80 - 70
features/localfeatures/LFReadCache.tcc

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LFReadCache.tcc
 * @author Erik Rodner
 * @date 02/14/2008
@@ -18,84 +18,94 @@
 #include "core/basics/FileMgt.h"
 #include "core/vector/VVector.h"
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 template <class ImageClass>
-int LFReadCache::extractFeaturesTemplate ( const ImageClass & img, 
-		  NICE::VVector & features, 
-		  NICE::VVector & positions) const
+int LFReadCache::extractFeaturesTemplate ( const ImageClass & img,
+    NICE::VVector & features,
+    NICE::VVector & positions ) const
 {
-    std::string filename = Globals::getCacheFilename ( cachedir, cachemode );
-    std::string filename_desc = filename + ".desc";
-    std::string filename_pos = filename + ".key";
+  std::string filename = Globals::getCacheFilename ( cachedir, cachemode );
+  std::string filename_desc = filename + ".desc";
+  std::string filename_pos = filename + ".key";
+
+  int ret = 0;
+
+  if ( ! NICE::FileMgt::fileExists ( filename_desc ) ||
+       ! NICE::FileMgt::fileExists ( filename_pos ) )
+  {
+    fprintf ( stderr, "LFReadCache::extractFeatures: recovering data (%s,%s not found)\n", filename_desc.c_str(),
+              filename_pos.c_str() );
+    if ( lfrep == NULL )
+      fthrow ( NICE::Exception, "LocalFeatureRepresentation not available, recovering is impossible!" );
+
+    lfrep->extractFeatures ( img, features, positions );
+
+    features.save ( filename_desc, descFormat );
+    positions.save ( filename_pos, NICE::VVector::FILEFORMAT_LINE );
+  }
+  else
+  {
+    if ( ( descFormat == NICE::VVector::FILEFORMAT_BINARY_DOUBLE ) || ( descFormat == NICE::VVector::FILEFORMAT_BINARY_CHAR ) )
+    {
+      if ( lfrep == NULL )
+      {
+        fthrow ( NICE::Exception, "Raw binary format needs a LocalFeatureRepresentation as prototype" );
+      }
+      else
+      {
+        features.setBufSize ( lfrep->getDescSize() );
+      }
+    }
 
-    int ret = 0;
+    features.read ( filename_desc, descFormat );
+    positions.read ( filename_pos, NICE::VVector::FILEFORMAT_LINE );
+
+    if ( positions.size() != features.size() )
+    {
+      std::cerr << "LFReadCache::extractFeatures: format error ! positions.size=" << positions.size() <<
+                " features.size()=" << features.size() << std::endl;
+      std::cerr << "features: " << filename_desc << std::endl;
+      std::cerr << "positions: " << filename_pos << std::endl;
+      exit ( -1 );
+    }
 
-    if ( ! NICE::FileMgt::fileExists ( filename_desc ) ||
-	 ! NICE::FileMgt::fileExists ( filename_pos ) )
+    if ( ( numFeatures >= 0 ) && ( features.size() > ( size_t ) numFeatures ) )
     {
-		fprintf (stderr, "LFReadCache::extractFeatures: recovering data (%s,%s not found)\n", filename_desc.c_str(),
-			filename_pos.c_str());
-		if ( lfrep == NULL )
-			fthrow(Exception, "LocalFeatureRepresentation not available, recovering is impossible!");
-
-		lfrep->extractFeatures ( img, features, positions );
-
-		features.save ( filename_desc, descFormat );
-		positions.save ( filename_pos, NICE::VVector::FILEFORMAT_LINE );
-    } else {
-		if ( (descFormat == NICE::VVector::FILEFORMAT_BINARY_DOUBLE) || (descFormat == NICE::VVector::FILEFORMAT_BINARY_CHAR) )
-		{
-			if ( lfrep == NULL ) {
-				fthrow(Exception, "Raw binary format needs a LocalFeatureRepresentation as prototype");
-			} else {
-				features.setBufSize(lfrep->getDescSize());
-			}
-		}
-
-		features.read( filename_desc, descFormat );
-		positions.read ( filename_pos, NICE::VVector::FILEFORMAT_LINE );
-
-		if ( positions.size() != features.size() )
-		{
-			std::cerr << "LFReadCache::extractFeatures: format error ! positions.size=" << positions.size() <<
-			" features.size()=" << features.size() << std::endl;
-			std::cerr << "features: " << filename_desc << std::endl;
-			std::cerr << "positions: " << filename_pos << std::endl;
-			exit(-1);
-		}
-
-		if ( (numFeatures >= 0) && (features.size() > (size_t)numFeatures) ) {
-			size_t n = features.size() - numFeatures; // >= 1
-			fprintf (stderr, "LFReadCache: number of local features is restricted: localfeature_count %d, real %d\n",
-			numFeatures, (int)features.size() );
-
-			if ( n > (size_t)numFeatures ) {
-				NICE::VVector nf;
-				NICE::VVector np;
-				for ( size_t l = 0 ; l < (size_t)numFeatures ; l++ )
-				{
-					size_t i = rand() % features.size();
-					nf.push_back ( features[i] );
-					np.push_back ( positions[i] );
-					features.erase ( features.begin() + i );
-					positions.erase ( positions.begin() + i );
-				}
-				positions = np;
-				features = nf;
-			} else {
-				for ( size_t l = 0 ; l < n ; l++ )
-				{
-					size_t i = rand() % features.size();
-					features.erase ( features.begin() + i );
-					positions.erase ( positions.begin() + i );
-				}
-			}
-		}
+      size_t n = features.size() - numFeatures; // >= 1
+      fprintf ( stderr, "LFReadCache: number of local features is restricted: localfeature_count %d, real %d\n",
+                numFeatures, ( int ) features.size() );
+
+      if ( n > ( size_t ) numFeatures )
+      {
+        NICE::VVector nf;
+        NICE::VVector np;
+        for ( size_t l = 0 ; l < ( size_t ) numFeatures ; l++ )
+        {
+          size_t i = rand() % features.size();
+          nf.push_back ( features[i] );
+          np.push_back ( positions[i] );
+          features.erase ( features.begin() + i );
+          positions.erase ( positions.begin() + i );
+        }
+        positions = np;
+        features = nf;
+      }
+      else
+      {
+        for ( size_t l = 0 ; l < n ; l++ )
+        {
+          size_t i = rand() % features.size();
+          features.erase ( features.begin() + i );
+          positions.erase ( positions.begin() + i );
+        }
+      }
     }
+  }
 
 
-    return ret;
+  return ret;
 }
 
 }

+ 2 - 1
features/localfeatures/LFSiftPP.h

@@ -8,10 +8,11 @@
 #ifndef LFSIFTPPINCLUDE
 #define LFSIFTPPINCLUDE
 
+#include "core/imagedisplay/ImageDisplay.h"
+
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
 #include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
 
 #include "core/basics/Config.h"
 #include "LocalFeatureRepresentation.h"

+ 49 - 47
features/localfeatures/LFonHSG.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LFonHSG.h
 * @brief This class can be used to calculate the positions of keyfeatures in a Honeyrate Structure Grid (HSG). Also the class call the normal getDescriptors methode from a given type of SIFT.
 * @author Eric Bach
@@ -29,64 +29,66 @@
 /** STRINGTOOLS **/
 /** 1) boost **/
 #ifdef NICE_USELIB_BOOST
-  #include <boost/tokenizer.hpp>
+#include <boost/tokenizer.hpp>
 /** 2) NICE (standard) **/
 #else
-  #include <core/basics/StringTools.h>
+#include <core/basics/StringTools.h>
 #endif
 
 namespace OBJREC
 {
-	class LFonHSG : public LocalFeatureRepresentation
-	{		
-		/* private member */
-		private:
-			/* parameter for the grid */
-			//! stepwidhts of the grid
-			int sampleScaling;
-			//! which scales should be used
-			std::string scales;
-			//! vector which save the different scales
-			std::vector <float> scalesV;	
+class LFonHSG : public LocalFeatureRepresentation
+{
+    /* private member */
+  private:
+    /* parameter for the grid */
+    //! stepwidhts of the grid
+    int sampleScaling;
+    //! which scales should be used
+    std::string scales;
+    //! vector which save the different scales
+    std::vector <float> scalesV;
+
+    /** Calculate the keypoint-positions by given imagesize, sample-spacing and scales.
+        @brief The methode returns the calculated positions on a honeyrate-grid. This
+        positions starts with (0;0).
+        @param[in] unsigned int imageWidth  - width (x) of the given image
+        @param[in] unsigned int imageHeight - heigth (y) of the given image
+        @param[in,out] NICE::VVector positions    - destination for the calculated positions
+    **/
+    void getPositionsOnHSG ( const unsigned int imageWidth,
+                             const unsigned int imageHeight,
+                             NICE::VVector& positions ) const;
+
+    //! simple methode to convert a string into float
+    float strToFloat ( const std::string str ) const;
 
-			/** Calculate the keypoint-positions by given imagesize, sample-spacing and scales.
-			    @brief The methode returns the calculated positions on a honeyrate-grid. This 
-				   positions starts with (0;0).
-			    @param[in] unsigned int imageWidth  - width (x) of the given image
-			    @param[in] unsigned int imageHeight - heigth (y) of the given image
-			    @param[in,out] NICE::VVector positions    - destination for the calculated positions
-			**/
-			void getPositionsOnHSG ( const unsigned int imageWidth,
-						 const unsigned int imageHeight,
-						 NICE::VVector& positions ) const;    
+    //! if true, print some log-output
+    bool debug;
 
-			//! simple methode to convert a string into float
-			float strToFloat( const std::string str ) const;
+    //! the descritor instanz
+    LocalFeature* lf;
 
-			//! if true, print some log-output
-			bool debug;
-			
-			//! the descritor instanz
-			LocalFeature* lf; 
+    /* public member */
+  public:
+    //! simple contructor
+    LFonHSG ( const NICE::Config *conf, const std::string section = "HSG" );
+    //! simple desctructor
+    ~LFonHSG();
 
-		/* public member */
-		public:
-			//! simple contructor
-			LFonHSG( const NICE::Config *conf, const std::string section = "HSG");
-			//! simple desctructor
-			~LFonHSG();
+    //! Returns the descriptorsize
+    int getDescSize() const {
+      return lf->getDescSize();
+    };
 
-			//! Returns the descriptorsize
-			int getDescSize() const { return lf->getDescSize(); };
+    //! Extract the descriptor-Values from a given grayscale-Image.
+    int extractFeatures ( const NICE::Image & img, NICE::VVector & features, NICE::VVector & positions ) const;
 
-			//! Extract the descriptor-Values from a given grayscale-Image.
-			int extractFeatures ( const NICE::Image & img, NICE::VVector & features, NICE::VVector & positions ) const;
+    //! Extract the descriptor-Values from a given color-Image.
+    int extractFeatures ( const NICE::ColorImage & cimg, NICE::VVector & features, NICE::VVector & positions ) const;
 
-			//! Extract the descriptor-Values from a given color-Image.
-      int extractFeatures ( const NICE::ColorImage & cimg, NICE::VVector & features, NICE::VVector & positions ) const;
-			
-			//! Visualisierung
-			void visualizeFeatures ( NICE::Image & mark, const NICE::VVector & positions, size_t color ) const;
-	};
+    //! Visualisierung
+    void visualizeFeatures ( NICE::Image & mark, const NICE::VVector & positions, size_t color ) const;
+};
 }
 #endif

+ 2 - 1
features/localfeatures/LocalFeatureRepresentation.h

@@ -8,10 +8,11 @@
 #ifndef LOCALFEATUREREPRESENTATIONINCLUDE
 #define LOCALFEATUREREPRESENTATIONINCLUDE
 
+#include "core/imagedisplay/ImageDisplay.h"
+
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
 #include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
  
 #include <vector>
 #include "core/vector/VVector.h"

+ 2 - 5
image/GenericImageTools.h

@@ -3,14 +3,12 @@
 * @brief simple filter stuff
 * @author Erik Rodner
 * @date 07/30/2008
-
 */
 #ifndef GENERICIMAGETOOLSINCLUDE
 #define GENERICIMAGETOOLSINCLUDE
 
 #include "core/image/MultiChannelImageT.h"
 
-
 namespace OBJREC {
 
 /** simple filter stuff */
@@ -19,15 +17,14 @@ class GenericImageTools
     public:
 
     template <class PixelValueDst, class PixelValueSrc>
-    static void calcIntegralImage ( PixelValueDst *integral, const PixelValueSrc *image, int xsize, int ysize );
+    static void calcIntegralImage ( NICE::ImageT<PixelValueDst> &integralImage, const NICE::ImageT<PixelValueSrc> &image, int xsize, int ysize );
 
     template <class PixelValueDst, class PixelValueSrc>
-    static void nonMaximumSuppression ( PixelValueDst *dst, const PixelValueSrc *src, int xsize, int ysize, bool useEightConnectivity = true );
+    static void nonMaximumSuppression ( NICE::ImageT<PixelValueDst> &dst, const NICE::ImageT<PixelValueSrc> &src, int xsize, int ysize, bool useEightConnectivity = true );
 
 };
 
 #include "GenericImageTools.tcc"
- 
 
 } // namespace
 

+ 66 - 48
image/GenericImageTools.tcc

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file GenericImageTools.cpp
 * @brief simple filter stuff
 * @author Erik Rodner
@@ -10,65 +10,83 @@
 #include "GenericImageTools.h"
 
 template <class PixelValueDst, class PixelValueSrc>
-void GenericImageTools::calcIntegralImage ( PixelValueDst *integralImage, const PixelValueSrc *image, int xsize, int ysize )
+void GenericImageTools::calcIntegralImage ( NICE::ImageT<PixelValueDst> &integralImage, const NICE::ImageT<PixelValueSrc> &image, int xsize, int ysize )
 {
-    integralImage[0] = image[0];
+  integralImage ( 0, 0 ) = ( PixelValueDst ) image ( 0, 0 );;
 
-    int k = xsize;
-    for ( int y = 1 ; y < ysize; y++, k+=xsize )
-	integralImage[k] = (PixelValueDst)(integralImage[k-xsize] + image[k]);
+  for ( int y = 1 ; y < ysize; y++ )
+    integralImage ( 0, y ) += image ( 0, y - 1 );
 
-    k = 1;
-    for ( int x = 1 ; x < xsize; x++, k++ )
-	integralImage[k] = (PixelValueDst)(integralImage[k-1] + image[k]);
+  for ( int x = 1 ; x < xsize; x++ )
+    integralImage ( x, 0 ) += image ( x - 1, 0 );
 
-    k = xsize + 1;
-    for ( int y = 1 ; y < ysize ; y++,k++ )
-	for ( int x = 1 ; x < xsize ; x++,k++ )
-	{
-	    integralImage[k] = (PixelValueDst)image[k];
-	    integralImage[k] += integralImage[k-1]; 
-	    integralImage[k] += integralImage[k - xsize];
-	    integralImage[k] -= integralImage[k - xsize - 1];
-	}
+  for ( int y = 1 ; y < ysize ; y++ )
+    for ( int x = 1 ; x < xsize ; x++ )
+    {
+      integralImage ( x, y ) = ( PixelValueDst ) image ( x, y );
+      integralImage ( x, y ) += integralImage ( x, y - 1 );
+      integralImage ( x, y ) += integralImage ( x - 1, y );
+      integralImage ( x, y ) -= integralImage ( x - 1, y - 1 );
+    }
 }
 
 template <class PixelValueDst, class PixelValueSrc>
-void GenericImageTools::nonMaximumSuppression ( PixelValueDst *dst, const PixelValueSrc *src,
-    int xsize, int ysize, bool useEightConnectivity )
+void GenericImageTools::nonMaximumSuppression ( NICE::ImageT<PixelValueDst> &dst, const NICE::ImageT<PixelValueSrc> &src, int xsize, int ysize, bool useEightConnectivity )
 {
-    long k = 0;
-    for ( int y = 0 ; y < ysize ; y++ )
-	for ( int x = 0 ; x < xsize ; x++,k++ )
-	{
-	    if ( x != 0 )
-	    {
-			if ( src[k-1] > src[k] ) { dst[k] = 0; continue; };
-			if ( useEightConnectivity ) {
-				if ( ( y != 0 ) && ( src[k-xsize-1] > src[k] ) ) { dst[k] = 0; continue; };
-				if ( ( y != ysize-1 ) && ( src[k+xsize-1] > src[k] ) ) { dst[k] = 0; continue; };
-			}
-	    }
+  for ( int y = 0 ; y < ysize ; y++ )
+    for ( int x = 0 ; x < xsize ; x++ )
+    {
+      if ( x != 0 )
+      {
+        if ( src ( x - 1, y ) > src ( x, y ) ) {
+          dst ( x, y ) = 0;
+          continue;
+        };
+        if ( useEightConnectivity ) {
+          if ( ( y != 0 ) && ( src ( x, y - 1 ) > src ( x, y ) ) ) {
+            dst ( x, y ) = 0;
+            continue;
+          };
+          if ( ( y != ysize - 1 ) && ( src ( x - 1, y + 1 ) > src ( x, y ) ) ) {
+            dst ( x, y ) = 0;
+            continue;
+          };
+        }
+      }
 
-	    if ( x != xsize-1 ) 
-	    {
-			if ( src[k+1] > src[k] ) { dst[k] = 0; continue; };
-			if ( useEightConnectivity ) {
-				if ( ( y != 0 ) && ( src[k-xsize+1] > src[k] ) ) { dst[k] = 0; continue; };
-				if ( ( y != ysize-1 ) && ( src[k+xsize+1] > src[k] ) ) { dst[k] = 0; continue; };
-			}
-	    }
+      if ( x != xsize - 1 )
+      {
+        if ( src ( x + 1, y ) > src ( x, y ) ) {
+          dst ( x, y ) = 0;
+          continue;
+        };
+        if ( useEightConnectivity ) {
+          if ( ( y != 0 ) && ( src ( x + 1, y - 1 ) > src ( x, y ) ) ) {
+            dst ( x, y ) = 0;
+            continue;
+          };
+          if ( ( y != ysize - 1 ) && ( src ( x + 1, y + 1 ) > src ( x, y ) ) ) {
+            dst ( x, y ) = 0;
+            continue;
+          };
+        }
+      }
 
-	    // CHANGE THIS to dst <-> src !!
+      // CHANGE THIS to dst <-> src !!
 
-	    if ( y != 0 ) 
-			if ( src[k-xsize] > src[k] ) { dst[k] = 0; continue; };
-	    
-	    if ( y != ysize-1 ) 
-			if ( src[k+xsize] > src[k] ) { dst[k] = 0; continue; };
+      if ( y != 0 )
+        if ( src ( x, y - 1 ) > src ( x, y ) ) {
+          dst ( x, y ) = 0;
+          continue;
+        };
 
-	    dst[k] = src[k];
-	}
+      if ( y != ysize - 1 )
+        if ( src ( x, y + 1 ) > src ( x, y ) ) {
+          dst ( x, y ) = 0;
+          continue;
+        };
 
+      dst ( x, y ) = src ( x, y );
+    }
 }
 

+ 2 - 2
math/cluster/GMM.h

@@ -124,7 +124,7 @@ class GMM : public ClusterAlgorithm
      * @param vin input vector
      * @param probs BoV output vector
      */
-    void getProbs ( const NICE::Vector &vin, SparseVector &probs );
+    void getProbs ( const NICE::Vector &vin, NICE::SparseVector &probs );
 
     /**
      * returns the probabilities for each gaussian
@@ -138,7 +138,7 @@ class GMM : public ClusterAlgorithm
      * @param vin input vector
      * @param probs Fisher score output vector
      */
-    void getFisher ( const NICE::Vector &vin, SparseVector &probs );
+    void getFisher ( const NICE::Vector &vin, NICE::SparseVector &probs );
 
     /**
      *   init the GaussianMixture by selecting randomized mean vectors and using the coovariance of all features

+ 32 - 33
math/cluster/KMeansOnline.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file KMeansOnline.h
 * @brief online kmeans clustering
 * @author Erik Rodner
@@ -16,43 +16,42 @@
 #include "vislearning/cbaselib/Example.h"
 
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 /** online kmeans clustering */
 class KMeansOnline : public ClusterOnline
 {
 
-    protected:
-	size_t numClusters;
-	double gamma;
-
-    public:
-  
-	/** simple constructor */
-	KMeansOnline( size_t numClusters, double gamma = 1.0 );
-      
-	/** simple destructor */
-	virtual ~KMeansOnline();
-
-	// refactor-nice.pl: check this substitution
-	// old: int updateClusters ( const Vector & x );
-	int updateClusters ( const NICE::Vector & x );
-	void init ();
-     
-	/**
-	 * Cluster algorithm using examples
-	 * @param ex input examples
-	 */
-	void cluster( const Examples &ex);
-	
-	/**
-	 * returns the distance to the centre of each cluster
-	 * @param vin input vector
-	 * @param dist distance
-	 * @param size how much centres should considered
-	 * @param hard use a hard assignment (all values = 1 or 0) or not
-		 */
-	void getDist(const NICE::Vector &vin, SparseVector &dist, int size = 1, bool hard = false);
+  protected:
+    size_t numClusters;
+    double gamma;
+
+  public:
+
+    /** simple constructor */
+    KMeansOnline ( size_t numClusters, double gamma = 1.0 );
+
+    /** simple destructor */
+    virtual ~KMeansOnline();
+
+    int updateClusters ( const NICE::Vector & x );
+    void init ();
+
+    /**
+     * Cluster algorithm using examples
+     * @param ex input examples
+     */
+    void cluster ( const Examples &ex );
+
+    /**
+     * returns the distance to the centre of each cluster
+     * @param vin input vector
+     * @param dist distance
+     * @param size how much centres should considered
+     * @param hard use a hard assignment (all values = 1 or 0) or not
+      */
+    void getDist ( const NICE::Vector &vin, NICE::SparseVector &dist, int size = 1, bool hard = false );
 };
 
 

+ 48 - 48
math/distances/genericDistance.h

@@ -8,54 +8,54 @@ namespace OBJREC
 
 class GenericDistanceSelection
 {
-public:
-
-	static NICE::VectorDistance<double> *selectDistance(
-			std::string distance_type)
-	{
-		NICE::VectorDistance<double> *distance = NULL;
-
-		if (distance_type == "euclidean")
-		{
-			distance = new NICE::EuclidianDistance<double>();
-		}
-		else if (distance_type == "manhattan" || distance_type == "cityblock")
-		{
-			distance = new NICE::ManhattanDistance<double>();
-		}
-		else if (distance_type == "median")
-		{
-			distance = new NICE::MedianDistance<double>();
-		}
-		else if (distance_type == "cosinus")
-		{
-			distance = new NICE::CosDistance<double>();
-		}
-		else if (distance_type == "spherical")
-		{
-			distance = new NICE::SphericalDistance<double>();
-		}
-		else if (distance_type == "chisquare" || distance_type == "chi2")
-		{
-			distance = new NICE::Chi2Distance<double>();
-
-		}
-		else if (distance_type == "kl" || distance_type == "kullbackleibler")
-		{
-			distance = new NICE::KLDistance<double>();
-		}
-		else if (distance_type == "bhattacharyya")
-		{
-			distance = new NICE::BhattacharyyaDistance<double>();
-		}
-		else
-		{
-			fthrow(Exception, "Distance type " << distance_type << " is unknown - euclidean distance used" );
-			distance = new NICE::EuclidianDistance<double>();
-		}
-
-		return distance;
-	}
+  public:
+
+    static NICE::VectorDistance<double> *selectDistance (
+      std::string distance_type )
+    {
+      NICE::VectorDistance<double> *distance = NULL;
+
+      if ( distance_type == "euclidean" )
+      {
+        distance = new NICE::EuclidianDistance<double>();
+      }
+      else if ( distance_type == "manhattan" || distance_type == "cityblock" )
+      {
+        distance = new NICE::ManhattanDistance<double>();
+      }
+      else if ( distance_type == "median" )
+      {
+        distance = new NICE::MedianDistance<double>();
+      }
+      else if ( distance_type == "cosinus" )
+      {
+        distance = new NICE::CosDistance<double>();
+      }
+      else if ( distance_type == "spherical" )
+      {
+        distance = new NICE::SphericalDistance<double>();
+      }
+      else if ( distance_type == "chisquare" || distance_type == "chi2" )
+      {
+        distance = new NICE::Chi2Distance<double>();
+
+      }
+      else if ( distance_type == "kl" || distance_type == "kullbackleibler" )
+      {
+        distance = new NICE::KLDistance<double>();
+      }
+      else if ( distance_type == "bhattacharyya" )
+      {
+        distance = new NICE::BhattacharyyaDistance<double>();
+      }
+      else
+      {
+        fthrow ( NICE::Exception, "Distance type " << distance_type << " is unknown - euclidean distance used" );
+        distance = new NICE::EuclidianDistance<double>();
+      }
+
+      return distance;
+    }
 
 };
 } //namespace

+ 10 - 5
math/ftransform/PCA.cpp

@@ -9,7 +9,7 @@
  * This is an example of how to use the Principal Component Analysis (PCA) class.
  */
 
-// #define DEBUG
+//#define DEBUG
 #undef DEBUG
 
 #include <iostream>
@@ -83,6 +83,7 @@ void PCA::calculateMean ( const NICE::Matrix &features, NICE::Vector & mean )
   mean.set(0);
   for ( uint i = 0 ; i < features.rows(); i++ )
     mean = mean + features.getRow ( i );
+  mean /= features.rows();
 }
 
 void PCA::calculateBasis ( const NICE::Matrix &features,
@@ -99,18 +100,21 @@ void PCA::calculateBasis ( const NICE::Matrix &features,
   NICE::Vector eigenvalue;
 
   calculateMean ( features, mean );
-
+  
 #ifdef NICE_USELIB_TRLAN
   EigValues *eig;
-  if(mindimension < 4)
+  if(mindimension < 12)
     eig = new EVArnoldi();//Arnoldi for (srcFeatureSize<n)
   else
     eig = new EigValuesTRLAN();//fast lanczos TRLAN
 #else
   EigValues *eig = new EVArnoldi();//Arnoldi for (srcFeatureSize<n)
 #endif
+
   NICE::Matrix features_transpose = features.transpose();
+
   GMCovariance C ( &features_transpose );
+  
   if ( adaptive )
   {
     eig->getEigenvalues ( C, eigenvalue, eigenvectors, srcFeatureSize );
@@ -146,7 +150,6 @@ void PCA::calculateBasis ( const NICE::Matrix &features,
 
   //compute basis size
 
-
   if ( adaptive )
   { //compute target dimension
     uint dimensioncount = 0;
@@ -183,6 +186,7 @@ void PCA::calculateBasis ( const NICE::Matrix &features,
     count++;
     it++;
   }
+  
   //normalization matrix / modify variance to 1 for all eigenvectors
   normalization = NICE::Matrix ( mindimension, mindimension, 0 );
   for ( uint k = 0; k < mindimension; k++ )
@@ -203,12 +207,13 @@ NICE::Vector PCA::getFeatureVector ( const NICE::Vector &data,
   //free data of mean
   if ( normalize )
   {
-
     NICE::Vector meanfree ( data );
     meanfree -= mean;
     //Y=W^t * B^T
+    
     if ( normbasis.rows() == 0 )
       normbasis.multiply ( normalization, basis, false, true );
+    
     NICE::Vector tmp;
     tmp.multiply ( normbasis, meanfree );
     return tmp;

+ 0 - 88
math/ftransform/progs/Makefile.inc

@@ -1,88 +0,0 @@
-# BINARY-DIRECTORY-MAKEFILE
-# conventions:
-# - there are no subdirectories, they are ignored!
-# - all ".C", ".cpp" and ".c" files in the current directory are considered
-#   independent binaries, and linked as such.
-# - the binaries depend on the library of the parent directory
-# - the binary names are created with $(BINNAME), i.e. it will be more or less
-#   the name of the .o file
-# - all binaries will be added to the default build list ALL_BINARIES
-
-# --------------------------------
-# - remember the last subdirectory
-#
-# set the variable $(SUBDIR) correctly to the current subdirectory. this
-# variable can be used throughout the current makefile.inc. The many 
-# SUBDIR_before, _add, and everything are only required so that we can recover
-# the previous content of SUBDIR before exitting the makefile.inc
-
-SUBDIR_add:=$(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
-SUBDIR_before:=$(SUBDIR)
-SUBDIR:=$(strip $(SUBDIR_add))
-SUBDIR_before_$(SUBDIR):=$(SUBDIR_before)
-
-# ------------------------
-# - include subdirectories
-#
-# note the variables $(SUBDIRS_OF_$(SUBDIR)) are required later on to recover
-# the dependencies automatically. if you handle dependencies on your own, you
-# can also dump the $(SUBDIRS_OF_$(SUBDIR)) variable, and include the
-# makefile.inc of the subdirectories on your own...
-
-#SUBDIRS_OF_$(SUBDIR):=$(patsubst %/Makefile.inc,%,$(wildcard $(SUBDIR)*/Makefile.inc))
-#include $(SUBDIRS_OF_$(SUBDIR):%=%/Makefile.inc)
-
-# ----------------------------
-# - include local dependencies
-#
-# include the libdepend.inc file, which gives additional dependencies for the
-# libraries and binaries. additionally, an automatic dependency from the library
-# of the parent directory is added (commented out in the code below).
-
--include $(SUBDIR)libdepend.inc
-
-PARENTDIR:=$(patsubst %/,%,$(dir $(patsubst %/,%,$(SUBDIR))))
-$(eval $(call PKG_DEPEND_INT,$(PARENTDIR)))
-
-# ---------------------------
-# - objects in this directory
-#
-# the use of the variable $(OBJS) is not mandatory. it is mandatory however
-# to update $(ALL_OBJS) in a way that it contains the path and name of
-# all objects. otherwise we can not include the appropriate .d files.
-
-OBJS:=$(patsubst %.cpp,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.cpp))) \
-      $(patsubst %.C,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.C))) \
-      $(shell grep -ls Q_OBJECT $(SUBDIR)*.h | sed -e's@^@/@;s@.*/@$(OBJDIR)moc_@;s@\.h$$@.o@') \
-      $(patsubst %.c,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.c)))
-ALL_OBJS += $(OBJS)
-
-# ----------------------------
-# - binaries in this directory
-#
-# output of binaries in this directory. none of the variables has to be used.
-# but everything you add to $(ALL_LIBRARIES) and $(ALL_BINARIES) will be
-# compiled with `make all`. be sure again to add the files with full path.
-
-BINARIES:=$(patsubst %.o,$(BINDIR)%,$(filter-out moc_%,$(notdir $(OBJS))))
-ALL_BINARIES+=$(BINARIES)
-
-# ---------------------
-# - binary dependencies
-#
-# there is no way of determining the binary dependencies automatically, so we
-# follow conventions. each binary depends on the corresponding .o file and
-# on the libraries specified by the INTLIBS/EXTLIBS. these dependencies can be
-# specified manually or they are automatically stored in a .bd file.
-
-$(foreach head,$(wildcard $(SUBDIR)*.h),$(eval $(shell grep -q Q_OBJECT $(head) && echo $(head) | sed -e's@^@/@;s@.*/\(.*\)\.h$$@$(BINDIR)\1:$(OBJDIR)moc_\1.o@')))
--include $(OBJS:%.o=%.bd)
-
-# -------------------
-# - subdir management
-#
-# as the last step, always add this line to correctly recover the subdirectory
-# of the makefile including this one!
-
-SUBDIR:=$(SUBDIR_before_$(SUBDIR))
-

+ 59 - 75
math/ftransform/tests/TestFTransform.cpp

@@ -29,7 +29,7 @@ using namespace std;
 using namespace NICE;
 using namespace OBJREC;
 
-CPPUNIT_TEST_SUITE_REGISTRATION(TestFTransform);
+CPPUNIT_TEST_SUITE_REGISTRATION ( TestFTransform );
 
 void TestFTransform::setUp()
 {
@@ -41,81 +41,65 @@ void TestFTransform::tearDown()
 
 void TestFTransform::TestFTransformComputation()
 {
-    uint samplecount = 16; //samples
-    uint sampledimension = 8; //sample dimension
-    bool init_random = true;
-
-    NICE::Matrix T(samplecount, sampledimension);
-
-    //trivial test
-    CPPUNIT_ASSERT_EQUAL(samplecount, (uint)T.rows());
-    CPPUNIT_ASSERT_EQUAL(sampledimension, (uint)T.cols());
-
-
-    T.set(0.0);
-    if (init_random)
-        srand48(time(NULL));
-
-    // generate random matrix
-    for (uint i = 0 ; i < T.rows() ; i++)
-        for (uint j = 0 ; j < T.cols() ; j++)
-        {
-            T(i, j) = drand48();
-        }
-//cout<<T<<endl;
-    PCA *ftransform = new PCA(sampledimension);
-#ifdef NICE_USELIB_ICE
-#ifdef NICE_USELIB_TRLAN
-	for (int mode = 0;mode <= 1;mode++)
+  uint samplecount = 13; //samples
+  uint sampledimension = 4; //sample dimension
+
+  NICE::Matrix T ( samplecount, sampledimension );
+  NICE::Matrix goalBasis ( sampledimension, sampledimension );
+  NICE::Matrix goalFeats ( samplecount, sampledimension );
+
+  //trivial test
+  CPPUNIT_ASSERT_EQUAL ( samplecount, ( uint ) T.rows() );
+  CPPUNIT_ASSERT_EQUAL ( sampledimension, ( uint ) T.cols() );
+
+  ifstream is ( "./pca.data" );
+  for ( uint i = 0 ; i < T.rows() ; i++ )
+    for ( uint j = 0 ; j < T.cols() ; j++ )
+      is >> T ( i, j );
+
+  for ( uint i = 0 ; i < goalBasis.rows() ; i++ )
+    for ( uint j = 0 ; j < goalBasis.cols() ; j++ )
+      is >> goalBasis ( i, j );
+
+  for ( uint i = 0 ; i < goalFeats.rows() ; i++ )
+    for ( uint j = 0 ; j < goalFeats.cols() ; j++ )
+      is >> goalFeats ( i, j );
+  is.close();
+
+
+  PCA *ftransform = new PCA ( sampledimension );
+
+  bool mode = false;
+  ftransform->calculateBasis ( T, sampledimension, mode ); //fastes available method
+  NICE::Matrix basis, featurematrix;
+  featurematrix = T;
+  //cout << featurematrix << endl;
+  basis = ftransform->getBasis();
+  //cout<<basis<<endl;
+  //orthogonality test
+
+  for ( uint i = 0 ; i < goalBasis.rows() ; i++ )
+    for ( uint j = 0 ; j < goalBasis.cols() ; j++ )
+    {
+      CPPUNIT_ASSERT_DOUBLES_EQUAL_NOT_NAN ( abs ( goalBasis ( i, j ) ), abs ( basis ( i, j ) ), 1e-4 );
+    }
+  //transform features and test
+
+  for ( uint k = 0;k < T.rows();k++ )
+  {
+    NICE::Vector feature, feature_transformed;
+    feature = T.getRow ( k );
+    feature_transformed = ftransform-> getFeatureVector ( feature, false );
+    for ( uint d = 0;d < feature_transformed.size();d++ )
     {
-        ftransform->calculateBasis(T, sampledimension, mode); //fastes available method
-        NICE::Matrix basis, featurematrix;
-        featurematrix = T;
-        basis = ftransform->getBasis();
-        //cout<<basis<<endl;
-        //orthogonality test
-        for (int k = 0;k < basis.rows() - 1;k++)
-        {
-            NICE::Vector b1, b2;
-            b1 = basis.getRow(k);
-            b2 = basis.getRow(k + 1);
-            double sp = b1.scalarProduct(b2);
-            CPPUNIT_ASSERT_DOUBLES_EQUAL_NOT_NAN(0.0, sp, 1e-4);
-        }
-        //transform features and test
-
-        for (int k = 0;k < T.rows();k++)
-        {
-            NICE::Vector feature, feature_transformed;
-            feature = T.getRow(k);
-            feature_transformed = ftransform-> getFeatureVector(feature, true);
-            for (uint d = 0;d < feature_transformed.size();d++)
-            {
-                featurematrix(k, d) = feature_transformed[d];
-            }
-        }
-
-        //cout<<featurematrix<<endl;
-        //Covariance Test
-        NICE::Matrix covariance;
-        covariance = featurematrix.transpose() * featurematrix;
-        ////cout<<covariance<<endl;
-        for (uint i = 0;i < covariance.rows();i++)
-        {
-            for (uint j = 0;j < covariance.cols();j++)
-            {
-                if (i == j)
-                {
-                    CPPUNIT_ASSERT_DOUBLES_EQUAL_NOT_NAN((double)samplecount, covariance(i, j), 1e-4);
-                }
-                else
-                {
-                    CPPUNIT_ASSERT_DOUBLES_EQUAL_NOT_NAN(0.0, covariance(i, j), 1e-4);
-                }
-            }
-        }
+      featurematrix ( k, d ) = feature_transformed[d];
     }
-#endif
-#endif
+  }
 
+  for ( uint i = 0 ; i < goalFeats.rows() ; i++ )
+    for ( uint j = 0 ; j < goalFeats.cols() ; j++ )
+    {
+      CPPUNIT_ASSERT_DOUBLES_EQUAL_NOT_NAN ( abs ( goalFeats ( i, j ) ), abs ( featurematrix ( i, j ) ), 1e-2 );
+    }
 }
+

+ 15 - 14
math/ftransform/tests/TestFTransform.h

@@ -1,20 +1,20 @@
 //
 // C++ Interface: TestFTransform
 //
-// Description: 
+// Description:
 //
 //
 // Author: Michael Koch <Koch.Michael@uni-jena.de>, (C) 2009
 //
 // Copyright: See COPYING file that comes with this distribution
 //
-/** 
+/**
  * @file TestFTransform.h
  * @brief TestFTransform
  * @author Michael Koch
  * @date Di Aug 4 2009
  */
- 
+
 
 #ifndef OBJREC_TestFTransform_H
 #define OBJREC_TestFTransform_H
@@ -23,26 +23,27 @@
 #include <cppunit/extensions/HelperMacros.h>
 
 /**
- * CppUnit-Testcase. 
+ * CppUnit-Testcase.
  * Tests for EigenValue Operations
  */
 class TestFTransform : public CppUnit::TestFixture
 {
-     CPPUNIT_TEST_SUITE( TestFTransform );
+    CPPUNIT_TEST_SUITE ( TestFTransform );
+
 
-    
-     CPPUNIT_TEST( TestFTransformComputation );
+    CPPUNIT_TEST ( TestFTransformComputation );
 
-     CPPUNIT_TEST_SUITE_END();
+    CPPUNIT_TEST_SUITE_END();
 
-     private:
+  private:
+
+  public:
+    void setUp();
+    void tearDown();
+    void TestFTransformComputation();
 
-     public:
-          void setUp();
-          void tearDown();
-          void TestFTransformComputation();
-       
 };
 
 #endif // _TestFTransform_H_
 
+

+ 30 - 0
math/ftransform/tests/pca.data

@@ -0,0 +1,30 @@
+7	26	6	60
+1	29	15	52
+11	56	8	20
+11	31	8	47
+7	52	6	33
+11	55	9	22
+3	71	17	6
+1	31	22	44
+2	54	18	22
+21	47	4	26
+1	40	23	34
+11	66	9	12
+10	68	8	12
+-0.067799985695474	-0.646018286568727	0.567314540990512	0.506179559977705
+-0.678516235418647	-0.019993340484099	-0.543969276583817	0.493268092159297
+0.029020832106229	0.755309622491132	0.403553469172668	0.515567418476836
+0.730873909451461	-0.108480477171676	-0.468397518388289	0.484416225289198
+36.821825999449722	-6.870878154227368	-4.590944457629744	0.396652582713913
+29.607273420710978	4.610881963526304	-2.247578163663947	-0.395843536696488
+-12.981775719737621	-4.204913183175940	0.902243082694698	-1.126100587210614
+23.714725720918029	-6.634052554708719	1.854742000806314	-0.378564808384691
+-0.553191676624596	-4.461732123178687	-6.087412652325180	0.142384896047281
+-10.812490833309822	-3.646571174544059	0.912970791674604	-0.134968810314679
+-32.588166608817936	8.979846284936064	-1.606265913996589	0.081763927599949
+22.606395499005593	10.725906457369447	3.236537714483417	0.324334774646368
+-9.262587237675843	8.985373347478786	-0.016909578102172	-0.543746175981799
+-3.283969329640674	-14.157277337500913	7.046512994833764	0.340509860960608
+9.220031117829379	12.386080787220450	3.428342878284625	0.435152769664895
+-25.584908517429557	-2.781693148152387	-0.386716066864491	0.446817950545607
+-26.903161834677618	-2.930971165042989	-2.445522630195304	0.411607156409659

+ 26 - 21
math/kernels/genericKernel.h

@@ -1,34 +1,39 @@
 #ifndef _NICE_OBJREC_GENERICKERNELSELECTION_INCLUDE
 #define _NICE_OBJREC_GENERICKERNELSELECTION_INCLUDE
 
-
 #include <vector>
 #include "KernelRBF.h"
 #include "KernelExp.h"
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 class GenericKernelSelection
 {
-    public:
-
-		static Kernel *selectKernel ( const NICE::Config *conf, std::string kernel_type )
-		{
-			Kernel *kernel = NULL;
-
-			if ( kernel_type == "rbf" ) {
-				double log_rbf_gamma = conf->gD("Kernel","log_rbf_gamma",-2.5);
-				kernel = new KernelRBF (log_rbf_gamma);
-			} else if ( kernel_type == "exp" ) {
-				double log_rbf_gamma = conf->gD("Kernel","log_rbf_gamma",-2.5);
-				double log_rbf_sv = conf->gD("Kernel","log_rbf_sv",0.0);
-				kernel = new KernelExp (log_rbf_gamma, log_rbf_sv);
-			} else {
-				fthrow(Exception, "Kernel type " << kernel_type << " is unknown" );
-			}
-
-			return kernel;
-		}
+  public:
+
+    static Kernel *selectKernel ( const NICE::Config *conf, std::string kernel_type )
+    {
+      Kernel *kernel = NULL;
+
+      if ( kernel_type == "rbf" )
+      {
+        double log_rbf_gamma = conf->gD ( "Kernel","log_rbf_gamma",-2.5 );
+        kernel = new KernelRBF ( log_rbf_gamma );
+      }
+      else if ( kernel_type == "exp" )
+      {
+        double log_rbf_gamma = conf->gD ( "Kernel","log_rbf_gamma",-2.5 );
+        double log_rbf_sv = conf->gD ( "Kernel","log_rbf_sv",0.0 );
+        kernel = new KernelExp ( log_rbf_gamma, log_rbf_sv );
+      }
+      else
+      {
+        fthrow ( NICE::Exception, "Kernel type " << kernel_type << " is unknown" );
+      }
+
+      return kernel;
+    }
 
 };
 

+ 54 - 54
math/pdf/tests/TestPDF.cpp

@@ -25,35 +25,35 @@
 #include "core/vector/VVector.h"
 #include "vislearning/math/pdf/PDFGaussian.h"
 
-#include "vislearning/nice_nonvis.h"
+#include "objrec/nice_nonvis.h"
 
 using namespace std;
 using namespace NICE;
 using namespace OBJREC;
 
-Matrix computeCovariance(const VVector & vecs)
+Matrix computeCovariance ( const VVector & vecs )
 {
-	Vector mean(vecs[0].size(), 0.0);
+  Vector mean ( vecs[0].size(), 0.0 );
 
-    for (unsigned int i = 0; i < vecs.size(); ++i)
-		mean += vecs[i];
-    
-	mean *= 1.0 / vecs.size();
+  for ( unsigned int i = 0; i < vecs.size(); ++i )
+    mean += vecs[i];
 
-    Matrix cov(vecs[0].size(), vecs[0].size(), 0.0);
+  mean *= 1.0 / vecs.size();
 
-    for (unsigned int i = 0; i < vecs.size(); ++i)
-    {
-        Vector diff = vecs[i] - mean;
-        cov.addTensorProduct ( 1.0, diff, diff );
-    }
+  Matrix cov ( vecs[0].size(), vecs[0].size(), 0.0 );
+
+  for ( unsigned int i = 0; i < vecs.size(); ++i )
+  {
+    Vector diff = vecs[i] - mean;
+    cov.addTensorProduct ( 1.0, diff, diff );
+  }
 
-    cov *= 1.0 / ( vecs.size() );
+  cov *= 1.0 / ( vecs.size() );
 
-    return cov;
+  return cov;
 }
 
-CPPUNIT_TEST_SUITE_REGISTRATION(TestPDF);
+CPPUNIT_TEST_SUITE_REGISTRATION ( TestPDF );
 
 
 
@@ -67,42 +67,42 @@ void TestPDF::tearDown()
 
 void TestPDF::TestPDFComputation()
 {
-    uint dim = 3;
-    bool init_random = true ;
-    uint samples = dim*500;
-
-    NICE::Matrix C(dim, dim);
-    NICE::Vector mean(dim, 0.0);
-    VVector samplevectors;
-    C.set(0.0);
-	cerr << "Sample from Gaussian" << endl;
-    //init random
-    if (init_random)
-        srand48(time(NULL));
-
-    // generate random symmetric matrix
-    for (uint i = 0 ; i < dim ; i++)
-        for (uint j = i ; j < dim ; j++)
-        {
-            C(i, j) = drand48();
-            C(j, i) = C(i, j);
-        }
-	C=C*C.transpose();
-    cerr << "Ground-Truth covariance" << endl;
-    cerr << C << endl;
-    //initialize GaussPDF
-    PDFGaussian pdf_gauss(C, mean);
-    
-	//draw samples
-    pdf_gauss.sample(samplevectors, samples);
-    Matrix Cov_test = computeCovariance(samplevectors);
-    cerr << "Estimated covariance" << endl;
-    cerr<<Cov_test<<endl;
-        
-	NICE::Matrix diff = C-Cov_test;
-	double frobNorm = diff.frobeniusNorm();
-
-	cerr << "Frobenius norm: " << frobNorm << endl;
-	CPPUNIT_ASSERT_DOUBLES_EQUAL_NOT_NAN(0.0, frobNorm, 0.1);
-     
+  uint dim = 3;
+  bool init_random = true ;
+  uint samples = dim * 500;
+
+  NICE::Matrix C ( dim, dim );
+  NICE::Vector mean ( dim, 0.0 );
+  VVector samplevectors;
+  C.set ( 0.0 );
+  cerr << "Sample from Gaussian" << endl;
+  //init random
+  if ( init_random )
+    srand48 ( time ( NULL ) );
+
+  // generate random symmetric matrix
+  for ( uint i = 0 ; i < dim ; i++ )
+    for ( uint j = i ; j < dim ; j++ )
+    {
+      C ( i, j ) = drand48();
+      C ( j, i ) = C ( i, j );
+    }
+  C = C * C.transpose();
+  cerr << "Ground-Truth covariance" << endl;
+  cerr << C << endl;
+  //initialize GaussPDF
+  PDFGaussian pdf_gauss ( C, mean );
+
+  //draw samples
+  pdf_gauss.sample ( samplevectors, samples );
+  Matrix Cov_test = computeCovariance ( samplevectors );
+  cerr << "Estimated covariance" << endl;
+  cerr << Cov_test << endl;
+
+  NICE::Matrix diff = C - Cov_test;
+  double frobNorm = diff.frobeniusNorm();
+
+  cerr << "Frobenius norm: " << frobNorm << endl;
+  CPPUNIT_ASSERT_DOUBLES_EQUAL_NOT_NAN ( 0.0, frobNorm, 0.1 );
+
 }

+ 4 - 0
progs/libdepend.inc

@@ -0,0 +1,4 @@
+$(call PKG_DEPEND_EXT,OPENMP)
+$(call PKG_DEPEND_EXT,OPENCV)
+$(call PKG_DEPEND_INT,objrec/iclassifier)
+$(call PKG_DEPEND_INT,vislearning/classifier)

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно