Browse Source

Merge remote branch 'origin/master'

bodesheim 12 years ago
parent
commit
eb21af29b8
37 changed files with 1142 additions and 231 deletions
  1. 15 0
      .gitignore
  2. 2 0
      cbaselib/BoundingBox.cpp
  3. 6 0
      cbaselib/BoundingBox.h
  4. 118 125
      cbaselib/ImageInfo.cpp
  5. 32 4
      cbaselib/ImageInfo.h
  6. 52 26
      cbaselib/LabeledFileList.cpp
  7. 48 25
      cbaselib/LabeledFileList.h
  8. 43 0
      cbaselib/LabeledSetCreatorInterface.h
  9. 66 0
      cbaselib/LabeledSetFactory.cpp
  10. 117 0
      cbaselib/LabeledSetFactory.h
  11. 59 1
      cbaselib/LocalizationResult.cpp
  12. 47 2
      cbaselib/LocalizationResult.h
  13. 17 7
      cbaselib/MultiDataset.cpp
  14. 14 8
      cbaselib/MultiDataset.h
  15. 4 1
      cbaselib/Polygon.cpp
  16. 6 0
      cbaselib/Polygon.h
  17. 1 1
      classifier/kernelclassifier/GPLaplaceOptimizationProblem.h
  18. 2 2
      classifier/kernelclassifier/KCGPLaplace.cpp
  19. 3 3
      classifier/kernelclassifier/KCGPLaplaceOneVsAll.cpp
  20. 3 3
      classifier/kernelclassifier/KCGPRegOneVsAll.cpp
  21. 3 2
      features/fpfeatures/FIGradients.cpp
  22. 7 0
      image/GenericImageTools.h
  23. 4 4
      image/GenericImageTools.tcc
  24. 143 0
      matlabAccessHighLevel/ImageNetData.cpp
  25. 110 0
      matlabAccessHighLevel/ImageNetData.h
  26. 8 0
      matlabAccessHighLevel/Makefile
  27. 103 0
      matlabAccessHighLevel/Makefile.inc
  28. 4 0
      matlabAccessHighLevel/libdepend.inc
  29. 88 0
      matlabAccessHighLevel/progs/Makefile.inc
  30. 1 1
      progs/libdepend.inc
  31. 4 4
      progs/testImageNetBinary.cpp
  32. 2 3
      progs/testImageNetBinaryBruteForce.cpp
  33. 4 3
      progs/testImageNetBinaryGPBaseline.cpp
  34. 1 1
      regression/gpregression/GPRegressionOptimizationProblem.h
  35. 3 3
      regression/gpregression/RegGaussianProcess.cpp
  36. 1 1
      regression/gpregression/modelselcrit/GPMSCLooEstimates.cpp
  37. 1 1
      regression/gpregression/modelselcrit/GPMSCLooEstimates.h

+ 15 - 0
.gitignore

@@ -0,0 +1,15 @@
+# Lines starting with '#' are considered comments.
+# Ignore any file named paper_occ.pdf
+#paper_occ.pdf
+# Ignore (generated) html files,
+#*.html
+#Ignore tex-specific files
+#
+#Think about whether or not to include the resulting moc files
+#*.moc
+# Definitely do not look for temporary files
+*~
+# except foo.html which is maintained by hand.
+#!foo.html
+# Ignore objects and archives.
+#*.[oa]

+ 2 - 0
cbaselib/BoundingBox.cpp

@@ -19,6 +19,7 @@ BoundingBox::BoundingBox()
 	bottom_right_.x = -1;
 	bottom_right_.y = -1;
 	id_ = -1;
+    unique_id_ = -1;
 }
 
 // A copy-constructor
@@ -27,6 +28,7 @@ BoundingBox::BoundingBox(const BoundingBox &copy)
 	top_left_ = copy.topLeft();
 	bottom_right_ = copy.bottomRight();
 	id_ = copy.id();
+    unique_id_ = copy.unique_id_;
 }
 
 //! A desctructor

+ 6 - 0
cbaselib/BoundingBox.h

@@ -42,7 +42,13 @@ class BoundingBox
   private:
     NICE::CoordT< int > top_left_;
     NICE::CoordT< int > bottom_right_;
+
+    /// id interpreted as a class label
     int id_;
+
+public:
+    /// unique id that distinguishs this particular bounding box object from all others
+    int unique_id_;
 };
 
 } //namespace

+ 118 - 125
cbaselib/ImageInfo.cpp

@@ -17,12 +17,16 @@
 #ifdef NICE_USELIB_QT4_XML
 
 #include <QFile>
+#include <QFileInfo>
+#include <QDir>
 #include <QString>
 #include <QByteArray>
 #include <QDomDocument>
 #include <QDomNode>
 #include <QDomElement>
 #include <QPoint>
+#include <QStringList>
+#include <QVariant>
 
 #endif //NICE_USELIB_QT4_XML
 
