Jelajahi Sumber

Revision 1.0 - compileable

Alexander Luetz 13 tahun lalu
induk
melakukan
bdb79e8c11

+ 0 - 204
classifier/progs/toyExample.cpp

@@ -1,204 +0,0 @@
-/** 
-* @file toyExample.cpp
-* @brief just a toy tool
-* @author Erik Rodner
-* @date 04/07/2009
-
-*/
-
-
-#include <iomanip>
-#include <core/imagedisplay/SimpleSelector.h>
-#include <core/imagedisplay/OverlayColors.h>
-#include <core/image/CrossT.h>
-#include <core/image/CircleT.h>
-
-#include "core/basics/Config.h"
-#include "vislearning/baselib/ICETools.h"
-
-#include "vislearning/classifier/genericClassifierSelection.h"
-
-#ifdef NOVISUAL
-#include <vislearning/nice_nonvis.h>
-#else
-#include <vislearning/nice.h>
-#endif
-
-using namespace OBJREC;
-
-using namespace NICE;
-using namespace std;
-
-#ifndef NOVISUAL
-
-void selectTrainingSet ( LabeledSetVector & train, NICE::Image & img, int numClasses,
-    bool addBias = false )
-{
-    vector<int> colors;
-    vector<CoordT<double> > points;
-    NICE::selectColoredPoints ( img, points, colors, "Select some points!", numClasses );
-    
-    int k = 0;
-    for ( vector<CoordT<double> >::const_iterator i = points.begin();
-	    i != points.end(); i++,k++ )
-    {
-	NICE::Vector feature ( addBias ? 3 : 2 );
-	feature[0] = i->x;
-	feature[1] = i->y;
-	if ( addBias )
-	    feature[2] = 1.0;
-
-	train.add ( colors[k]-1, feature );
-    }
-}
-#endif
-
-void markBoundary ( const NICE::Image & imgclassno, NICE::Image & mark )
-{
-    for ( int y = 0 ; y < imgclassno.height(); y++ )
-	for ( int x = 0 ; x < imgclassno.width(); x++ )
-	{
-	    int val = imgclassno.getPixel(x,y);
-	    bool boundary = false;
-	    for ( int i = -1 ; (i <= 1) && (!boundary) ; i++ )
-		for ( int j = -1 ; (j <= 1) && (!boundary) ; j++ )
-		{
-		    int xn = x + i;
-		    int yn = y + j;
-		    if ( (xn<0) || (yn<0) || (xn>=imgclassno.width()) || (yn>=imgclassno.height()) )
-			continue;
-		    int valn = imgclassno.getPixel(xn,yn);
-		    if ( valn != val )
-			boundary = true;
-		}
-	    if ( boundary )
-		mark.setPixel(x,y,1);
-	}
-}
-
-/** 
-    just a toy tool 
-*/
-int main (int argc, char **argv)
-{   
-    std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
-
-    Config conf ( argc, argv );
-    conf.store(cout);
- 
-    std::string classifier_type = conf.gS("main", "classifier", "sparse_logistic_regression");
-    fprintf (stderr, "Classifier type: %s\n", classifier_type.c_str() );
-    VecClassifier *vec_classifier = GenericClassifierSelection::selectVecClassifier ( &conf, classifier_type );
-
-    if ( vec_classifier == NULL )
-    {
-	fprintf (stderr, "This classifier type is unknown !\n");
-	exit(-1);
-    }
-
-	conf.sS("VCSVMLight", "normalization_type", "none" );
-    int xsize = conf.gI("main", "xsize", 300 );
-    int ysize = conf.gI("main", "ysize", 300 );
-    int numClasses = conf.gI("main", "numClasses", 2 );
-    vec_classifier->setMaxClassNo(numClasses);
-    
-    bool addBias = conf.gB("main", "addbias", "false" );
-    NICE::Image img (xsize, ysize);
-    NICE::Image mark (img);
-         
-    mark.set(0);
-    img.set(255);
-
-    LabeledSetVector train;
-
-    std::string trainsetcache = conf.gS("main", "trainset", "");
-    bool readtrainset = conf.gB("main", "readtrainset", false);
-    bool selectManually = conf.gB("main", "select", true);
-    if ( selectManually )
-    {
-#ifdef NOVISUAL
-	fprintf (stderr, "toyExample: visual manual selection needs ICE visualization\n");
-#else
-	selectTrainingSet ( train, img, numClasses, addBias );
-#endif
-    }
-
-    if ( readtrainset && (trainsetcache.size() > 0 ) )
-    {
-	train.read ( trainsetcache, LabeledSetVector::FILEFORMAT_NOINDEX );
-    }
-    
-    LOOP_ALL(train)
-    {
-	EACH(classno,x);
-	if ( classno == 0 ) {
-		Cross cross ( Coord( (int)(x[0]), (int)(x[1]) ), 10 );
-		mark.draw ( cross, classno+2 );
-	} else {
-		Circle circle ( Coord( (int)(x[0]), (int)(x[1]) ), 10 );
-		mark.draw ( circle, classno+2 );
-	}
-    }
-
-    bool writetrainset = conf.gB("main", "writetrainset", false);
-    if ( writetrainset && (trainsetcache.size() > 0) )
-	train.save ( trainsetcache, LabeledSetVector::FILEFORMAT_NOINDEX);
-
-    if ( train.count() <= 0 )
-    {
-	fprintf (stderr, "toyExample: size of the training set is zero!\n");
-	exit(-1);
-    }
-
-    fprintf (stderr, "Dimension of the training set: %d\n", train.dimension() );
-    vec_classifier->teach ( train );
-    vec_classifier->finishTeaching();
-
-    NICE::FloatImage imgd (img.width(), img.height());
-    NICE::Image imgclassno (img);
-
-    for ( int y = 0 ; y < img.height(); y++ )
-	for ( int x = 0 ; x < img.width(); x++ )
-	{
-	    NICE::Vector example ( addBias ? 3 : 2 );
-	    example[0] = x;
-	    example[1] = y;
-	    if ( addBias )
-		example[2] = 1.0;
-	    
-	    ClassificationResult r = vec_classifier->classify(example);
-
-	    if ( numClasses == 2 )
-	    {
-		imgd.setPixel(x,y,(r.scores.get(1)));
-	    } else {
-		imgd.setPixel(x, y, r.classno / (double)(numClasses-1) );
-	    }
-
-	    imgclassno.setPixel(x,y,r.classno);
-	}
-    markBoundary ( imgclassno, mark );
-    floatToGrayScaled ( imgd, &img );
-
-	showImageOverlay ( img, mark );
-
-	string resultimg = conf.gS("main", "resultimg", "");
-	if ( resultimg.size() > 0 )
-	{
-		ColorImage result;
-		grayToRGB( img, &result );
-		for ( uint y = 0 ; y < result.height() ; y++ )
-			for ( uint x = 0 ; x < result.width() ; x++ )
-				if ( mark.getPixel(x,y) > 0 ) {
-					result.setPixel(x,y,0,overlayColorTable[mark.getPixel(x,y)][0]);
-					result.setPixel(x,y,1,overlayColorTable[mark.getPixel(x,y)][1]);
-					result.setPixel(x,y,2,overlayColorTable[mark.getPixel(x,y)][2]);
-				}
-		ImageFile imgf ( resultimg );
-		imgf.writer(&result);
-	}
-
-    showImageOverlay ( imgclassno, imgclassno );
-
-    return 0;
-}

+ 0 - 265
features/localfeatures/LFSegContour.cpp