@@ -85,16 +89,25 @@ ImageInfo::loadImageInfo(const string &aFilename)
 		if(!element.isNull()) {
 			/* path to the image */
 			if (element.tagName() == "image") {
-				string_buffer = element.text();
-				if (string_buffer.isEmpty()) {
+
+                string_buffer = element.text();
+
+                if (string_buffer.isEmpty())
+                {
 					cout << "loadImageInfo:The file with data"
 							" doesn't contain path to the image\n";
 					return false;
-					/* NOTREACHED */
 				}
+                if( QFileInfo(string_buffer).isRelative() )
+                {
+                    QString asd = QFileInfo( QString(aFilename.c_str()) ).absoluteDir().absolutePath();
+
+                    QString qwe = QFileInfo( asd + "/" + string_buffer ).absoluteFilePath();
+
+                    string_buffer = qwe;
+                }
 
-				QByteArray array = string_buffer.toAscii();
-				image_path_ = string(array.data());
+                image_path_ = string_buffer.toStdString();
 			}
 			/* path to the segmented image */
 			if (element.tagName() == "segmented") {
@@ -115,14 +128,11 @@ ImageInfo::loadImageInfo(const string &aFilename)
 			/* tags */
 			else if (element.tagName() == "tags") {
 				string_buffer = element.text();
-				if (string_buffer.isEmpty()) {
-					rootNode = rootNode.nextSibling();
-					cout << "tags are empty\n";
-					continue;
-				}
-				QByteArray array = string_buffer.toAscii();
-				//TODO: make parsing into the string list 
-				tags_ = string(array.data());
+                if ( !string_buffer.isEmpty()) {
+                    QByteArray array = string_buffer.toAscii();
+                    //TODO: make parsing into the string list
+                    tags_ = string(array.data());
+                }
 			}
 			/* legend */
 			else if (element.tagName() == "legend") {
@@ -152,19 +162,41 @@ ImageInfo::loadImageInfo(const string &aFilename)
 						continue;
 					}
 
-					string_buffer = subElement.text();
+                    // try reading a unique object/bounding box id, which identifies
+                    // this object against all others (not a label)
+                    string_buffer = subElement.attribute("uniqueObjectId");
+                    ok = 1;
+                    int uniqueObjectId = string_buffer.toInt(&ok, 10);
+                    if(!ok)
+                        uniqueObjectId = -1;
 
+
+                    string_buffer = subElement.text();
 					if (subElement.tagName() == "bbox") {
-						BoundingBox bbox = BBoxFromData(&string_buffer, id);
-						//bbox.setID(id);
-						bboxes_.push_back(bbox);
+                        BoundingBox bbox;
+                        bool bValid = BBoxFromData(&string_buffer, id, bbox);
+                        if( bValid )
+                        {
+                            bbox.unique_id_ = uniqueObjectId;
+
+                            bboxes_.push_back(bbox);
+                        }
 					}
 					if (subElement.tagName() == "poly") {
-						Polygon poly = polyFromData(&string_buffer);
-						poly.setID(id);
-						polys_.push_back(poly);
+                        Polygon poly;
+                        bool bValid = polyFromData(&string_buffer, poly);
+                        if(bValid)
+                        {
+                            poly.setID(id);
+                            poly.unique_id_ = uniqueObjectId;
+
+                            polys_.push_back(poly);
+                        }
+
 					}
 
+
+
 					subNode = subNode.nextSibling();
 				}
 			}
@@ -316,120 +348,81 @@ ImageInfo::loadCategoryInfo(QDomElement *anElement)
 /*!
  * format is x;y;w;h where w - width and h - height
  */
-BoundingBox
-ImageInfo::BBoxFromData(
-	QString *aBBoxData,
-	int &id
-)
+bool ImageInfo::BBoxFromData( QString *aBBoxData, int &id, BoundingBox &p_bbox )
 {
-	BoundingBox bbox;
-	bbox.setID(id);
-
-	QString buffer;
-	int startPos = 0;
-	bool ok = 1;
-
-	int counter = 0;
-	for (int i = 0; i < aBBoxData->size(); i++) {
-		if (';' != aBBoxData->at(i))
-			continue;
-
-		buffer = aBBoxData->mid(startPos, i - startPos);
-
-		int bboxData = buffer.toInt(&ok, 10);
-		if (!ok) {
-			cout <<
-				"BBoxFromData: "
-				"bbox format is corrupted\n";
-			break;
-		}
-
-		if (!counter) {
-			bbox.setTopLeft(bboxData, 0);
-			counter++;
-		}
-		else if (1 == counter) {
-			int x = bbox.topLeft().x;
-			bbox.setTopLeft(x, bboxData);
-			counter++;
-		}
-		else if (2 == counter) {
-			bbox.setWidth(bboxData);
-			counter++;
-		}
-		else if (3 == counter) {
-			bbox.setHeight(bboxData);
-			counter++;
-		}
-
-		startPos = i + 1;
-	}
-
-	if (!bbox.isValid() || !ok) {
-		cout <<
-			"BBoxFromData: "
-			"bbox format is corrupted\n";
-		bbox.setTopLeft(0, 0);
-		bbox.setBottomRight(0, 0);
-	}
 
-	return bbox;
+    p_bbox.setID(id);
+
+    QStringList coordsList = aBBoxData->split(";", QString::SkipEmptyParts);
+
+    try
+    {
+        if( coordsList.size() == 4)
+        {
+            int x = QVariant(coordsList[0]).toInt();
+            int y = QVariant(coordsList[1]).toInt();
+            int w = QVariant(coordsList[2]).toInt();
+            int h = QVariant(coordsList[3]).toInt();
+
+            p_bbox.setTopLeft(x,y);
+            p_bbox.setWidth( w );
+            p_bbox.setHeight( h );
+        }
+        else
+        {
+            std::cout <<
+                "BBoxFromData: "
+                "bbox format is corrupted\n";
+
+            return false;
+        }
+    }
+    catch(std::exception &e)
+    {
+        std::cout << "BBoxFromData: exception:" << e.what() << std::endl;
+        return false;
+    }
+
+    if ( !p_bbox.isValid() )
+    {
+        std::cout << "BBoxFromData not valid:"<< aBBoxData->toStdString() << std::endl;
+        p_bbox.setTopLeft(0, 0);
+        p_bbox.setBottomRight(0, 0);
+        return false;
+    }
+
+    return true;
 }
 
 //! A protected member parsing string data and returning a Polygon from it
 /*!
  * format is x0;y0;x1;y1;...
  */
-Polygon
-ImageInfo::polyFromData(
-	QString *aPolyData
-)
+bool ImageInfo::polyFromData( QString *aPolyData, Polygon &p_Poly)
 {
-	Polygon poly;
-	QPoint point;
-	QString buffer;
-	int startPos = 0;
-	bool ok = 1;
-	/* indicates whether coordinate x or y */
-	bool evenFlag = 0;
-
-	for (int i = 0; i < aPolyData->size(); i++) {
-		/* ";" is a separator */
-		if (';' != aPolyData->at(i))
-			continue;
-
-		buffer = aPolyData->mid(startPos, i - startPos);
-
-		int polyCoor = buffer.toInt(&ok, 10);
-		if (!ok) {
-			cout <<
-				"polyFromData: "
-				"poly format is corrupted\n";
-			break;
-		}
-
-		if (!evenFlag) {
-			point.setX(polyCoor);
-			evenFlag = 1;
-		}
-		else {
-			point.setY(polyCoor);
-			poly.push(point.x(), point.y());
-			evenFlag = 0;
-		}
-		startPos = i + 1;
-	}
-
-	/* last coordinate was Xi what means an error or
-	   last converting from string was not successful */
-	if (evenFlag || !ok) {
-		cout <<
-			"polyFromData: "
-			"poly format is corrupted\n";
-		//poly.clear();
-	}
-
-	return poly;
+    QStringList coordsList = aPolyData->split(";", QString::SkipEmptyParts);
+    try
+    {
+        if( coordsList.size() % 2 == 0)
+        {
+            for( int i = 0; i < coordsList.size(); i += 2)
+            {
+                p_Poly.push( QVariant(coordsList[i]).toInt(),
+                              QVariant(coordsList[i+1]).toInt() );
+            }
+        }
+        else
+        {
+            std::cout << "polyFromData: not valid (coordinates not multiple of two)" << std::endl;
+            return false;
+        }
+    }
+    catch(std::exception &e)
+    {
+        std::cout << "polyFromData: exception:" << e.what() << std::endl;
+        return false;
+    }
+    return true;
 }
 
 //!

+ 32 - 4
cbaselib/ImageInfo.h

@@ -28,7 +28,22 @@ class QDomElement;
 namespace OBJREC
 {
 
-/** localization info + image filename + ? */
+/**
+ * @brief Class for loading label information created by the ImageLabeler tool.
+ *
+ * The label file format is xml consisting of several sections about the label desription,
+ * occuring objects (such as bounding boxes and polygons) and their label ids, and reference to the
+ * original image file.
+ *
+ * Note: Be aware of the code redundancy of the xml loading presented here and the separate code in the ImageLabeler tool.
+ * Both try to interprete/load the label xml but with different code, so changes at one code place do not affect the other one.
+ *
+ * Second note/todo: in future this class should complete be integrated into LocalizationResult, which also includes bounding box label info
+ * and is more integrated into NICE feature extraction and classification mechanism.
+ * Currently, to convert a loaded label file into a LocalizationResult, use function LocalizationResult::loadImageInfo() (currently only bounding box information).
+ *
+ * localization info + image filename + ?
+ */
 class ImageInfo
 {
 
@@ -39,8 +54,9 @@ class ImageInfo
 
 #ifdef NICE_USELIB_QT4_XML
 
-    Polygon polyFromData ( QString *aPolyData );
-    BoundingBox BBoxFromData ( QString *aBBoxData, int &id );
+    bool polyFromData( QString *aPolyData, Polygon &p_Poly);
+    bool BBoxFromData(QString *aBBoxData, int &id , BoundingBox &p_bbox);
+
     void loadLegendFromElement ( QDomElement *anElement );
     bool loadCategoryInfo ( QDomElement *anElement );
     NICE::ImageT< unsigned int > imageTFromData (
@@ -53,7 +69,11 @@ class ImageInfo
 
   public:
 
-    /** simple constructor */
+    /**
+     * @brief simple constructor
+     * @param _imagefn image file name
+     * @param _lr Localization result containing label information
+     */
     ImageInfo ( const std::string & _imagefn, LocalizationResult *_lr ) :
         imagefn ( _imagefn ), lr ( _lr ), localization_info ( true ) {};
 
@@ -69,6 +89,14 @@ class ImageInfo
     {
       return imagefn;
     };
+
+    /**
+    * @brief Returns available localization information.
+    *
+    * Note: This class doesn't create a new LocalizationResult instance - it only returns the reference to a previously assigned instance (see constructor).
+    * To convert a loaded label file into a LocalizationResult, use function LocalizationResult::loadImageInfo() (currently only bounding box information).
+    * @see LocalizationResult::loadImageInfo()
+    */
     const LocalizationResult *localization () const
     {
       assert ( localization_info );

+ 52 - 26
cbaselib/LabeledFileList.cpp

@@ -32,6 +32,18 @@ LabeledFileList::~LabeledFileList()
 }
 
 
+/**
+ * @brief Loads the label information according to a given label file format.
+ *
+ * Supported types of label file format (localization_format):
+ * - "image": <br>usage of a single channel images containing label regions
+ * - "imagergb": <br>usage of a multi channel color images containing label regions
+ * - "polygon": <br>obtaining bounding boxes from textural label files (used with e.g. PASCAL dataset)
+ * - "imagelabeler": <br>obtaining label information (currently only bounding boxes) from the separate label files (XML like) created with the ImageLabeler ( < file name >_labeled.dat ). @see ImageInfo
+ *
+ * @param classnames class containing all potential class names (label categories)
+ * @param conf configuration structure containing a information from a loaded config file; has to tag "localization_format" in section "main" in order to obtain the correct label information from a file.
+ */
 LocalizationResult *LabeledFileList::getLocalizationInfo ( const ClassNames & classnames,
     int classno,
     const std::string & file,
@@ -95,15 +107,22 @@ LocalizationResult *LabeledFileList::getLocalizationInfo ( const ClassNames & cl
 
     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 )
+	  fprintf (stderr, "LabeledFileList: object localization %d\n", (int)lr->size() );
+    }
+    else if ( format == "imagelabeler" ) {
 
-  if ( debug_dataset )
-    if ( lr != NULL )
-      fprintf ( stderr, "%s (%d objects)\n", lfile.c_str(), ( int ) lr->size() );
+        lr = new LocalizationResult ( &classnames );
+        lr->loadImageInfo(lfile);
+
+    }
+    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;
 }
@@ -251,29 +270,36 @@ void LabeledFileList::getFromList (
     ls.printInformation();
 }
 
-
-void LabeledFileList::get (
-  const std::string & dir,
-  const Config & datasetconf,
-  const ClassNames & classnames,
-  LabeledSet & ls,
-  bool localizationInfoDisabled,
-  bool debugDataset )
+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;
+    std::string pattern = datasetconf.gS("main", "pattern", "");
+    std::string filelist = datasetconf.gS("main", "filelist", "");
+    std::string factoryxmlfile = datasetconf.gS("main", "factoryxml", "");
+
+    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;
+	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 );
-  }
+	getFromList ( filelist, datasetconf, classnames, ls, localizationInfoDisabled );
+    }
+    else if( !factoryxmlfile.empty() &&  m_pLabeledSetFactory != NULL )
+    {
+        factoryxmlfile = ( factoryxmlfile.substr(0,1) == "/" ) ? factoryxmlfile : dir + "/" + factoryxmlfile;
+        m_pLabeledSetFactory->createLabeledSetFromXml( factoryxmlfile, datasetconf,classnames, ls );
+    }
+    else {
+	fprintf (stderr, "LabeledFileList: Unable to obtain labeled file list\n");
+	exit(-1);
+    }
 }

+ 48 - 25
cbaselib/LabeledFileList.h

@@ -15,40 +15,57 @@
 #include "ClassNames.h"
 #include "LocalizationResult.h"
 #include "LabeledSet.h"
+#include "LabeledSetFactory.h"
 
 namespace OBJREC {
 
-/** reads images from directory */
+/**
+ * @brief 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;
+    LabeledSetFactory *m_pLabeledSetFactory;
+
+    public:
+  
+	/** simple constructor */
+	LabeledFileList(); 
+      
+	/** simple destructor */
+	virtual ~LabeledFileList();
+ 
+	LocalizationResult *getLocalizationInfo ( const ClassNames & classnames,
+					    int classno,
+					    const std::string & file,
+					    const NICE::Config & conf ) const;
+
+    /**
+    * @brief extract multiple label information from different sources.
+    *
+    * Different sources specified in the logfile under section "main":
+    *-"pattern" <br>
+    *-"filelist" <br>
+    *-"factoryxml" <br>
+    *  xml file whose information is extracted and inserted into a LabeledSet. In order to use the right xml loader, a factory had to be provided
+    * ( ::setFactory() ). [Johannes Ruehle]
+    * @see LabeledSetFactory
+    */
+	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 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,
@@ -56,6 +73,12 @@ class LabeledFileList
                        LabeledSet & ls,
                        bool localizationInfoDisabled = false ) const;
 
+
+    void setFactory(LabeledSetFactory *pLabeledSetFactory)
+    {
+         m_pLabeledSetFactory = pLabeledSetFactory;
+    }
+
 };
 
 

+ 43 - 0
cbaselib/LabeledSetCreatorInterface.h

@@ -0,0 +1,43 @@
+#ifndef LABELEDSETCREATORINTERFACE_H
+#define LABELEDSETCREATORINTERFACE_H
+
+#include "core/basics/Config.h"
+#include "vislearning/cbaselib/ClassNames.h"
+#include "vislearning/cbaselib/LabeledSet.h"
+
+namespace OBJREC
+{
+
+/**
+ * @brief Interface for extraction of information from xml files.
+ *
+ * This is used to have variable way of creating a LabeledSet from possibly many different xml file formats.
+ * Each xml file has its own interface implementation to enable xml specific loadings.
+ *
+ * @see LabeledSetFactory
+ *
+ * @author Johannes Ruehle
+ * @date 2012/05/18
+ */
+class LabeledSetCreatorInterface
+{
+public:
+    LabeledSetCreatorInterface(){};
+
+    virtual ~LabeledSetCreatorInterface(){};
+
+    /**
+     * @brief Extract label information from a xml file and insert in a LabeledSet data structure.
+     * @param p_sXmlFilename xml file name to load
+     * @param p_LabelSet LabeledSet to be filled by data extracted from the xml file.
+     */
+    virtual void createLabeledSet( std::string    p_sXmlFilename,
+                                   const NICE::Config & p_conf,
+                                   const ClassNames & p_classnames,
+                                   LabeledSet &p_LabelSet) = 0;
+
+};
+
+}//Namespace
+
+#endif // LABELEDSETCREATORINTERFACE_H

+ 66 - 0
cbaselib/LabeledSetFactory.cpp

@@ -0,0 +1,66 @@
+#include <stdio.h>
+
+#include <QDomDocument>
+#include <QFile>
+
+#include "LabeledSetFactory.h"
+
+namespace OBJREC
+{
+
+LabeledSetFactory::LabeledSetFactory()
+{
+}
+
+void LabeledSetFactory::createLabeledSetFromXml(std::string sXmlFilename,
+                                                       const NICE::Config &p_conf,
+                                                       const ClassNames &p_classnames,
+                                                       LabeledSet &p_LabelSet)
+{
+
+    QDomDocument doc("dummy");
+    QFile file(sXmlFilename.c_str());
+    if (!file.open(QIODevice::ReadOnly)) {
+        std::cout << "Can not open such file" << std::endl;
+        return;
+    }
+
+    QString errMsg;
+    if (!doc.setContent(&file, &errMsg)) {
+        std::cout << errMsg.toStdString() << std::endl;
+        file.close();
+        return;
+    }
+
+    file.close();
+
+    /* getting all info */
+    QDomElement elements = doc.documentElement();
+    QDomDocumentType type= doc.doctype();
+    std::string sTypeName = type.name().toStdString();
+
+    //choose appropriate xml-LabeledSet loader according to the documenttype, which had previously been added by ::addCreator
+    LabeledSetCreatorInterface *pCreator = this->m_MapLSCreators[ sTypeName ];
+    if( pCreator == NULL )
+    {
+        std::cout << "LabeledSetFactory::createLabeledSetFromXml No creator found for xml type " << sTypeName << std::endl;
+        return;
+    }
+
+    //call specific loading function for the given xml file.
+    pCreator->createLabeledSet( sXmlFilename, p_conf, p_classnames, p_LabelSet );
+
+}
+
+void LabeledSetFactory::addCreator(std::string sCreatorName, LabeledSetCreatorInterface *pCreator)
+{
+    //is there already a mapper for this document type registered?
+    if (this->m_MapLSCreators.find(sCreatorName) != this->m_MapLSCreators.end() )
+        return;  //element already exist, so don't try to overwrite it
+
+    // store the mapping
+    this->m_MapLSCreators[sCreatorName] = pCreator;
+}
+
+
+}//namespace