@@ -1,265 +0,0 @@
-/** 
-* @file LFSegContour.cpp
-* @brief Local Features are connected components of a arbitrary segmentation
-* @author Erik Rodner
-* @date 01/21/2008
-
-*/
-
-#include <vislearning/nice.h>
-
-
-
-#ifdef NICE_USELIB_ICE
-
-#include <image_nonvis.h>
-
-
-#include <iostream>
-
-#include <core/image/RectangleT.h>
-
-
-#include "vislearning/features/localfeatures/LFSegContour.h"
-#include "vislearning/segmentation/SegLocal.h"
-
-#include <core/iceconversion/image_convertice.h>
-#include <core/iceconversion/convertice.h>
-
-using namespace OBJREC;
-
-
-using namespace std;
-using namespace NICE;
-
-
-
-LFSegContour::LFSegContour( const Config *conf, FeatureFactory *_fc )
-{
-    segmentation = new SegLocal ( conf );
-
-    fourier_coefficients = conf->gI ( "LFSegContour", "fourier_coefficients", 50 );
-    display_segmentation = conf->gB ( "LFSegContour", "display_segmentation", false);
-    xsize = (size_t)conf->gI("FCGreyValues", "xsize", 11 );
-    ysize = (size_t)conf->gI("FCGreyValues", "ysize", 11 );
-    minArea = (size_t)conf->gI("LFSegContour", "min_area", 25 );
-    
-    std::string descriptor_method_s = conf->gS ("LFSegContour", "descriptor_method" );
-
-    fc = _fc;
-
-    if ( descriptor_method_s == "fourier" )
-		descriptor_method = DESCRIPTOR_METHOD_FOURIER;
-    else if ( descriptor_method_s == "hu" )
-		descriptor_method = DESCRIPTOR_METHOD_HU;
-    else if ( descriptor_method_s == "patch" ) {
-		descriptor_method = DESCRIPTOR_METHOD_PATCH;
-		if ( fc == NULL )
-		{
-			fprintf (stderr, "LFSegContour: please specify a patch feature factory !\n");
-			exit(-1);
-		}
-    } else {
-		fprintf (stderr, "LFSegContour: descriptor method not yet implemented !\n");
-		exit(-1);
-    }
-}
-
-LFSegContour::~LFSegContour()
-{
-    delete segmentation;
-}
-
-int LFSegContour::getDescSize () const
-{
-    if ( descriptor_method == DESCRIPTOR_METHOD_FOURIER )
-		return 2*fourier_coefficients - 2;
-    else if ( descriptor_method == DESCRIPTOR_METHOD_HU )
-		return 7;
-    else {
-		return xsize*ysize;
-    }
-}
-
-int LFSegContour::calcContourDescriptorFourier ( const ice::Contur & c,
-						  NICE::Vector & f ) const
-{
-    if ( (size_t)c.Number() < fourier_coefficients/2 ) 
-		return -1;
-
-    ice::PointList pl1, pl2;
-    double *r_feature = new double[fourier_coefficients];
-    double *i_feature = new double[fourier_coefficients];
-    double phi_1 = 0;
-
-    pl1 = ice::ConturPointList (c, 1);
-    pl2 = ice::NewPointList (pl1->lng);
-
-    ice::FourierD (pl1->xptr, pl1->yptr, pl1->lng, NORMAL, pl2->xptr, pl2->yptr);
-
-    if (fabs (pl2->xptr[1]) < 1.0e-12) {
-	if (pl2->yptr[1] > 0)
-	    phi_1 = PI / 2.0;
-	if (pl2->yptr[1] < 0)
-	    phi_1 = -PI / 2.0;
-	if (fabs (pl2->yptr[1]) < 1.0e-12)
-	{
-	    fprintf (stderr, "LFSegContour: numerical problems !!\n");
-	    exit(-1);
-	}
-    } else {
-	phi_1 = atan (pl2->yptr[1] / pl2->xptr[1]);
-    }
-
-    if (pl2->xptr[1] < 0 && pl2->yptr[1] < 0)
-	phi_1 += M_PI;
-    if (pl2->xptr[1] < 0 && pl2->yptr[1] > 0)
-	phi_1 += M_PI;
-
-    // die ersten 2*fd-2 Merkmale berechnen
-    for (size_t i = 0; i < fourier_coefficients / 2; ++i) {
-	double sinphi = sin (double (i + 1) * phi_1);
-	double cosphi = cos (double (i + 1) * phi_1);
-	r_feature[i] =
-	  pl2->xptr[i + 1] * cosphi + pl2->yptr[i + 1] * sinphi;
-	i_feature[i] =
-	  pl2->yptr[i + 1] * cosphi - pl2->xptr[i + 1] * sinphi;
-    }
-    for (size_t i = fourier_coefficients / 2; i < fourier_coefficients; ++i)
-    {
-	double cosphi = cos (double (-i - 1 + fourier_coefficients / 2) * phi_1);
-	double sinphi = sin (double (-i - 1 + fourier_coefficients / 2) * phi_1);
-	r_feature[i] =
-	  pl2->xptr[pl2->lng - i - 1 + fourier_coefficients / 2] * cosphi +
-	  pl2->yptr[pl2->lng - i - 1 + fourier_coefficients / 2] * sinphi;
-	i_feature[i] =
-	  pl2->yptr[pl2->lng - i - 1 + fourier_coefficients / 2] * cosphi -
-	  pl2->xptr[pl2->lng - i - 1 + fourier_coefficients / 2] * sinphi;
-    }
-
-    f.resize( 2*fourier_coefficients - 2 );
-    for (size_t i = 0; i < fourier_coefficients - 1; ++i)
-    {
-	  f[i] = r_feature[i + 1] / sqrt (r_feature[0] * r_feature[0] +
-				   i_feature[0] * i_feature[0]);
-    }
-    for (size_t i = fourier_coefficients - 1; i < 2 * fourier_coefficients - 2; ++i)
-    {
-	  f[i] = i_feature[i - fourier_coefficients + 2] 
-	         / sqrt (r_feature[0] * r_feature[0] +  i_feature[0] * i_feature[0]);
-    }
-
-    // aufräumen
-    ice::FreePointList (pl1);
-    ice::FreePointList (pl2);
-
-    delete [] r_feature;
-    delete [] i_feature;
-
-    return 0;
-}
-
-int LFSegContour::calcContourDescriptorHU ( const ice::Contur & c,
-					     // refactor-nice.pl: check this substitution
-					     // old: Vector & f ) const
-					     NICE::Vector & f ) const
-{
-    ice::Moments m ( c );
-    f = NICE::makeEVector ( m.AffineHuInvariants() );
-
-    return 0;
-}
-
-int LFSegContour::calcContourDescriptorPatch (  const NICE::Image & img,
-						const ice::Contur & c,
-						NICE::Vector & f ) const
-{
-    int xi, yi, xa, ya;
-    c.GetRect( xi, yi, xa, ya );
-    Rect r ( xi, yi, xa-xi+1, ya-yi+1 ); 
-
-    const NICE::Image *img_w = img.createSubImage ( r );
-    fc->convert ( *img_w, f );
-    delete img_w;
-
-    return 0;
-}
-
-// refactor-nice.pl: check this substitution
-// old: int LFSegContour::extractFeatures ( const Image & img, VVector & features, 
-int LFSegContour::extractFeatures ( const NICE::Image & img, VVector & features, 
-				      VVector & positions ) const
-{
-    std::vector<ice::Contur> contours;
-    segmentation->getContours ( img, contours );
-
-    NICE::Vector x;
-    int r;
-
-    ice::Image mark;
-
-    if ( display_segmentation )
-    {
-		mark = ice::NewImg ( img.width(), img.height(), 30 );
-		ice::ClearImg(mark);
-    }
-
-    for ( vector<ice::Contur>::const_iterator i = contours.begin();
-					 i != contours.end();
-					 i++ )
-    {
-		if ( display_segmentation )
-			ice::MarkContur ( *i, 1, mark );
-
-		int xi, yi, xa, ya;
-		i->GetRect(xi, yi, xa, ya);
-		
-		if ( (xa-xi)*(ya-yi) < minArea ) continue;
-
-		if ( descriptor_method == DESCRIPTOR_METHOD_FOURIER )
-			r = calcContourDescriptorFourier ( *i, x );
-		else if ( descriptor_method == DESCRIPTOR_METHOD_HU )
-			r = calcContourDescriptorHU ( *i, x );
-		else 
-			r = calcContourDescriptorPatch ( img, *i, x );
-
-		if ( r >= 0 ) {
-			features.push_back ( x );
-			NICE::Vector p ( 4 );
-			p[0] = xi; p[1] = yi;
-			p[2] = xa-xi; p[3] = ya-yi;
-			positions.push_back ( p );
-		}
-    }
-
-    if ( display_segmentation )
-    {
-#ifndef NOVISUAL
-		NICE::Image *mark_nice = NICE::createGrayImage ( mark );
-		showImageOverlay(img, *mark_nice);
-		delete mark_nice;
-#else
-		fprintf (stderr, "LFSegContour::extractFeatures: visualization disabled !\n");
-#endif
-    }
-
-    return positions.size();
-}
-
-void LFSegContour::visualizeFeatures ( NICE::Image & mark,
-				 const VVector & positions,
-				 size_t color ) const
-{
-    for ( size_t i = 0 ; i < positions.size() ; i++ )
-    {
-		const NICE::Vector & pos = positions[i];
-		int x = (int)pos[0];
-		int y = (int)pos[1];
-		int w = (int)pos[2];
-		int h = (int)pos[3];
-		RectangleT<Ipp8u> r ( Coord(x,y), Coord(x+w, y+w));
-		mark.draw ( r, color );
-    }
-}
-
-#endif

+ 0 - 86
features/localfeatures/LFSegContour.h