+ 117 - 0
cbaselib/LabeledSetFactory.h

@@ -0,0 +1,117 @@
+#ifndef LABELEDSETFACTORY_H
+#define LABELEDSETFACTORY_H
+
+#include <string>
+#include <map>
+
+#include "vislearning/cbaselib/LabeledSet.h"
+#include "LabeledSetCreatorInterface.h"
+
+namespace OBJREC
+{
+
+
+/**
+ * @brief Factory providing xml loading classes according to their document type.
+ *
+ * In order to extract ground truth information or - in general - structured data into a MultiDataset, xml files can be used as
+ * containers of file and label information. This factory is used to choose the right loading function for different xml file formats
+ * according to the stated document type in the xml file (e.g. < !DOCTYPE DaimlerStereoPedRecXml > ). This enables a flexible program design
+ * that can handle loading different xml files at runtime.
+ *
+ * When initializing this factory, you map a given document type to the appropriate loading class, which implements the interface given by LabeledSetCreatorInterface.
+ * For example, using the document type "DaimlerStereoPedRecXml" from above, by calling ::addCreator() this string is mapped to the xml load LabeledSetCreatorDaimlerXml,
+ * which exactly knows how to handle the internal xml structure and create a LabeledSet out of it.
+ *
+ * <h2>Example configuration</h2>
+ * contents of main_prog.config:
+ *  \verbatim
+ ...
+ [train]
+ dataset = <path to train folder containing config for training (train.config)>
+ ...
+ \endverbatim
+ *
+ * contents of training folder:<br>
+ * \verbatim
+ train.config
+ train_files.xml
+ ...
+ \endverbatim
+ *
+ * contents of train.config:
+ * \verbatim
+[main]
+factoryxml = train_files.xml  -> specifying that the factory is used for loading a xml file containing further information
+ ...
+ \endverbatim
+ * contents of train_files.xml:
+ * \verbatim
+ < !DOCTYPE DaimlerStereoPedRecXml >   -> Doctype tells the factory which implementation of the LabeledSetCreatorInterface interface should be used for handling this particulary xml file
+ < itemlist >
+ < item filename="07m_04s_237599u.pgm" objectid="17028"/>
+ < item filename="15m_39s_595649u.pgm" objectid="39616"/>
+   ....
+ < / itemlist >
+ \endverbatim
+
+ * To handle this example train_files.xml, suppose a class LabeledSetCreatorDaimlerXml was implemented (implementing interface LabeledSetCreatorInterface) .
+ * You have to add this class to the factory in advance of using the factory:
+ * \code
+ * NICE::Config confSimple ( "main_prog.config" );
+ *
+ * LabeledSetCreatorDaimlerXml *daimlerXml = new LabeledSetCreatorDaimlerXml();
+ * LabeledSetFactory *factory = new LabeledSetFactory();
+ * factory->addCreator("DaimlerStereoPedRecXml", daimlerXml); //the daimlerXml tells the factory that it is associated with the doctype "DaimlerStereoPedRecXml"
+ *
+ * MultiDataset  md( &confSimple, factory);
+ *
+ * const LabeledSet *pTrainFiles = md["train"];
+ * ...
+ *  \endcode
+ *
+ * \date 2012/05/18
+ * \author Johannes Ruehle
+ */
+class LabeledSetFactory
+{
+public:
+    LabeledSetFactory();
+
+
+    /**
+    * @brief Fill a LabeledSet with data loaded from a xml file using the right loading object specified by the xml document type.
+    *
+    * Reads the document type of a xml file containing training / test data and calls the appropriate xml extraction class accordingly.
+    * As a result, the xml loaded extract label information and stores them into a LabeledSet
+    *
+    * Note: An appropriate class derived from LabeledSetCreatorInterface had to be added in advance, by LabeledSetFactory::addCreator().
+    *
+    * @param sXmlFilename name of the config file (xml) containing a specific structure stated by the document type
+    *                      according to which the appropriate LabeledSetCreatorInferface implementation is called for xml loading
+    * @param p_conf Global config structure
+    * @param p_classnames Structure containing all classnames of the ground truth
+    * @param p_LabelSet labeled set of data to be created. All loaded data is appended to this structure.
+    */
+    void createLabeledSetFromXml(std::string sXmlFilename,
+                                        const NICE::Config & p_conf,
+                                        const ClassNames & p_classnames,
+                                        LabeledSet &p_LabelSet);
+
+    /**
+     * @brief Create mapping from a xml document type to the appropriate loading function for a xml file.
+     *
+     * @param sCreatorName xml document type stating a specific xml format and its contents
+     * @param pCreator object reference that knows how to load / parse the specific xml file and create a LabeledData set of it.
+     */
+    void addCreator(std::string sCreatorName, LabeledSetCreatorInterface *pCreator);
+
+protected:
+    /// Mapping from xml document type to loader implementation.
+    std::map<std::string, LabeledSetCreatorInterface*> m_MapLSCreators;
+
+};
+
+} //namespace
+
+#endif // LABELEDSETFACTORY_H

+ 59 - 1
cbaselib/LocalizationResult.cpp

@@ -14,6 +14,7 @@
 #include <core/image/LineT.h>
 
 #include "vislearning/cbaselib/LocalizationResult.h"
+#include "ImageInfo.h"
 #include "core/basics/StringTools.h"
 
 // use this macro to show labeled images
@@ -33,12 +34,14 @@ using namespace NICE;
 SingleLocalizationResult::SingleLocalizationResult ( ClassificationResult *_r, const NICE::Region & _reg, int _controlPoints ) 
     : controlPoints(_controlPoints), hasRegionInformation_bool(true), reg(_reg), r(_r)
 {
+    objectid = -1;
     reg.getRect(xi,yi,xa,ya);
 }
 
 SingleLocalizationResult::SingleLocalizationResult ( ClassificationResult *_r, int _xi, int _yi, int _xa, int _ya ) 
     : controlPoints(4), xi(_xi), yi(_yi), xa(_xa), ya(_ya), hasRegionInformation_bool(true), r(_r)
 {
+    objectid = -1;
 //    reg.add (xi,yi,xa,ya);
 //    this might lead to problems...in general the current Region representation is awful !
 }
@@ -354,11 +357,66 @@ void LocalizationResult::restore (istream & is, int format)
 		}
 
 		//sortEmpricalDepth();
-    } else {
+    }
+    else {
 		fthrow(IOException, "LocalizationResult::restore: file format not yet supported !");
     }
 }
 
+void LocalizationResult::loadImageInfo(std::string sFilename, int selectObjectWithUniqueId)
+{
+    ImageInfo info;
+    info.loadImageInfo(sFilename);
+
+    this->loadImageInfo(info, selectObjectWithUniqueId);
+}
+
+void LocalizationResult::loadImageInfo(ImageInfo &p_ImageInfo, int selectObjectWithUniqueId)
+{
+
+    try
+    {
+
+        const std::list< OBJREC::BoundingBox > *listBBoxes = p_ImageInfo.bboxes();
+
+        const double score = 1.0;
+        OBJREC::BoundingBox box;
+        std::list< OBJREC::BoundingBox >::const_iterator itBBoxes = listBBoxes->begin();
+        for(;itBBoxes != listBBoxes->end(); itBBoxes++)
+        {
+            box = *itBBoxes;
+            int id = box.id();
+
+            if( selectObjectWithUniqueId != -1 && selectObjectWithUniqueId != box.unique_id_ )
+                //only extract bounding boxes with a specific unique id. for why, see @
+                continue;
+
+            std::stringstream ss;
+            ss << id;
+
+            std::string classname = ss.str();
+            int classno = cn->classno(classname);
+            if(classno == -1)
+            {
+                fprintf (stderr, "LocalizationResult::loadImageInfo: no classno found for classname %s (using classno=-1)\n", classname.c_str());
+            }
+            ClassificationResult *r = new ClassificationResult ( classno, score, cn->getMaxClassno() );
+            r->classname = cn->text( classno );
+            SingleLocalizationResult *sr = new SingleLocalizationResult ( r, box.topLeft().x,
+                                                                             box.topLeft().y,
+                                                                             box.width(),
+                                                                             box.height() );
+            sr->objectid = box.unique_id_;
+            this->push_back ( sr );
+        }
+
+    }
+    catch(Exception e)
+    {
+        fthrow( Exception, "LocalizationResult::loadImageInfo: error loading image info (ImageLabeler xml format)");
+    }
+}
+
 void LocalizationResult::store (ostream & os, int format) const
 {
     if ( format == FILEFORMAT_PASCAL2006_RESULT ) 

+ 47 - 2
cbaselib/LocalizationResult.h

@@ -27,6 +27,8 @@
 
 namespace OBJREC {
 
+class ImageInfo;
+
 class SingleLocalizationResult 
 {
     private:
@@ -43,11 +45,32 @@ class SingleLocalizationResult
     
 	ClassificationResult *r;
 
+    /** Unique object identifier.
+     * (set when loading bounding box information from a ImageInfo file.
+     * @see ImageInfo::loadImageInfo()
+     */
+    int objectid;
+
 
 	SingleLocalizationResult ( ClassificationResult *r, const NICE::Region & reg, int controlPoints = 0 );
-	SingleLocalizationResult ( ClassificationResult *r, int xi, int yi, int xa, int ya );
+
+    /**
+     * @brief constructor
+     * @param xi (left)
+     * @param yi (top)
+     * @param xa (width)
+     * @param ya (height)
+     */
+    SingleLocalizationResult ( ClassificationResult *r, int xi, int yi, int xa, int ya );
 	~SingleLocalizationResult ();
 
+    /**
+     * @brief get the bounding box
+     * @param xi (left)
+     * @param yi (top)
+     * @param xa (width)
+     * @param ya (height)
+     */
 	void getBoundingBox ( int & xi, int & yi, int & xa, int & ya ) const;
 	void getBoundingBox ( NICE::RectT<int> & rectangle ) const;
 
@@ -83,7 +106,7 @@ class LocalizationResult : public std::vector<SingleLocalizationResult *>, publi
     enum {
 		FILEFORMAT_PASCAL2006_RESULT = 0,
 		FILEFORMAT_PASCAL2006_GROUNDTRUTH,
-		FILEFORMAT_POLYGON
+        FILEFORMAT_POLYGON
     };
 
     LocalizationResult ( int xsize = -1, int ysize = -1 );
@@ -105,6 +128,28 @@ class LocalizationResult : public std::vector<SingleLocalizationResult *>, publi
 			bool invert = false,
 			int width = 1) const;
 
+    /**
+     * @brief Loads image label information from the file format supported by the ImageLabeler tool.
+     *
+     * This function ignores the label description (xml section < legend > ) and assumes, that the label names were loaded in advance
+     * and are present in the ClassNames reference member variable LocalizationResult::cn.
+     *
+     * Note: Uses class ImageInfo for loading the xml information and inserts them into this LocalizationResult class.
+     * A future TODO would be to directly include the ImageInfo loading code here (or as part of LocalizationResult) to substitute redundancy
+     * between the classes ImageInfo and LocalizationResult (meaning both use BoundingBoxes etc).
+     *
+     * Currently only rectangular bounding box information are transferred from the loaded ImageInfo instance to this class.
+     * So, trying to use for instance Polygon data created with the ImageLabeler will fail (empty LocalizationResult).
+     *
+     * @param sFilename file name of the image label file (usually *.dat, xml formatted)
+     * @param selectObjectWithUniqueId unique object id for specifying a bounding box that is to be extracted from the label file(default -1, deactivated)
+     * @see OBJREC::ImageInfo
+     * @author Johannes Rühle
+     * @date 2012-05-11
+     */
+    void loadImageInfo(std::string sFilename, int selectObjectWithUniqueId = -1);
+    void loadImageInfo(ImageInfo &p_ImageInfo, int selectObjectWithUniqueId = -1);
+
     void restore (std::istream & is, int format = 0);
     void store (std::ostream & os, int format = 0) const;
     void clear ();

+ 17 - 7
cbaselib/MultiDataset.cpp

@@ -133,11 +133,13 @@ void MultiDataset::selectExamples ( const std::string & examples_command,
 }
 
 /** MultiDataset ------- constructor */
-MultiDataset::MultiDataset( const Config *conf )
+MultiDataset::MultiDataset( const Config *conf , LabeledSetFactory *pSetFactory)
 {
   std::set<string> blocks;
   conf->getAllBlocks ( blocks );
 
+  lfl.setFactory( pSetFactory );
+
   map<string, Config> dsconfs;
   map<string, string> dirs;
   for ( set<string>::iterator i = blocks.begin();
@@ -173,6 +175,7 @@ MultiDataset::MultiDataset( const Config *conf )
     LabeledSet dummy (true);
     LabeledSet temp (true);
 
+
     bool localizationInfoDisabled = conf->gB("traintest", "disable_localization_info", false );
 
     std::string classselection_train = conf->gS("traintest", "classselection_train", "*");
@@ -182,13 +185,13 @@ MultiDataset::MultiDataset( const Config *conf )
     std::string classNamesTxt = dirs["traintest"] + "/classnames.txt";
     if ( FileMgt::fileExists ( classNamesTxt ) )
     {
-      classnames["traintest"].read ( classNamesTxt );
+        classnames["traintest"].read ( classNamesTxt );
     } else {
-      classnames["traintest"].readFromConfig ( dsconfs["traintest"], classselection_train );
+        classnames["traintest"].readFromConfig ( dsconfs["traintest"], classselection_train );
     }
 
     lfl.get ( dirs["traintest"], dsconfs["traintest"], classnames["traintest"], ls_base,
-              localizationInfoDisabled, conf->gB("traintest", "debug_dataset", false ) );
+        localizationInfoDisabled, conf->gB("traintest", "debug_dataset", false ) );
 
     std::string examples_train =  conf->gS("traintest", "examples_train" );
     selectExamples ( examples_train, ls_base, ls_train, ls_nontrain, classnames["traintest"] );
@@ -249,11 +252,18 @@ MultiDataset::MultiDataset( const Config *conf )
 #ifdef DEBUG_MultiDataset
       fprintf (stderr, "MultiDataset: reading class names from dataset config file\n" );
 #endif
-      classnames[name].readFromConfig ( dsconfs[name], classselection );
+        classnames[name].readFromConfig ( dsconfs[name], classselection );
     }
+		
+
+    lfl.get (   dirs[name],
+                dsconfs[name],
+                classnames[name],
+                ls_base,
+                localizationInfoDisabled,
+                conf->gB(name, "debug_dataset", false ) );
+
 
-    lfl.get ( dirs[name], dsconfs[name], classnames[name], ls_base,
-              localizationInfoDisabled, conf->gB(name, "debug_dataset", false ) );
 #ifdef DEBUG_MultiDataset
     fprintf (stderr, "MultiDataset: class names -->\n" );
     classnames[name].store ( cerr );

+ 14 - 8
cbaselib/MultiDataset.h

@@ -17,6 +17,7 @@
 
 #include "LabeledSetSelection.h"
 #include "LabeledFileList.h"
+#include "LabeledSetFactory.h"
 #include "LabeledSet.h"
 #include "ClassNames.h"
 
@@ -38,14 +39,19 @@ protected:
                           LabeledSet & negatives,
                           const ClassNames & cn ) const;
 
-public:
-
-    /** simple constructor */
-    MultiDataset( const NICE::Config *conf );
-
-    /** simple destructor */
-    virtual ~MultiDataset();
-
+    public:
+  
+    /** Create a new data set consiting of multiple datasets.
+     *
+     * @param pSetFactory factory for creating the right loading object (@see LabeledSetCreatorInterface) for a specified xml config file.
+     *                      The factory is used when the log tag "factoryxml = < file >.xml" is specified in section " [main] ".
+     *  @see LabeledFileList::get()
+     */
+    MultiDataset( const NICE::Config *conf, LabeledSetFactory *pSetFactory = NULL );
+      
+	/** simple destructor */
+	virtual ~MultiDataset();
+    
     /** access class information, e.g., md.getClassNames("train") */
     const ClassNames & getClassNames ( const std::string & key ) const;
 

+ 4 - 1
cbaselib/Polygon.cpp

@@ -15,7 +15,8 @@ using namespace NICE;
 Polygon::Polygon()
 {
 	points_.clear();
-	id_ = -1;
+    id_ = -1;
+    unique_id_ = -1;
 }
 
 // A copy-constructor
@@ -23,6 +24,7 @@ Polygon::Polygon(const Polygon &copy)
 {
 	points_ = PointsList(*(copy.points()));
 	id_ = copy.id();
+    unique_id_ = copy.unique_id_;
 }
 
 //! A desctructor
@@ -72,6 +74,7 @@ Polygon::setID(const int &anID)
 		return;
 		/* NOTREACHED */
 	}