@@ -1,86 +0,0 @@
-/** 
-* @file LFSegContour.h
-* @brief Local Features are connected components of a arbitrary segmentation
-* @author Erik Rodner
-* @date 01/21/2008
-
-*/
-#ifndef LFSegContourINCLUDE
-#define LFSegContourINCLUDE
-
-#ifdef NOVISUAL
-#include <vislearning/nice_nonvis.h>
-#else
-#include <vislearning/nice.h>
-#endif
-
-
-#ifdef NICE_USELIB_ICE
-
-
-#include "LocalFeatureRepresentation.h"
-#include "vislearning/segmentation/SegmentationMethod.h"
-
-#include "core/basics/Config.h"
-#include "vislearning/features/fbase/FeatureFactory.h"
-
-
-namespace OBJREC {
-
-/** Local Features are connected components of an arbitrary segmentation */
-class LFSegContour : public LocalFeatureRepresentation
-{
-    public:
-	enum {
-	    DESCRIPTOR_METHOD_FOURIER = 0,
-	    DESCRIPTOR_METHOD_HU,
-	    DESCRIPTOR_METHOD_PATCH
-	};
-
-    protected:
-
-	SegmentationMethod *segmentation;
-	FeatureFactory *fc;
-
-	bool display_segmentation;
-	size_t fourier_coefficients;
-	size_t descriptor_method;
-	size_t xsize;
-	size_t ysize;
-	int minArea;
-
-
-	int calcContourDescriptorHU ( const ice::Contur & c,
-					 NICE::Vector & f ) const;
-
-	int calcContourDescriptorFourier ( const ice::Contur & c,
-					     NICE::Vector & f ) const;
-
-	int calcContourDescriptorPatch ( const NICE::Image & img,
-					 const ice::Contur & c,
-	 			         NICE::Vector & f ) const;
-
-    public:
-  
-	/** simple constructor */
-	LFSegContour( const NICE::Config *conf, FeatureFactory *fc = NULL );
-      
-	/** simple destructor */
-	virtual ~LFSegContour();
-     
-	int getDescSize () const;
-
-	int extractFeatures ( const NICE::Image & img, NICE::VVector & features, 
-			      NICE::VVector & positions ) const;
-
-	void visualizeFeatures ( NICE::Image & mark,
-				 const NICE::VVector & positions,
-				 size_t color ) const;
-
-};
-
-
-} // namespace
-
-#endif
-#endif

+ 0 - 91
features/localfeatures/LFSegmentation.cpp

@@ -1,91 +0,0 @@
-/** 
-* @file LFSegmentation.cpp
-* @brief Local Features are connected components of a arbitrary segmentation
-* @author Erik Rodner
-* @date 01/21/2008
-
-*/
-#ifdef NICE_USELIB_ICE
-#include <vislearning/nice.h>
-
-#include <image_nonvis.h>
-
-#include <core/image/RectangleT.h>
-
-#include <iostream>
-
-#include "vislearning/features/localfeatures/LFSegmentation.h"
-#include "vislearning/segmentation/SegLocal.h"
-
-#include <core/iceconversion/convertice.h>
-
-using namespace OBJREC;
-
-using namespace std;
-
-using namespace NICE;
-
-
-
-LFSegmentation::LFSegmentation( const Config *conf )
-{
-    segmentation = new SegLocal ( conf );
-}
-
-LFSegmentation::~LFSegmentation()
-{
-    delete segmentation;
-}
-
-int LFSegmentation::getDescSize () const
-{
-    return 1;
-}
-
-int LFSegmentation::extractFeatures ( const NICE::Image & img, VVector & features, 
-				      VVector & positions ) const
-{
-    std::vector<ice::Contur> contours;
-    segmentation->getContours ( img, contours );
-
-    ice::Matrix xcoordinate (0,4);
-    for ( vector<ice::Contur>::const_iterator i = contours.begin();
-					 i != contours.end();
-					 i++ )
-    {
-		int xi, yi, xa, ya;
-		i->GetRect(xi, yi, xa, ya);
-		if ( (ya == yi) || (xa == xi) ) continue;
-		xcoordinate.Append ( ice::Vector(xi,yi,xa-xi,ya-yi) );
-    }
-
-    xcoordinate.Sort();
-
-    for ( int i = 0 ; i < xcoordinate.rows() ; i++ )
-    {
-		NICE::Vector f (1);
-		f.set(0.0);
-		features.push_back(f);
-		positions.push_back( NICE::makeEVector(xcoordinate[i]) );
-    }
-
-    return positions.size();
-}
-
-void LFSegmentation::visualizeFeatures ( NICE::Image & mark,
-				 const VVector & positions,
-				 size_t color ) const
-{
-    for ( size_t i = 0 ; i < positions.size() ; i++ )
-    {
-		const NICE::Vector & pos = positions[i];
-		int x = (int)pos[0];
-		int y = (int)pos[1];
-		int w = (int)pos[2];
-		int h = (int)pos[3];
-		RectangleT<Ipp8u> rect ( Coord(x, y), Coord(x+w, y+w) );
-		mark.draw ( rect, (unsigned char)color );
-    }
-}
-
-#endif

+ 0 - 54
features/localfeatures/LFSegmentation.h

@@ -1,54 +0,0 @@
-/** 
-* @file LFSegmentation.h
-* @brief Local Features are connected components of a arbitrary segmentation
-* @author Erik Rodner
-* @date 01/21/2008
-
-*/
-
-#ifndef LFSEGMENTATIONINCLUDE
-#define LFSEGMENTATIONINCLUDE
-
-#ifdef NICE_USELIB_ICE
-
-#include <image_nonvis.h>
-
-#include "LocalFeatureRepresentation.h"
-#include "vislearning/segmentation/SegmentationMethod.h"
-
-#include "core/basics/Config.h"
-
-
-namespace OBJREC {
-
-/** Local Features are connected components of a arbitrary segmentation */
-class LFSegmentation : public LocalFeatureRepresentation
-{
-
-    protected:
-	SegmentationMethod *segmentation;
-
-    public:
-  
-	/** simple constructor */
-	LFSegmentation( const NICE::Config *conf );
-      
-	/** simple destructor */
-	virtual ~LFSegmentation();
-     
-	int getDescSize () const;
-
-	int extractFeatures ( const NICE::Image & img, NICE::VVector & features, 
-			      NICE::VVector & positions ) const;
-
-	void visualizeFeatures ( NICE::Image & mark,
-				 const NICE::VVector & positions,
-				 size_t color ) const;
-
-};
-
-
-} // namespace
-
-#endif
-#endif

+ 0 - 105
features/localfeatures/progs/createLocalFeatures.cpp

@@ -1,105 +0,0 @@
-/** 
-* @file createLocalFeatures.cpp
-* @brief create local feature files
-* @author Erik Rodner
-* @date 02/14/2008
-
-*/
-
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-
-#include <core/basics/Config.h>
-#include <vislearning/baselib/Globals.h>
-#include <vislearning/baselib/Preprocess.h>
-
-#include <vislearning/features/localfeatures/GenericLFSelection.h>
-#include <vislearning/features/localfeatures/LocalFeatureRepresentation.h>
-#include <vislearning/features/localfeatures/LFWriteCache.h>
-#include <vislearning/cbaselib/MultiDataset.h>
-#include <vislearning/baselib/ProgressBar.h>
-
-#ifdef NOVISUAL
-#include <vislearning/nice_nonvis.h>
-#else
-#include <vislearning/nice.h>
-#endif
-
-using namespace OBJREC;
-
-using namespace NICE;
-using namespace std;
-
-
-/** 
-    create local feature files 
-*/
-int main (int argc, char **argv)
-{   
-    std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
-
-	Config conf ( argc, argv );
-
-	string setname;
-	try {
-		setname = conf.gS("main", "set");
-	} catch ( Exception ) {
-		fprintf (stderr, "usage: %s -config <configfn> -ds <dataset>\n", argv[0]);
-		exit(-1);
-    }
-
-	bool useColor = conf.gB("main", "color", true );
-
-    Preprocess::Init ( &conf );
-    MultiDataset md ( &conf );
-    LabeledSet ls = *(md[setname]);
-
-    LocalFeatureRepresentation *lfrep = GenericLFSelection::selectLocalFeatureRep ( &conf );
-    LFWriteCache lfw ( &conf, lfrep );
-    
-    std::string cachedir = conf.gS("cache", "root");
-    int cachemode = Globals::getCacheMode ( conf.gS("cache", "mode", "cat") );
-    
-	ProgressBar pb ("Local Feature Extraction" );
-    LOOP_ALL_S(ls)
-    {
-		EACH_S(classno,filename);
-		pb.update ( ls.count() );
-
-		NICE::Image img;
-		NICE::ColorImage imgColor;
-
-		if ( !useColor ) 
-			img = Preprocess::ReadImgAdv ( filename );
-		else
-			imgColor = Preprocess::ReadImgAdvRGB ( filename );
-		Globals::setCurrentImgFN ( filename );
-		
-		std::string cache_filename = Globals::getCacheFilename( cachedir, cachemode );
-		std::string cache_filename_desc = cache_filename + ".desc";
-			struct stat dummy;
-		if ( stat ( cache_filename_desc.c_str(), &dummy ) < 0 )
-		{
-			VVector features;
-			VVector positions;
-
-			cerr << "creating features for file " << filename << " ..." << endl;
-			cerr << "writing features to file " << cache_filename_desc << " ..." << endl;
-			if ( !useColor ) {
-				lfw.extractFeatures ( img, features, positions );
-			} else {
-				lfw.extractFeatures ( imgColor, features, positions );
-			}
-			cerr << "pos: " << positions.size() << " feat:" << features.size() << endl;
-		} else {
-			cerr << "description file " << cache_filename_desc << " exists !" << endl;
-		}
-    }
-    
-    delete lfrep;
-    
-    return 0;
-}

+ 0 - 179
features/regionfeatures/RFBoV.cpp