+    this->id_ = anID;
 }
 
 //! returns a constant pointer to the list of polygon points(coordinates)

+ 6 - 0
cbaselib/Polygon.h

@@ -35,7 +35,13 @@ class Polygon
 
   private:
     PointsList points_;
+
+    /// id interpreted as a class label
     int id_;
+
+  public:
+    /// unique id that distinguishs this particular bounding box object from all others
+    int unique_id_;
 };
 
 } //namespace

+ 1 - 1
classifier/kernelclassifier/GPLaplaceOptimizationProblem.h

@@ -9,7 +9,7 @@
 
 #include "core/vector/VVector.h"
 #include "vislearning/math/kernels/ParameterizedKernel.h"
-#include "core/optimization/OptimizationProblemFirst.h"
+#include "core/optimization/gradientBased/OptimizationProblemFirst.h"
 
 #include "vislearning/math/kernels/KernelData.h"
 

+ 2 - 2
classifier/kernelclassifier/KCGPLaplace.cpp

@@ -15,8 +15,8 @@
 #include "LHCumulativeGauss.h"
 
 #include "vislearning/classifier/kernelclassifier/GPLaplaceOptimizationProblem.h"
-#include "core/optimization/FirstOrderTrustRegion.h"
-#include "core/optimization/FirstOrderRasmussen.h"
+#include "core/optimization/gradientBased/FirstOrderTrustRegion.h"
+#include "core/optimization/gradientBased/FirstOrderRasmussen.h"
 
 using namespace std;
 using namespace NICE;

+ 3 - 3
classifier/kernelclassifier/KCGPLaplaceOneVsAll.cpp

@@ -10,9 +10,9 @@
 
 #include "core/vector/Algorithms.h"
 
-#include "core/optimization/OptimizationAlgorithmFirst.h"
-#include "core/optimization/FirstOrderTrustRegion.h"
-#include "core/optimization/FirstOrderRasmussen.h"
+#include "core/optimization/gradientBased/OptimizationAlgorithmFirst.h"
+#include "core/optimization/gradientBased/FirstOrderTrustRegion.h"
+#include "core/optimization/gradientBased/FirstOrderRasmussen.h"
 
 #include "vislearning/classifier/kernelclassifier/GPLaplaceOptimizationProblem.h"
 #include "core/algebra/CholeskyRobust.h"

+ 3 - 3
classifier/kernelclassifier/KCGPRegOneVsAll.cpp

@@ -14,9 +14,9 @@
 
 #include "core/vector/Algorithms.h"
 
-#include "core/optimization/OptimizationAlgorithmFirst.h"
-#include "core/optimization/FirstOrderTrustRegion.h"
-#include "core/optimization/FirstOrderRasmussen.h"
+#include "core/optimization/gradientBased/OptimizationAlgorithmFirst.h"
+#include "core/optimization/gradientBased/FirstOrderTrustRegion.h"
+#include "core/optimization/gradientBased/FirstOrderRasmussen.h"
 
 #include "vislearning/regression/gpregression/GPRegressionOptimizationProblem.h"
 #include "core/algebra/CholeskyRobust.h"

+ 3 - 2
features/fpfeatures/FIGradients.cpp

@@ -72,8 +72,9 @@ void FIGradients::buildEOHMap ( CachedExample *ce,
   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 );
+    ImageT<double> tmpEohImg         = eohimg[i];
+    ImageT<double> tmpEohIntegralImg = eohintimg[i];
+    GenericImageTools::calcIntegralImage ( tmpEohIntegralImg, tmpEohImg, xsize_s, ysize_s );
   }
 
 }

+ 7 - 0
image/GenericImageTools.h

@@ -16,6 +16,13 @@ class GenericImageTools
 {
     public:
 
+    /**
+     * calculates the integral image.
+     *
+     * note: result integral image has same dimensions as the source image -
+     * the size is NOT extended by a new 0-row and 0-column as is done in cv::integral.
+     *
+     */
     template <class PixelValueDst, class PixelValueSrc>
     static void calcIntegralImage ( NICE::ImageT<PixelValueDst> &integralImage, const NICE::ImageT<PixelValueSrc> &image, int xsize, int ysize );
 

+ 4 - 4
image/GenericImageTools.tcc

@@ -14,11 +14,11 @@ void GenericImageTools::calcIntegralImage ( NICE::ImageT<PixelValueDst> &integra
 {
   integralImage ( 0, 0 ) = ( PixelValueDst ) image ( 0, 0 );;
 
-  for ( int y = 1 ; y < ysize; y++ )
-    integralImage ( 0, y ) += image ( 0, y - 1 );
+  for ( int y = 0 ; y < (ysize - 1); ++y )
+    integralImage ( 0, y + 1) = integralImage ( 0, y) + image ( 0, y);
 
-  for ( int x = 1 ; x < xsize; x++ )
-    integralImage ( x, 0 ) += image ( x - 1, 0 );
+  for ( int x = 0 ; x < (xsize - 1); ++x )
+    integralImage ( x + 1, 0 ) = integralImage ( x, 0 ) + image ( x, 0 );
 
   for ( int y = 1 ; y < ysize ; y++ )
     for ( int x = 1 ; x < xsize ; x++ )

+ 143 - 0
matlabAccessHighLevel/ImageNetData.cpp

@@ -0,0 +1,143 @@
+/** 
+* @file ImageNetData.cpp
+* @brief wrapper class for matlab IO with ImageNet data
+* @author Erik Rodner
+* @date 02/03/2012
+
+*/
+#include <iostream>
+#include <vector>
+
+#include <core/basics/Exception.h>
+#include <core/vector/VectorT.h>
+
+#include "ImageNetData.h"
+
+using namespace NICE;
+using namespace std;
+
+
+ImageNetData::ImageNetData( const string & imageNetRoot )
+{
+  this->imageNetRoot = imageNetRoot;
+}
+
+ImageNetData::~ImageNetData()
+{
+}
+
+void ImageNetData::getBatchData ( sparse_t & data, Vector & y, const string & fileTag, const string & variableTag )
+{
+  string filename = imageNetRoot + "/demo." + fileTag + ".mat";
+  string vn_data = variableTag + "_instance_matrix";
+  string vn_y = variableTag + "_label_vector";
+  MatFileIO matfileIO (filename,MAT_ACC_RDONLY);
+  matfileIO.getSparseVariableViaName(data,vn_data);
+  matfileIO.getVectorViaName(y,vn_y);
+}
+
+void ImageNetData::preloadData ( const string & fileTag, const string & variableTag )
+{
+  sparse_t m_XPreload;
+  getBatchData ( m_XPreload, yPreload, fileTag, variableTag ); 
+
+  XPreload.resize ( yPreload.size() );
+  cerr << "ImageNetData: converting data ... " << yPreload.size() << " examples" << endl;
+  for ( int i = 0; i < m_XPreload.njc-1; i++ ) //walk over dimensions
+	{
+		for ( int j = m_XPreload.jc[i]; j < m_XPreload.jc[i+1] && j < m_XPreload.ndata; j++ )
+    {
+      int exampleIndex = m_XPreload.ir[ j];
+      if ( exampleIndex < 0 || exampleIndex >= (int)XPreload.size() )
+        fthrow(Exception, "Label and data file seem to mismatch according the sizes: " << XPreload.size() << " vs. " << exampleIndex);
+      XPreload[exampleIndex].insert ( pair<int, double> ( i, ((double *)m_XPreload.data)[j] ) );
+    }
+  }
+  cerr << "ImageNetData: data conversion finished." << endl;
+}
+
+void ImageNetData::loadDataAsLabeledSetVector( OBJREC::LabeledSetVector & lsVector, const std::string & fileTag, const std::string & variableTag )
+{
+  sparse_t m_XPreload;
+  
+  //load raw data
+  getBatchData ( m_XPreload, yPreload, fileTag, variableTag ); 
+  
+  //tmp storage 
+  std::vector<NICE::Vector> dataTmp;
+  dataTmp.resize(yPreload.size());
+  
+  
+  //initialize every entries with zero
+  NICE::Vector vZero (yPreload.size(), 0.0);
+  for (uint i = 0; i < yPreload.size(); i++)
+  {
+    dataTmp[i] = vZero;
+  }
+ 
+  //set non-zero entries according to the stored values
+  std::cerr << "ImageNetData: converting data ... " << yPreload.size() << " examples" << std::endl;
+  for ( int i = 0; i < m_XPreload.njc-1; i++ ) //walk over dimensions
+  {
+    for ( int j = m_XPreload.jc[i]; j < m_XPreload.jc[i+1] && j < m_XPreload.ndata; j++ ) //and over every non-zero entry in this dimension
+    {
+      //what is the original index?
+      int exampleIndex = m_XPreload.ir[ j];
+      if ( exampleIndex < 0 || exampleIndex >= (int)yPreload.size() )
+        fthrow(Exception, "Label and data file seem to mismatch according the sizes: " << yPreload.size() << " vs. " << exampleIndex);      
+      
+      //insert at the original index and the corresponding dimension
+      dataTmp[exampleIndex][i] =  ((double *)m_XPreload.data)[j];
+    }
+  }
+
+  std::cerr << "ImageNetData: data conversion finished." << std::endl;
+  
+  lsVector.clear();
+  for (uint i = 0; i < yPreload.size(); i++)
+  {
+        lsVector.add( yPreload[i], dataTmp[i] );
+  }
+}
+
+const SparseVector & ImageNetData::getPreloadedExample ( int index ) const
+{
+  if ( index >= (int)XPreload.size() || index < 0 )
+    fthrow(Exception, "Invalid index!");
+  return XPreload[index];
+}
+
+double ImageNetData::getPreloadedLabel ( int index ) const
+{
+  if ( index < 0 || index >= (int)yPreload.size() )
+    fthrow(Exception, "Invalid index!");
+  return yPreload[index];
+}
+
+int ImageNetData::getNumPreloadedExamples () const
+{
+  return yPreload.size();
+}
+
+void ImageNetData::loadExternalLabels ( const string & fn, int n )
+{
+  if ( n <= 0  && yPreload.size() == 0 ) {
+    fthrow(Exception, "Please initialize with preloadData() first, or use the second optional argument to give the number of examples.");
+  }
+  if ( n >= 0 )
+    yPreload.resize( n );
+
+  ifstream ifs ( fn.c_str(), ios::in );
+  if ( ! ifs.good() )
+    fthrow(Exception, "Unable to read " << fn );
+
+  int value;
+  int i = 0;
+  while ( (i < yPreload.size()) && (ifs >> value) ) 
+    yPreload[i++] = value;
+
+  ifs.close();
+
+  if ( (XPreload.size() > 0) && (yPreload.size() != XPreload.size()) )
+    fthrow(Exception, "Size of the label vector and the size of the data structure do not match.");
+}

+ 110 - 0
matlabAccessHighLevel/ImageNetData.h

@@ -0,0 +1,110 @@
+/** 
+* @file ImageNetData.h
+* @author Erik Rodner
+* @date 02/03/2012
+
+*/
+#ifndef _NICE_IMAGENETDATAINCLUDE
+#define _NICE_IMAGENETDATAINCLUDE
+
+#include <string>
+
+#include <core/vector/VectorT.h>
+#include <core/vector/SparseVector.h>
+#include <core/matlabAccess/MatFileIO.h>
+
+#include "vislearning/cbaselib/LabeledSet.h"
+
+
+namespace NICE {
+  
+/** @class ImageNetData
+ * wrapper class for matlab IO with ImageNet data 
+ *
+ * @author Erik Rodner
+ */
+class ImageNetData
+{
+
+  protected:
+    std::string imageNetRoot;
+
+    std::vector< SparseVector > XPreload;
+    Vector yPreload;
+
+  public:
+
+    /** simple constructor */
+    ImageNetData( const std::string & imageNetRoot = "/home/dbv/bilder/imagenet/devkit-1.0/demo/" );
+      
+    /** simple destructor */
+    virtual ~ImageNetData();
+
+    /**
+    * @brief get a bulk of (training) data with labels
+    *
+    * @param data feature vectors
+    * @param y label vector
+    * @param fileTag demo.<tag>.mat will be accessed
+    * @param variableTag variables are named <tag>_instance_matrix and <tag>_label_vector
+    */
+    void getBatchData ( sparse_t & data, Vector & y, const std::string & fileTag = "train", const std::string & variableTag = "training" );
+
+
+    /**
+    * @brief load the data specified for later access using the get functions
+    *
+    * @param fileTag
+    * @param variableTag
+    */
+    void preloadData ( const std::string & fileTag = "val", const std::string & variableTag = "testing" );
+    
+    /**
+    * @brief load the data specified for later access using the get functions, give everything as a LabeledSetVector object which is usefull for objects of type KernelClassifier (as used in vislearning)
+    *
+    * @date 23-05-2012 (dd-mm-yyyy)
+    * @param fileTag
+    * @param variableTag
+    * @param lsVector
+    */    
+    void loadDataAsLabeledSetVector( OBJREC::LabeledSetVector & lsVector, const std::string & fileTag = "train", const std::string & variableTag = "training" );
+
+    /**
+    * @brief get a specific feature vector
+    *
+    * @param index index of the example
+    * @return constant reference to the SparseVector
+    */
+    const SparseVector & getPreloadedExample ( int index ) const;
+
+    /**
+    * @brief get the label of a specific example
+    *
+    * @param index index of the example
+    *
+    * @return label of the example (can be continous)
+    */
+    double getPreloadedLabel ( int index ) const;
+
+    /**
+    * @brief get number of examples
+    */
+    int getNumPreloadedExamples () const;
+
+  
+    /**
+    * @brief load external labels
+    *
+    * @param fn file name of the external labels
+    * @param n number of examples, if this parameter is set to -1 we assume that 
+    * the data is already loaded
+    */
+    void loadExternalLabels ( const std::string & fn, int n = -1 );
+    
+    std::vector< SparseVector > getPreloadedData() { return XPreload;};
+    NICE::Vector getPreloadedLabels()const {return yPreload;};    
+};
+
+}
+
+#endif

+ 8 - 0
matlabAccessHighLevel/Makefile

@@ -0,0 +1,8 @@
+#TARGETS_FROM:=$(notdir $(patsubst %/,%,$(shell pwd)))/$(TARGETS_FROM)
+#$(info recursivly going up: $(TARGETS_FROM) ($(shell pwd)))
+
+all:
+
+%:
+	$(MAKE) TARGETS_FROM=$(notdir $(patsubst %/,%,$(shell pwd)))/$(TARGETS_FROM) -C .. $@
+

+ 103 - 0
matlabAccessHighLevel/Makefile.inc

@@ -0,0 +1,103 @@
+# LIBRARY-DIRECTORY-MAKEFILE
+# conventions:
+# - all subdirectories containing a "Makefile.inc" are considered sublibraries
+#   exception: "progs/" and "tests/" subdirectories!
+# - all ".C", ".cpp" and ".c" files in the current directory are linked to a
+#   library
+# - the library depends on all sublibraries 
+# - the library name is created with $(LIBNAME), i.e. it will be somehow
+#   related to the directory name and with the extension .a
+#   (e.g. lib1/sublib -> lib1_sublib.a)
+# - the library will be added to the default build list ALL_LIBRARIES
+
+# --------------------------------
+# - 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)
+ifeq "$(SUBDIR)" "./"
+SUBDIR:=
+endif
+
+# ------------------------
+# - 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
+#
+# you can specify libraries needed by the individual objects or by the whole
+# directory. the object specific additional libraries are only considered
+# when compiling the specific object files
+# TODO: update documentation...
+
+-include $(SUBDIR)libdepend.inc
+
+$(foreach d,$(filter-out %progs %tests,$(SUBDIRS_OF_$(SUBDIR))),$(eval $(call PKG_DEPEND_INT,$(d))))
+
+# ---------------------------
+# - 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.
+
+LIBRARY_BASENAME:=$(call LIBNAME,$(SUBDIR))
+ifneq "$(SUBDIR)" ""
+ALL_LIBRARIES+=$(LIBDIR)$(LIBRARY_BASENAME).$(LINK_FILE_EXTENSION)
+endif
+
+# ---------------------
+# - binary dependencies
+#
+# there is no way of determining the binary dependencies automatically, so we
+# follow conventions. the current library depends on all sublibraries.
+# all other dependencies have to be added manually by specifying, that the
+# current .pc file depends on some other .pc file. binaries depending on
+# libraries should exclusivelly use the .pc files as well.
+
+ifeq "$(SKIP_BUILD_$(OBJDIR))" "1"
+$(LIBDIR)$(LIBRARY_BASENAME).a:
+else
+$(LIBDIR)$(LIBRARY_BASENAME).a:$(OBJS) \
+	$(call PRINT_INTLIB_DEPS,$(PKGDIR)$(LIBRARY_BASENAME).a,.$(LINK_FILE_EXTENSION))
+endif
+
+$(PKGDIR)$(LIBRARY_BASENAME).pc: \
+	$(call PRINT_INTLIB_DEPS,$(PKGDIR)$(LIBRARY_BASENAME).pc,.pc)
+
+# -------------------
+# - 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))
+

+ 4 - 0
matlabAccessHighLevel/libdepend.inc

@@ -0,0 +1,4 @@
+$(call PKG_DEPEND_INT,core/vector/)
+$(call PKG_DEPEND_INT,core/basics/)
+$(call PKG_DEPEND_INT,core/matlabAccess/)
+$(call PKG_DEPEND_INT,vislearning/cbaselib/)

+ 88 - 0
matlabAccessHighLevel/progs/Makefile.inc

@@ -0,0 +1,88 @@
+# 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))
+

+ 1 - 1
progs/libdepend.inc

@@ -4,6 +4,6 @@ $(call PKG_DEPEND_INT,vislearning/math)
 $(call PKG_DEPEND_INT,vislearning/baselib)
 $(call PKG_DEPEND_INT,vislearning/cbaselib)
 $(call PKG_DEPEND_INT,vislearning/classifier/kernelclassifier)
-$(call PKG_DEPEND_INT,fast-hik)
+$(call PKG_DEPEND_INT,vislearning/matlabAccess)
 
 

+ 4 - 4
progs/testImageNetBinary.cpp

@@ -10,19 +10,19 @@
 #include "vislearning/cbaselib/ClassificationResults.h"
 #include "vislearning/baselib/ProgressBar.h"
 
-#include "fast-hik/tools.h"
-#include "fast-hik/MatFileIO.h"
-#include "fast-hik/ImageNetData.h"
+#include "core/matlabAccess/MatFileIO.h"
+#include "vislearning/matlabAccessHighLevel/ImageNetData.h"
 
 #include "vislearning/classifier/kernelclassifier/KCGPOneClass.h"
 #include "vislearning/classifier/kernelclassifier/KCGPApproxOneClass.h"
 
-
 #include "vislearning/math/kernels/KernelData.h"
 #include "vislearning/math/kernels/Kernel.h"
 #include "vislearning/math/kernels/KernelRBF.h"
 #include "vislearning/math/kernels/KernelExp.h"
 
+// #include "fast-hik/tools.h"
+
 
 using namespace std;
 using namespace NICE;

+ 2 - 3
progs/testImageNetBinaryBruteForce.cpp

@@ -20,9 +20,8 @@
 #include "vislearning/baselib/ProgressBar.h"
 #include "vislearning/classifier/kernelclassifier/KCMinimumEnclosingBall.h"
 
-#include "fast-hik/tools.h"
-#include "fast-hik/MatFileIO.h"
-#include "fast-hik/ImageNetData.h"
+#include "core/matlabAccess/MatFileIO.h"
+#include "vislearning/matlabAccessHighLevel/ImageNetData.h"
 
 using namespace std;
 using namespace NICE;

+ 4 - 3
progs/testImageNetBinaryGPBaseline.cpp

@@ -14,9 +14,10 @@
 #include "vislearning/cbaselib/ClassificationResults.h"
 #include "vislearning/baselib/ProgressBar.h"
 
-#include "fast-hik/tools.h"
-#include "fast-hik/MatFileIO.h"
-#include "fast-hik/ImageNetData.h"
+#include "core/matlabAccess/MatFileIO.h"
+#include "vislearning/matlabAccessHighLevel/ImageNetData.h"
+
+// #include "fast-hik/tools.h"
 
 using namespace std;
 using namespace NICE;

+ 1 - 1
regression/gpregression/GPRegressionOptimizationProblem.h

@@ -9,7 +9,7 @@
 
 #include "core/vector/VVector.h"
 #include "vislearning/math/kernels/ParameterizedKernel.h"
-#include "core/optimization/OptimizationProblemFirst.h"
+#include "core/optimization/gradientBased/OptimizationProblemFirst.h"
 
 #include "vislearning/math/kernels/KernelData.h"
 

+ 3 - 3
regression/gpregression/RegGaussianProcess.cpp

@@ -8,9 +8,9 @@
 #include <iostream>
 #include <sstream>
 
-#include "core/optimization/OptimizationAlgorithmFirst.h"
-#include "core/optimization/FirstOrderTrustRegion.h"
-#include "core/optimization/FirstOrderRasmussen.h"
+#include "core/optimization/gradientBased/OptimizationAlgorithmFirst.h"
+#include "core/optimization/gradientBased/FirstOrderTrustRegion.h"
+#include "core/optimization/gradientBased/FirstOrderRasmussen.h"
 
 #include "core/vector/Algorithms.h"
 #include "core/algebra/CholeskyRobust.h"

+ 1 - 1
regression/gpregression/modelselcrit/GPMSCLooEstimates.cpp

@@ -11,7 +11,7 @@
 #include "vislearning/cbaselib/ClassificationResults.h"
 #include "vislearning/classifier/kernelclassifier/LikelihoodFunction.h"
 #include "core/algebra/CholeskyRobustAuto.h"
-#include "core/optimization/FirstOrderTrustRegion.h"
+#include "core/optimization/gradientBased/FirstOrderTrustRegion.h"
 
 #include "core/vector/Algorithms.h"
 

+ 1 - 1
regression/gpregression/modelselcrit/GPMSCLooEstimates.h

@@ -11,7 +11,7 @@
 #include "vislearning/math/kernels/KernelData.h"
 #include "vislearning/regression/gpregression/modelselcrit/GPModelSelectionCriterion.h"
 
-#include "core/optimization/OptimizationProblemFirst.h"
+#include "core/optimization/gradientBased/OptimizationProblemFirst.h"
 
 namespace OBJREC {