@@ -1,179 +0,0 @@
-#ifdef NICE_USELIB_OPENMP
-#include <omp.h>
-#endif
-
-#include "vislearning/features/regionfeatures/RFBoV.h"
-
-#include <iostream>
-#include "core/basics/Timer.h"
-using namespace OBJREC;
-using namespace std;
-using namespace NICE;
-
-
-RFBoV::RFBoV( const Config *_conf, LocalFeature *_lf ):RegionFeatures(_conf)
-{
-	lf = _lf;
-	string sscales = conf->gS("SIFTTest", "scales", "1+2.0+3.0");
-	grid = conf->gI("SIFTTest", "grid", 20);
-
-	string::size_type pos = 0;
-	string::size_type oldpos = 0;
-	while(pos != string::npos)
-	{
-		pos = sscales.find("+", oldpos);
-		string val;
-		if(pos == string::npos)
-			val = sscales.substr(oldpos);
-		else
-			val = sscales.substr(oldpos, pos-oldpos);
-		double d = atof(val.c_str());
-		scales.push_back(d);
-		oldpos = pos+1;
-	}
-	gmm = NULL;
-	pca = NULL;
-}
-
-void RFBoV::setPCA(PCA *_pca){
-	pca = _pca;
-}
-
-void RFBoV::setGMM(GMM *_gmm){
-	gmm = _gmm;
-}
-
-void RFBoV::extract ( const NICE::Image & img, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
-{
-	VVector positions, features;
-	getPositions(rg, mask, positions);
-	lf->getDescriptors(img, positions, features);
-	assert(features.size() == positions.size());
-	convert(mask, rg, features, feats, positions);
-}
-
-void RFBoV::extractRGB ( const NICE::ColorImage & cimg, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
-{
-	assert(cimg.width() == (int)mask.rows());
-	assert(cimg.height() == (int)mask.cols());
-
-	VVector positions, features;
-
-	getPositions(rg, mask, positions);
-
-	lf->getDescriptors(cimg, positions, features);
-
-	assert(features.size() == positions.size());
-
-	convert(mask, rg, features, feats, positions);
-}
-
-void RFBoV::convert(const Matrix &mask, const RegionGraph &rg, VVector &infeats, VVector &outfeats, VVector &positions)
-{
-	int fsize = gmm->getSize();
-	for(int i = 0; i < (int)rg.size(); i++)
-	{
-		Vector v(fsize);
-		v.set(0.0);
-		outfeats.push_back(v);
-	}
-	vector<int> counter(rg.size(), 0);
-	
-#if 0
-#pragma omp parallel for
-	for(int i = 0; i < (int)infeats.size(); i++)
-	{
-		infeats[i] = pca->getFeatureVector ( infeats[i], true );
-		SparseVector probs;
-
-		gmm->getProbs(infeats[i], probs);
-
-		int r = mask(positions[i][0], positions[i][1]);
-
-#pragma omp critical
-		{
-			for(int j = 0; j < fsize; j++)
-			{
-				outfeats[r][j] += probs.get(j);
-			}
-
-			counter[r]++;
-		}
-	}
-#else
-#pragma omp parallel for
-	for(int i = 0; i < (int)infeats.size(); i++)
-	{
-		
-		infeats[i] = pca->getFeatureVector ( infeats[i], true );
-		SparseVector probs;
-
-		//gmm->getProbs(infeats[i], probs);
-		int bc = gmm->getBestClass(infeats[i]);
-		int r = mask(positions[i][0], positions[i][1]);
-assert(r < (int) rg.size());
-#pragma omp critical
-		{
-			outfeats[r][bc]++;
-			counter[r]++;
-		}
-	}
-#endif
-	for(int i = 0; i < (int)rg.size(); i++)
-	{
-		outfeats[i] /= (double)counter[i];
-	}
-}
-
-void RFBoV::getPositions(const RegionGraph &rg, const NICE::Matrix &mask, VVector &positions)
-{
-	assert(rg.size() > 0);
-	vector<int> featinreg(rg.size(), 0);
-	int x0 = grid/2;
-	for(int y = 0; y < (int)mask.cols(); y+=grid)
-	{
-		for(int x = x0; x < (int)mask.rows(); x+=grid)
-		{
-			int r = (int)mask(x,y);
-			for(int s = 0; s < (int)scales.size(); s++)
-			{
-				featinreg[r]++;
-				Vector vec(3);
-				vec[0] = x;
-				vec[1] = y;
-				vec[2] = scales[s];
-				positions.push_back(vec);
-			}
-		}
-		if(x0 == 0)
-		{
-			x0 = grid/2;
-		}
-		else
-		{
-			x0 = 0;
-		}
-	}
-
-	for(int i = 0; i < (int)featinreg.size(); i++)
-	{
-		if(featinreg[i] == 0)
-		{
-			int x, y;
-			rg[i]->getCentroid(x,y);
-			for(int s = 0; s < (int)scales.size(); s++)
-			{
-				Vector vec(3);
-				vec[0] = x;
-				vec[1] = y;
-				vec[2] = scales[s];
-				positions.push_back(vec);
-				//FIXME: Achtung es kann in seltenen Fällen vorkommen, dass der Mittelpunkt einer Region nicht zur Region gehört -> abfangen
-			}
-		}
-	}
-}
-
-RFBoV::~RFBoV()
-{
-}

+ 0 - 103
features/regionfeatures/RFBoV.h

@@ -1,103 +0,0 @@
-/** 
-* @file RFBoV.h
-* @brief Bag of Visual Words with an local feature
-* @author Björn Fröhlich
-* @date 02-11-2010
-*/
-#ifndef RFBoVINCLUDE
-#define RFBoVINCLUDE
-
-#include <vislearning/nice.h>
-
-#include "core/basics/Config.h"
-#include "vislearning/cbaselib/LabeledSet.h"
-#include "vislearning/segmentation/RegionGraph.h"
-#include "vislearning/features/localfeatures/LocalFeature.h"
-
-#include "vislearning/math/ftransform/PCA.h"
-#include "vislearning/math/cluster/GMM.h"
-#include "vislearning/features/regionfeatures/RegionFeatures.h"
-
-
-namespace OBJREC {
-
-class RFBoV : public RegionFeatures
-{
-    protected:
-		//! local feature extraction method
-		LocalFeature *lf;
-		
-		//! used scales for SIFT features
-		std::vector<double> scales;
-		
-		//! distances between features
-		int grid;
-		
-		PCA *pca;
-		GMM *gmm;
-		
-				
-    public:
-  
-	/** simple constructor */
-	RFBoV( const NICE::Config *_conf, LocalFeature *_lf );
-
-	/** simple destructor */
-	virtual ~RFBoV();
-
-	/**
-	 * extracts the features for region rg (displayed in mask)
-	 * @param img input image
-	 * @param rg input region graph
-	 * @param mask input region map
-	 * @param feats output features (in order of rg)
-	 * @return 
-	 */
-	virtual void extract ( const NICE::Image & img, const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector & feats );
-        
-	/**
-	 * set the gmm
-	 * @param _gmm 
-	 */
-	void setGMM(GMM *_gmm);
-
-	/**
-	 * set the pca
-	 * @param _pca 
-	 */
-	void setPCA(PCA *_pca);
-	
-	/**
-	 * extracts the features for region rg (displayed in mask)
-	 * using colorimages
-	 * @param cimg input image
-	 * @param rg input region graph
-	 * @param mask input region map
-	 * @param feats output features (in order of rg)
-	 * @return 
-		 */
-	virtual void extractRGB ( const NICE::ColorImage & cimg, const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector & feats );
-	
-	/**
-	 * get the relevant positions
-	 * @param rg 
-	 * @param mask 
-	 * @param positions 
-	 */
-	void getPositions(const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector &positions);
-	
-	/**
-	 * bags the features for each region
-	 * @param mask region mask
-	 * @param rg region graph
-	 * @param infeats input features for image
-	 * @param outfeats output features for regions
-	 * @param positions positions of the input features
-	 */
-	virtual void convert(const NICE::Matrix &mask, const RegionGraph &rg, NICE::VVector &infeats, NICE::VVector &outfeats, 
-VVector &positions);
-};
-
-} // namespace
-
-#endif

+ 0 - 62
features/regionfeatures/RFBoVCodebook.cpp

@@ -1,62 +0,0 @@
-#ifdef NICE_USELIB_OPENMP
-#include <omp.h>
-#endif
-
-#include "vislearning/features/regionfeatures/RFBoVCodebook.h"
-
-#include <iostream>
-#include "core/basics/Timer.h"
-using namespace OBJREC;
-using namespace std;
-using namespace NICE;
-
-
-RFBoVCodebook::RFBoVCodebook( const Config *_conf, LocalFeature *_lf ):RFBoV(_conf, _lf)
-{
-	cb = NULL;
-}
-
-void RFBoVCodebook::setCodebook(Codebook *_cb){
-	cb = _cb;
-}
-
-void RFBoVCodebook::convert(const Matrix &mask, const RegionGraph &rg, VVector &infeats, VVector &outfeats, VVector &positions)
-{
-	int fsize = conf->gI("BoVMoosmann", "codebooksize", 1024);
-	for(int i = 0; i < (int)rg.size(); i++)
-	{
-		Vector v(fsize);
-		v.set(0.0);
-		outfeats.push_back(v);
-	}
-	vector<double> counter(rg.size(), 0.0);
-
-#pragma omp parallel for
-	for(int i = 0; i < (int)infeats.size(); i++)
-	{
-		SparseVector probs;
-
-		cb->vote(infeats[i], probs);
-
-		int r = mask(positions[i][0], positions[i][1]);
-
-#pragma omp critical
-		{
-			for(int j = 0; j < fsize; j++)
-			{
-				double val = probs.get(j);
-				outfeats[r][j] += val;
-				counter[r] += val;
-			}
-		}
-	}
-
-	for(int i = 0; i < (int)rg.size(); i++)
-	{
-		outfeats[i] /= counter[i];
-	}
-}
-
-RFBoVCodebook::~RFBoVCodebook()
-{
-}

+ 0 - 60
features/regionfeatures/RFBoVCodebook.h

@@ -1,60 +0,0 @@
-/** 
- * @file RFBoVCodebook.h
-* @brief Bag of Visual Words with an local feature
-* @author Björn Fröhlich
-* @date 02-11-2010
-*/
-#ifndef RFBoVCodebookINCLUDE
-#define RFBoVCodebookINCLUDE
-
-#include <vislearning/nice.h>
-
-#include "core/basics/Config.h"
-#include "vislearning/cbaselib/LabeledSet.h"
-#include "vislearning/segmentation/RegionGraph.h"
-#include "vislearning/features/localfeatures/LocalFeature.h"
-
-#include "vislearning/math/ftransform/PCA.h"
-#include "vislearning/math/cluster/GMM.h"
-#include "vislearning/features/regionfeatures/RegionFeatures.h"
-#include "vislearning/features/regionfeatures/RFBoV.h"
-
-#include "vislearning/features/simplefeatures/Codebook.h"
-
-namespace OBJREC {
-
-class RFBoVCodebook : public RFBoV
-{
-    protected:
-		//! codebook
-		Codebook *cb;
-			
-    public:
-  
-	/** simple constructor */
-	RFBoVCodebook( const NICE::Config *_conf, LocalFeature *_lf );
-
-	/** simple destructor */
-	virtual ~RFBoVCodebook();
- 
-	/**
-	 * set the codebook
-	 * @param _cb codebook
-	 */
-	void setCodebook(Codebook *_cb);
-	
-	/**
-	 * bags the features for each region
-	 * @param mask region mask
-	 * @param rg region graph
-	 * @param infeats input features for image
-	 * @param outfeats output features for regions
-	 * @param positions positions of the input features
-	 */
-	void convert(const NICE::Matrix &mask, const RegionGraph &rg, NICE::VVector &infeats, NICE::VVector &outfeats, NICE::VVector 
-&positions);
-};
-
-} // namespace
-
-#endif

+ 0 - 64
features/regionfeatures/RFColor.cpp

@@ -1,64 +0,0 @@
-#include "vislearning/features/regionfeatures/RFColor.h"
-
-#include <iostream>
-
-using namespace OBJREC;
-
-using namespace std;
-using namespace NICE;
-
-
-RFColor::RFColor( const Config *_conf, const LocalFeature *_lf ):RegionFeatures(_conf)
-{
-	lf = _lf;
-}
-
-void RFColor::extract ( const NICE::Image & img, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
-{
-	fprintf (stderr, "RFColor::extract: please use ColorImage instead of GrayImage. This are Colorfeatures!!\n");
-    exit(-1);
-}
-
-void RFColor::extractRGB ( const NICE::ColorImage & cimg, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
-{
-	int rgcount = rg.size();
-	vector<vector<int> > means;
-	for(int i = 0; i < 3; i ++)
-	{
-		vector<int> m(rgcount,0);
-		means.push_back(m);
-	}
-		
-	for(int y = 0; y < cimg.height(); y++)
-	{
-		for(int x = 0; x < cimg.width(); x++)
-		{
-			int pos = mask(x,y);
-			for(int i = 0; i < 3; i++)
-			{
-				means[i][(int)pos] += cimg.getPixel(x,y,i);
-			}
-		}
-	}
-		
-	ColorImage tmp(rgcount, 1);
-		
-	VVector positions;
-	for(int j = 0; j < rgcount; j++)
-	{
-		for(int i = 0; i < 3; i++)
-		{
-			tmp.setPixel(j,0,i,(int)((double)means[i][j]/(double)rg[j]->getSize()));
-		}
-		Vector vec(2);
-		vec[0] = j;
-		vec[1] = 0;
-		positions.push_back(vec);
-	}
-	lf->getDescriptors(tmp, positions, feats);
-}
-
-RFColor::~RFColor()
-{
-	
-}

+ 0 - 59
features/regionfeatures/RFColor.h

@@ -1,59 +0,0 @@
-/** 
-* @file RFColor.h
-* @brief computes the average color for each region and uses this with a local feature
-* @author Björn Fröhlich
-* @date 02-10-2010
-*/
-#ifndef RFColorINCLUDE
-#define RFColorINCLUDE
-
-#include <vislearning/nice.h>
-
-#include "core/basics/Config.h"
-#include "vislearning/cbaselib/LabeledSet.h"
-#include "vislearning/segmentation/RegionGraph.h"
-#include "vislearning/features/localfeatures/LocalFeature.h"
-#include "vislearning/features/regionfeatures/RegionFeatures.h"
-
-namespace OBJREC {
-
-class RFColor: public RegionFeatures
-{
-    protected:
-		//! pointer to used local feature
-		const LocalFeature *lf;
-
-    public:
-  
-	/** simple constructor */
-	RFColor( const NICE::Config *conf, const LocalFeature *_lf );
-
-	/** simple destructor */
-	virtual ~RFColor();
-
-
-	/**
-	 * extracts the features for region rg (displayed in mask)
-	 * @param img input image
-	 * @param rg input region graph
-	 * @param mask input region map
-	 * @param feats output features (in order of rg)
-	 * @return 
-	 */
-	virtual void extract ( const NICE::Image & img, const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector & feats );
-        
-	/**
-	 * extracts the features for region rg (displayed in mask)
-	 * using colorimages
-	 * @param cimg input image
-	 * @param rg input region graph
-	 * @param mask input region map
-	 * @param feats output features (in order of rg)
-	 * @return 
-	 */
-	virtual void extractRGB ( const NICE::ColorImage & cimg, const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector & feats );
-};
-
-} // namespace
-
-#endif

+ 0 - 340
features/regionfeatures/RFCsurka.cpp

@@ -1,340 +0,0 @@
-#include "vislearning/features/regionfeatures/RFCsurka.h"
-
-#include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
-#include "vislearning/classifier/fpclassifier/logisticregression/FPCSMLR.h"
-
-#include "core/image/Filter.h"
-
-#include <iostream>
-
-using namespace OBJREC;
-using namespace std;
-using namespace NICE;
-
-
-RFCsurka::RFCsurka( const Config *_conf, LocalFeature *_lf ):RFBoV(_conf, _lf)
-{
-	lf = _lf;
-	string sscales = conf->gS("SIFTTest", "scales", "1+2.0+3.0");
-	grid = conf->gI("SIFTTest", "grid", 20);
-	sigmaweight = conf->gD ( "RFCsurka", "sigmaweight", 0.2 );
-	
-	string::size_type pos = 0;
-	string::size_type oldpos = 0;
-	while(pos != string::npos)
-	{
-		pos = sscales.find("+", oldpos);
-		string val;
-		if(pos == string::npos)
-			val = sscales.substr(oldpos);
-		else
-			val = sscales.substr(oldpos, pos-oldpos);
-		double d = atof(val.c_str());
-		scales.push_back(d);
-		oldpos = pos+1;
-	}
-	gmm = NULL;
-	pca = NULL;
-	fpc = NULL;
-	vec = NULL;
-}
-
-RFCsurka::~RFCsurka()
-{
-}
-
-void RFCsurka::setPCA(PCA *_pca)
-{
-	pca = _pca;
-}
-
-void RFCsurka::setGMM(GMM *_gmm)
-{
-	gmm = _gmm;
-}
-
-void RFCsurka::setClassifier(FeaturePoolClassifier *_fpc)
-{
-	fpc = _fpc;
-	vec = NULL;
-	nbclasses = fpc->getMaxClassNo ()+1;
-}
-
-void RFCsurka::setClassifier(VecClassifier *_vec)
-{
-	vec = _vec;
-	fpc = NULL;
-	nbclasses = vec->getMaxClassNo ()+1;
-}
-	
-		
-void RFCsurka::extract ( const NICE::Image & img, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
-{
-	VVector positions, features;
-	getPositions(rg, mask, positions);
-	lf->getDescriptors(img, positions, features);
-	assert(features.size() == positions.size());
-	convert(mask, rg, features, feats, positions);
-}
-
-void RFCsurka::extractRGB ( const NICE::ColorImage & cimg, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
-{
-	assert(fpc != NULL || vec != NULL);
-	VVector positions, features;
-
-	getPositions(rg, mask, positions);
-
-	lf->getDescriptors(cimg, positions, features);
-
-	assert(features.size() == positions.size());
-
-	convert(mask, rg, features, feats, positions);
-
-}
-
-void RFCsurka::convert(const Matrix &mask, const RegionGraph &rg, VVector &infeats, VVector &outfeats, VVector &positions)
-{
-	outfeats.reSize(rg.size(),nbclasses);
-
-	bool usepca = false;
-	bool usegmm = false;
-	
-	if(pca != NULL)
-		usepca = true;
-	
-	if(gmm != NULL)
-		usegmm = true;
-
-	set<double> scales;
-	map<double,int> scalesmap;
-
-	for(int i = 0; i < (int)infeats.size(); i++)
-	{
-		scales.insert(positions[i][2]);
-	}
-
-	int s = 0;
-	for(set<double>::const_iterator iter = scales.begin(); iter != scales.end(); ++iter, s++)
-	{
-		scalesmap[*iter] = s;
-	}
-
-	int xsize = mask.rows();
-	int ysize = mask.cols();
-
-	MultiChannelImageT<double> preMap ( xsize,ysize,nbclasses*scales.size(),true );
-	MultiChannelImageT<double> probabilities ( xsize, ysize, nbclasses, true);
-	preMap.setAll(0.0);
-	probabilities.setAll(0.0);
-
-	// Die Wahrscheinlichkeitsmaps mit den einzelnen Wahrscheinlichkeiten je Skalierung füllen
-	for(int i = 0; i < (int)infeats.size(); i++)
-	{
-		Vector *feat = new Vector(infeats[i]);
-		Example ex(feat);
-		if(usepca)
-			*ex.vec = pca->getFeatureVector ( *ex.vec, true );
-		if(usegmm)
-		{
-			Vector probs;
-			gmm->getProbs(*ex.vec, probs);
-			*ex.vec = probs;
-		}
-		
-
-
-		ClassificationResult r;
-		
-		if(fpc != NULL)
-			r = fpc->classify ( ex );		
-		else
-			r = vec->classify(*ex.vec);
-
-		for ( int j = 0 ; j < ( int ) probabilities.numChannels; j++ )
-			preMap.set ( positions[i][0],positions[i][1],r.scores[j],j+scalesmap[positions[i][2]]*nbclasses);
-		delete ex.vec;
-		ex.vec = NULL;
-	}
-	
-	s = 0;
-
-	vector<double> sigmavec;
-	for(set<double>::const_iterator iter = scales.begin(); iter != scales.end(); ++iter, s++)
-	{
-		double sigma = sigmaweight*16.0* (*iter);
-		sigmavec.push_back(sigma);
-	}
-
-
-	for(int s = 0; s < (int)sigmavec.size(); s++)
-	{
-		double sigma = sigmavec[s];
-		cerr << "sigma: " << sigma << endl;
-#pragma omp parallel for
-		for ( int i = 0; i < nbclasses; i++ )
-		{
-			int pos = i+s*nbclasses;
-			
-			double maxval = preMap.data[pos][0];
-			double minval = preMap.data[pos][0];
-
-			for ( int z = 1; z < xsize*ysize; z++ )
-			{
-				maxval = std::max ( maxval, preMap.data[pos][z] );
-				minval = std::min ( minval, preMap.data[pos][z] );
-			}
-
-			NICE::FloatImage dblImg( xsize, ysize);
-			NICE::FloatImage gaussImg( xsize, ysize);
-
-			long int offset = 0;
-			for ( int y = 0; y < ysize; y++ )
-			{
-				for ( int x = 0; x < xsize; x++, offset++ )
-				{
-					dblImg.setPixel(x,y,preMap.data[pos][offset]);
-				}
-			}
-
-			filterGaussSigmaApproximate<float,float,float>( dblImg, sigma, &gaussImg );
-
-			offset = 0;
-			for ( int y = 0; y < ysize; y++ )
-			{
-				for ( int x = 0; x < xsize; x++, offset++ )
-				{
-					preMap.data[pos][offset]=gaussImg.getPixel(x,y);
-				}
-			}
-		}
-	}
-
-	int scalesize = scales.size();
-	
-	// Zusammenfassen und auswerten
-#pragma omp parallel for
-	for ( int x = 0; x < xsize; x++ )
-	{
-		for ( int y = 0; y < ysize; y++ )
-		{
-			for ( int j = 0 ; j < ( int ) probabilities.numChannels; j++ )
-			{
-				double prob = 0.0;
-				for ( int s = 0; s < ( int ) scalesize; s++ )
-				{
-
-					prob+=preMap.get ( x,y,j+s*nbclasses );
-
-				}
-
-				double val = prob / ( double ) ( scalesize );
-				probabilities.set ( x,y,val, j );
-			}
-		}
-	}
-	
-	// Wahrscheinlichkeiten für Regionen bestimmen
-	for ( int x = 0; x < xsize; x++ )
-	{
-		for ( int y = 0; y < ysize; y++ )
-		{
-			for ( int j = 0 ; j < ( int ) probabilities.numChannels; j++ )
-			{
-				int r = mask(x,y);
-				double val = probabilities.get ( x,y,j );
-				outfeats[r][j] += val;
-			}
-		}
-	}
-	
-#pragma omp parallel for
-	for(int i = 0; i < (int)outfeats.size(); i++)
-	{
-
-		double sum = 0.0;
-
-		for(int j = 0; j < (int)outfeats[i].size(); j++)
-		{
-			sum += outfeats[i][j];
-		}
-		for(int j = 0; j < (int)outfeats[i].size(); j++)
-		{
-			outfeats[i][j]/=sum;
-		}
-	}
-
-#undef VISSEMSEG
-#ifdef VISSEMSEG
-// 	showImage(img);
-	for ( int j = 0 ; j < ( int ) probabilities.numChannels; j++ )
-	{
-		cout << "klasse: " << j << endl;//" " << cn.text ( j ) << endl;
-
-		NICE::Matrix tmp ( probabilities.ysize, probabilities.xsize );
-		double maxval = 0.0;
-		for ( int y = 0; y < probabilities.ysize; y++ )
-			for ( int x = 0; x < probabilities.xsize; x++ )
-			{
-				double val = probabilities.get ( x,y,j );
-				tmp(y, x) = val;
-				maxval = std::max ( val, maxval );
-			}
-
-		NICE::ColorImage imgrgb (probabilities.xsize, probabilities.ysize);
-		ICETools::convertToRGB ( tmp, imgrgb );
-
-		cout << "maxval = " << maxval << " for class " << j << endl; //cn.text ( j ) << endl;
-		imgrgb.write("out.ppm");
-		showImage(imgrgb, "Ergebnis");
-	}
-#endif
-}
-
-void RFCsurka::getPositions(const RegionGraph &rg, const NICE::Matrix &mask, VVector &positions)
-{
-	vector<int> featinreg(rg.size(), 0);
-	int x0 = grid/2;
-
-	for(int y = 0; y < (int)mask.cols(); y+=grid)
-	{
-		for(int x = x0; x < (int)mask.rows(); x+=grid)
-		{
-			int r = (int)mask(x,y);
-			for(int s = 0; s < (int)scales.size(); s++)
-			{
-				featinreg[r]++;
-				Vector vec(3);
-				vec[0] = x;
-				vec[1] = y;
-				vec[2] = scales[s];
-				positions.push_back(vec);
-			}
-		}
-		if(x0 == 0)
-		{
-			x0 = grid/2;
-		}
-		else
-		{
-			x0 = 0;
-		}
-	}
-
-	for(int i = 0; i < (int)featinreg.size(); i++)
-	{
-		if(featinreg[i] == 0)
-		{
-			int x, y;
-			rg[i]->getCentroid(x,y);
-			for(int s = 0; s < (int)scales.size(); s++)
-			{
-				Vector vec(3);
-				vec[0] = x;
-				vec[1] = y;
-				vec[2] = scales[s];
-				positions.push_back(vec);
-				//FIXME: Achtung es kann in seltenen Fällen vorkommen, dass der Mittelpunkt einer kleinen Region nicht zur Region gehört -> abfangen
-			}
-		}
-	}
-}

+ 0 - 124
features/regionfeatures/RFCsurka.h

@@ -1,124 +0,0 @@
-/** 
- * @file RFCsurka.h
- * @brief Classification result similiar Csurka08 as region features
- * @author Björn Fröhlich
- * @date 02-11-2010
- */
-
-#ifndef RFCsurkaINCLUDE
-#define RFCsurkaINCLUDE
-
-#include <vislearning/nice.h>
-
-#include "core/basics/Config.h"
-#include "vislearning/cbaselib/LabeledSet.h"
-#include "vislearning/segmentation/RegionGraph.h"
-#include "vislearning/features/localfeatures/LocalFeature.h"
-
-#include "vislearning/math/ftransform/PCA.h"
-#include "vislearning/math/cluster/GMM.h"
-#include "vislearning/features/regionfeatures/RFBoV.h"
-
-#include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
-#include "vislearning/classifier/classifierbase/VecClassifier.h"
-
-
-namespace OBJREC {
-
-class RFCsurka : public RFBoV
-{
-    protected:
-		//! local feature extraction method
-		LocalFeature *lf;
-		
-		//! used scales for SIFT features
-		std::vector<double> scales;
-		
-		//! distances between features
-		int grid;
-		
-		//! Feature Transformations
-		PCA *pca;
-		GMM *gmm;
-		
-		//! classifier
-		FeaturePoolClassifier *fpc;
-		VecClassifier *vec;
-		
-		//! number of classes
-		int nbclasses;
-		
-		//! weight for smoothing image
-		double sigmaweight;
-				
-    public:
-  
-	/** simple constructor */
-	RFCsurka( const NICE::Config *_conf, LocalFeature *_lf );
-
-	/** simple destructor */
-	virtual ~RFCsurka();
-
-	/**
-	 * extracts the features for region rg (displayed in mask)
-	 * @param img input image
-	 * @param rg input region graph
-	 * @param mask input region map
-	 * @param feats output features (in order of rg)
-	 * @return 
-	 */
-	virtual void extract ( const NICE::Image & img, const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector & feats );
-        
-	/**
-	 * set the gmm
-	 * @param _gmm 
-	 */
-	void setGMM(GMM *_gmm);
-
-	/**
-	 * set the pca
-	 * @param _pca 
-	 */
-	void setPCA(PCA *_pca);
-	
-	/**
-	 * set the classifier
-	 * @param _fpc classifier
-	 */
-	void setClassifier(FeaturePoolClassifier *_fpc);
-	void setClassifier(VecClassifier *_vec);
-	
-	/**
-	 * extracts the features for region rg (displayed in mask)
-	 * using colorimages
-	 * @param cimg input image
-	 * @param rg input region graph
-	 * @param mask input region map
-	 * @param feats output features (in order of rg)
-	 * @return 
-		 */
-	virtual void extractRGB ( const NICE::ColorImage & cimg, const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector & feats );
-	
-	/**
-	 * get the relevant positions
-	 * @param rg 
-	 * @param mask 
-	 * @param positions 
-	 */
-	void getPositions(const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector &positions);
-	
-	/**
-	 * bags the features for each region
-	 * @param mask region mask
-	 * @param rg region graph
-	 * @param infeats input features for image
-	 * @param outfeats output features for regions
-	 * @param positions positions of the input features
-	 */
-	void convert(const NICE::Matrix &mask, const RegionGraph &rg, NICE::VVector &infeats, NICE::VVector &outfeats, NICE::VVector 
-&positions);
-};
-
-} // namespace
-
-#endif

+ 0 - 120
features/regionfeatures/RFHoG.cpp

@@ -1,120 +0,0 @@
-#ifdef NICE_USELIB_OPENMP
-#include <omp.h>
-#endif
-
-#include "vislearning/features/regionfeatures/RFHoG.h"
-
-#include <iostream>
-#include "vislearning/baselib/FastFilter.h"
-
-using namespace OBJREC;
-
-using namespace std;
-using namespace NICE;
-
-
-RFHoG::RFHoG( const Config *_conf):RFStruct(_conf)
-{
-	numBins = conf->gI( "RFHoG", "numbins", 8 );
-	usesigned = conf->gB( "RFHoG", "usesigned", false );
-    
-	amount_cell_x = conf->gI("RFHoG", "cell_x", 4 );
-	amount_cell_y = conf->gI("RFHoG", "cell_y", 4 );
-	block_x = conf->gI("RFHoG", "block_x", 2 );
-	block_y = conf->gI("RFHoG", "block_y", 2 );
-}
-
-void RFHoG::extract ( const NICE::FloatImage &imgd_gradient, const NICE::Image &imgd_graddir, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
-{
-	int rgsize = rg.size();
-	
-	int block_part_x = amount_cell_x - block_x + 1;
-	int block_part_y = amount_cell_y - block_y + 1;
-	
-	for(int r = 0; r < rgsize; r++)
-	{
-		Vector v(block_part_x * block_part_y * block_x * block_y * numBins);
-		feats.push_back(v);
-	}
-	
-#pragma omp parallel for
-	for(int r = 0; r < rgsize; r++)
-	{
-		// ***** 6.3 Spatial/Orientation binning *****
-		int x0,y0,x1,y1;
-		rg[r]->getRect(x0,y0,x1,y1);
-		double x_size = x1-x0;
-		double y_size = y1-y0;
-		double width = imgd_gradient.width();
-		double height = imgd_gradient.height();
-		int cell_x = int ( ceil( x_size / amount_cell_x ) );
-		int cell_y = int ( ceil( y_size / amount_cell_y ) );
-
-		vector<vector<double> > array_cell_hist_vec;
-		int pos = 0;
-		for (int i = 0; i < amount_cell_x; i++){
-			for (int j = 0; j < amount_cell_y; j++, pos++){
-				vector<double> cell_hist_vec(numBins,0);
-				array_cell_hist_vec.push_back(cell_hist_vec);
-				for (int k = 0; k < cell_x; k++){
-					int x_coord, y_coord;
-					for (int l = 0; l < cell_y; l++){
-						x_coord = i*cell_x + k + x0;
-						y_coord = j*cell_y + l + y0;
-						if ((x_coord <= x1) && (y_coord <= y_size+y1) && x_coord < width && y_coord < height){
-							int reg = mask(x_coord, y_coord);
-							//!TODO: eventuell auch mal ausprobieren mit Pixeln in Bounding Box, die nicht zur Region gehören
-							if(reg != r)
-								continue;
-							
-							double gradient = imgd_gradient.getPixel(x_coord,y_coord);
-							int graddir = imgd_graddir.getPixel(x_coord,y_coord);
-							array_cell_hist_vec[pos][graddir] += gradient;
-						}
-						else break;
-					}
-				}
-			}
-		}
-	// **************************************************
-	
-	// ***** 6.4 Normalization and Descriptor Block *****	
-		int co = 0;
-		for (int i = 0; i < block_part_x; i++)
-		{
-			for (int j = 0; j < block_part_y; j++)
-			{
-				vector<double> fdi;	// final descriptor intermediate
-				for (int k = 0; k < block_x; k++)
-				{
-					for (int l = 0; l < block_y; l++)
-					{
-						int number = (i+k)*amount_cell_y + (j+l);
-						fdi.insert(fdi.begin(),array_cell_hist_vec.at(number).begin(),array_cell_hist_vec.at(number).end());
-					}
-				}
-				vector<double>::iterator it;
-				it = fdi.begin();
-				double norm_factor = 1e-10;	//epsilon^2
-				while(it!=fdi.end())
-				{
-					norm_factor += (*it)*(*it);
-					it++;
-				}
-				double sqrt_norm_factor = sqrt(norm_factor);
-				it = fdi.begin();
-				while(it!=fdi.end())
-				{
-					feats[r][co] = (*it) / sqrt_norm_factor;
-					it++;
-					co++;
-				}
-			}		
-		}
-	}
-}
-
-RFHoG::~RFHoG()
-{
-	
-}

+ 0 - 53
features/regionfeatures/RFHoG.h

@@ -1,53 +0,0 @@
-/** 
-* @file RFHoG.h
-* @brief computes the HoG features for each region
-* @author Björn Fröhlich and Alexander Arest
-* @date 02-10-2010
-*/
-#ifndef RFHoGINCLUDE
-#define RFHoGINCLUDE
-
-#include <vislearning/nice.h>
-
-#include "core/basics/Config.h"
-#include "vislearning/cbaselib/LabeledSet.h"
-#include "vislearning/segmentation/RegionGraph.h"
-#include "vislearning/features/localfeatures/LocalFeature.h"
-#include "vislearning/features/regionfeatures/RegionFeatures.h"
-#include "vislearning/features/regionfeatures/RFStruct.h"
-
-namespace OBJREC {
-
-class RFHoG: public RFStruct
-{
-    protected:
-		/** @{ feature parameter */
-		int amount_cell_x; // Amount of cells in x-Axis
-		int amount_cell_y; // Amount of cells in y-Axis
-		int block_x;
-		int block_y;
-
-		/** @} */
-		
-    public:
-  
-	/** simple constructor */
-	RFHoG( const NICE::Config *conf);
-
-	/** simple destructor */
-	virtual ~RFHoG();
-	
-	/**
-	 * extracts the features for region rg (displayed in mask)
-	 * @param imgd_gradient allready computed gradientsmagnitudes
-	 * @param imgd_graddir allready computed gradientsdirection
-	 * @param rg input region graph
-	 * @param mask input region map
-	 * @param feats output features (in order of rg)
-	 */
-	virtual void extract ( const NICE::FloatImage &imgd_gradient, const NICE::Image &imgd_graddir, const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector & feats );
-};
-
-} // namespace
-
-#endif

+ 0 - 131
features/regionfeatures/RFStruct.cpp

@@ -1,131 +0,0 @@
-#ifdef NICE_USELIB_OPENMP
-#include <omp.h>
-#endif
-
-#include "vislearning/features/regionfeatures/RFStruct.h"
-
-#include <iostream>
-#include "vislearning/baselib/FastFilter.h"
-
-using namespace OBJREC;
-
-using namespace std;
-using namespace NICE;
-
-
-RFStruct::RFStruct( const Config *_conf):RegionFeatures(_conf)
-{
-	numBins = conf->gI( "RFStruct", "numbins", 8 );
-	usesigned = conf->gB( "RFStruct", "usesigned", false );
-}
-
-
-void RFStruct::extract ( const NICE::Image & img, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
-{
-	const unsigned char *imgdraw = img.getPixelPointerXY(0,0);
-
-	float *gradient = new float[ img.width() * img.height() ];
-
-	unsigned char *graddir = new unsigned char[ img.width() * img.height() ];
-	
-	FastFilter::calcGradient<const unsigned char,float,unsigned char> ( imgdraw, img.width(), img.height(), gradient, graddir, numBins, usesigned );
-
-	NICE::FloatImage imgd_gradient(gradient, img.width(), img.height(), GrayColorImageCommonImplementation::noAlignment);
-	NICE::Image imgd_graddir(graddir, img.width(), img.height(), GrayColorImageCommonImplementation::noAlignment);
-
-	/*
-	Image tmp;
-	floatToGray(imgd_gradient, &tmp);		
-	showImage(tmp, "Grad");*/
-		
-	extract ( imgd_gradient, imgd_graddir, rg, mask, feats );
-	
-	delete [] gradient;
-	delete [] graddir;
-}
-
-void RFStruct::extractRGB ( const NICE::ColorImage & cimg, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
-{
-	unsigned char *imgdraw[3];
-
-	for(int i = 0; i < 3; i++)
-	{
-		imgdraw[i] = new unsigned char[ cimg.width() * cimg.height() ];
-		long int k = 0;
-		for(int y = 0; y < cimg.height(); y++)
-		{
-			for(int x = 0; x < cimg.width(); x++, k++)
-			{
-				imgdraw[i][k] = cimg.getPixel(x,y,i);
-			}
-		}
-	}
-
-	float *gradient = new float[ cimg.width() * cimg.height() ];
-
-	unsigned char *graddir = new unsigned char[ cimg.width() * cimg.height() ];
-	
-	FastFilter::calcColorGradient<unsigned char,float,unsigned char> ( imgdraw[0],imgdraw[1],imgdraw[2], cimg.width(), cimg.height(), gradient, graddir, numBins, usesigned );
-
-	NICE::FloatImage imgd_gradient(gradient, cimg.width(), cimg.height(), GrayColorImageCommonImplementation::noAlignment);
-	NICE::Image imgd_graddir(graddir, cimg.width(), cimg.height(), GrayColorImageCommonImplementation::noAlignment);
-
-	extract ( imgd_gradient, imgd_graddir, rg, mask, feats );
-	
-	for(int i = 0; i < 3; i++)
-	{
-		delete [] imgdraw[i];
-	}
-	delete [] gradient;
-	delete [] graddir;
-}
-
-void RFStruct::extract ( const NICE::FloatImage &imgd_gradient, const NICE::Image &imgd_graddir, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
-{
-	int rgsize = rg.size();
-	feats.clear();
-
-	for(int r = 0; r < rgsize; r++)
-	{
-		Vector f(numBins);
-		f.set(0.0);
-		feats.push_back(f);
-	}
-	
-#pragma omp parallel for
-	for(int r = 0; r < rgsize; r++)
-	{
-		// ***** 6.3 Spatial/Orientation binning *****
-		int x0,y0,x1,y1;
-		rg[r]->getRect(x0,y0,x1,y1);
-							
-		for(int y = y0; y <= y1; y++)
-		{
-			for(int x = x0; x <= x1; x++)
-			{
-				int reg = mask(x, y);
-				if(reg != r)
-					continue;
-							
-				double gradient = imgd_gradient.getPixel(x, y);
-				int graddir = imgd_graddir.getPixel(x, y);
-				feats[r][graddir] += gradient;
-			}
-		}
-		
-		double sum = 0.0;
-		for(int j = 0; j < (int) feats[r].size(); j++)
-		{
-			sum += feats[r][j];
-		}
-		for(int j = 0; j < (int) feats[r].size(); j++)
-		{
-			feats[r][j] /= sum;
-		}
-	}
-}
-
-RFStruct::~RFStruct()
-{
-	
-}

+ 0 - 71
features/regionfeatures/RFStruct.h

@@ -1,71 +0,0 @@
-/** 
-* @file RFStruct.h
-* @brief computes histogram over gradients for each region
-* @author Björn Fröhlich
-* @date 02-10-2010
-*/
-#ifndef RFStructINCLUDE
-#define RFStructINCLUDE
-
-#include <vislearning/nice.h>
-
-#include "core/basics/Config.h"
-#include "vislearning/cbaselib/LabeledSet.h"
-#include "vislearning/segmentation/RegionGraph.h"
-#include "vislearning/features/localfeatures/LocalFeature.h"
-#include "vislearning/features/regionfeatures/RegionFeatures.h"
-
-//!TODO: eventuell eine Rotationsinvariante Normierung durchführen
-
-namespace OBJREC {
-
-class RFStruct: public RegionFeatures
-{
-    protected:
-		int numBins;
-		bool usesigned;
-		
-    public:
-  
-	/** simple constructor */
-	RFStruct( const NICE::Config *conf);
-
-	/** simple destructor */
-	virtual ~RFStruct();
-
-
-	/**
-	 * extracts the features for region rg (displayed in mask)
-	 * @param img input image
-	 * @param rg input region graph
-	 * @param mask input region map
-	 * @param feats output features (in order of rg)
-	 * @return 
-	 */
-	virtual void extract ( const NICE::Image & img, const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector & feats );
-        
-	/**
-	 * extracts the features for region rg (displayed in mask)
-	 * using colorimages
-	 * @param cimg input image
-	 * @param rg input region graph
-	 * @param mask input region map
-	 * @param feats output features (in order of rg)
-	 * @return 
-	 */
-	virtual void extractRGB ( const NICE::ColorImage & cimg, const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector & feats );
-	
-	/**
-	 * extracts the features for region rg (displayed in mask)
-	 * @param imgd_gradient allready computed gradientsmagnitudes
-	 * @param imgd_graddir allready computed gradientsdirection
-	 * @param rg input region graph
-	 * @param mask input region map
-	 * @param feats output features (in order of rg)
-	 */
-	virtual void extract ( const NICE::FloatImage &imgd_gradient, const NICE::Image &imgd_graddir, const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector & feats );
-};
-
-} // namespace
-
-#endif

+ 0 - 32
features/regionfeatures/RegionFeatures.cpp

@@ -1,32 +0,0 @@
-#include "vislearning/features/regionfeatures/RegionFeatures.h"
-
-#include <iostream>
-
-using namespace OBJREC;
-using namespace std;
-using namespace NICE;
-
-
-RegionFeatures::RegionFeatures( const Config *_conf )
-{
-	conf = _conf;
-}
-
-void RegionFeatures::extract ( const NICE::Image & img, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
-{
-	fprintf (stderr, "RegionFeatures::extract: not yet implemented !\n");
-    exit(-1);
-}
-
-void RegionFeatures::extractRGB ( const NICE::ColorImage & cimg, const RegionGraph &rg, const NICE::Matrix &mask, VVector & feats )
-{
-    NICE::Image tmp;
-	rgbToGray(cimg, &tmp);
-	fprintf (stderr, "No Colorfeatures, using GrayImg instead\n");
-	   
-	return extract(tmp, rg, mask, feats);
-}
-
-RegionFeatures::~RegionFeatures()
-{
-}

+ 0 - 56
features/regionfeatures/RegionFeatures.h

@@ -1,56 +0,0 @@
-/** 
-* @file RegionFeatures.h
-* @brief Abstract class for region feature extraction
-* @author Björn Fröhlich
-* @date 02-10-2010
-*/
-#ifndef RegionFeaturesINCLUDE
-#define RegionFeaturesINCLUDE
-
-#include <vislearning/nice.h>
-
-#include "core/basics/Config.h"
-#include "vislearning/cbaselib/LabeledSet.h"
-#include "vislearning/segmentation/RegionGraph.h"
-
-
-namespace OBJREC {
-
-class RegionFeatures
-{
-    protected:
-		const NICE::Config *conf;
-		
-    public:
-  
-	/** simple constructor */
-	RegionFeatures( const NICE::Config *_conf );
-
-	/** simple destructor */
-	virtual ~RegionFeatures();
-
-	/**
-	 * extracts the features for region rg (displayed in mask)
-	 * @param img input image
-	 * @param rg input region graph
-	 * @param mask input region map
-	 * @param feats output features (in order of rg)
-	 * @return 
-	 */
-	virtual void extract ( const NICE::Image & img, const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector & feats );
-        
-	/**
-	 * extracts the features for region rg (displayed in mask)
-	 * using colorimages
-	 * @param cimg input image
-	 * @param rg input region graph
-	 * @param mask input region map
-	 * @param feats output features (in order of rg)
-	 * @return 
-		 */
-	virtual void extractRGB ( const NICE::ColorImage & cimg, const RegionGraph &rg, const NICE::Matrix &mask, NICE::VVector & feats );
-};
-
-} // namespace
-
-#endif