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

extended Example and CachedExample for the use of 3d images

Sven Sickert 9 жил өмнө
parent
commit
6d489c68da

+ 357 - 198
cbaselib/CachedExample.cpp

@@ -1,13 +1,13 @@
 /**
 * @file CachedExample.cpp
 * @brief data caching
-* @author Erik Rodner
-* @date 04/21/2008
+* @author Erik Rodner, Sven Sickert
+* @date 04/21/2008 (modified 03/18/2016)
 
 */
 #include <iostream>
 
-#include "vislearning/cbaselib/CachedExample.h"
+#include "CachedExample.h"
 #include "vislearning/baselib/Conversions.h"
 #include "vislearning/baselib/ProgressBar.h"
 
@@ -17,275 +17,434 @@
 
 using namespace OBJREC;
 
-using namespace std;
-using namespace NICE;
-
-
 void CachedExample::init ()
 {
-  dchannels = new MultiChannelImageT<double> [D_NUMCHANNELS];
-  ichannels = new MultiChannelImageT<int> [I_NUMCHANNELS];
-  lchannels = new MultiChannelImageT<long> [L_NUMCHANNELS];
-
-  svmap = new SparseVector *[SVNUMCHANNELS];
-  svmap_xsize = new int [SVNUMCHANNELS];
-  svmap_ysize = new int [SVNUMCHANNELS];
-  for ( uint k = 0 ; k < SVNUMCHANNELS ; k++ )
-  {
-    svmap[k] = NULL;
-    svmap_xsize[k] = 0;
-    svmap_ysize[k] = 0;
-  }
+    dchannels = new NICE::MultiChannelImageT<double> [D_NUMCHANNELS];
+    ichannels = new NICE::MultiChannelImageT<int> [I_NUMCHANNELS];
+    lchannels = new NICE::MultiChannelImageT<long> [L_NUMCHANNELS];
+
+    dchannels3 = new NICE::MultiChannelImage3DT<double> [D_NUMCHANNELS];
+    ichannels3 = new NICE::MultiChannelImage3DT<int> [I_NUMCHANNELS];
+    lchannels3 = new NICE::MultiChannelImage3DT<long> [L_NUMCHANNELS];
+
+    svmap = new NICE::SparseVector *[SVNUMCHANNELS];
+    svmap_xsize = new int [SVNUMCHANNELS];
+    svmap_ysize = new int [SVNUMCHANNELS];
+    for ( uint k = 0 ; k < SVNUMCHANNELS ; k++ )
+    {
+        svmap[k] = NULL;
+        svmap_xsize[k] = 0;
+        svmap_ysize[k] = 0;
+    }
 }
 
 CachedExample::CachedExample ( const std::string & _imgfn,
                                int _newWidth,
                                int _newHeight )
 {
-  imgfn = _imgfn;
-  newWidth = _newWidth;
-  newHeight = _newHeight;
-  Preprocess::getImageSize ( _imgfn, oxsize, oysize );
-  init();
-  hasColorInformation = true;
+    imgfn.push_back(_imgfn);
+    newWidth = _newWidth;
+    newHeight = _newHeight;
+    newDepth = 1;
+    Preprocess::getImageSize ( _imgfn, oxsize, oysize );
+    ozsize = 1;
+    init();
+    hasColorInformation = true;
+}
+
+CachedExample::CachedExample (
+        const std::vector<std::string> & _imgfn,
+        int _newWidth,
+        int _newHeight,
+        int _newDepth )
+{
+    imgfn = _imgfn;
+    newWidth = _newWidth;
+    newHeight = _newHeight;
+    newDepth = _newDepth;
+    Preprocess::getImageSize ( _imgfn[0], oxsize, oysize );
+    ozsize = _imgfn.size();
+    init();
+    hasColorInformation = true;
 }
 
 CachedExample::CachedExample ( const NICE::Image & _img )
 {
-  imgfn = "";
-  newWidth = -1;
-  newHeight = -1;
-  init();
-
-  oxsize = _img.width();
-  oysize = _img.height();
-  
-  ichannels[I_GRAYVALUES].freeData();
-  ichannels[I_GRAYVALUES].addChannel(_img);
-  hasColorInformation = false;
+    imgfn.push_back("");
+    newWidth = -1;
+    newHeight = -1;
+    newDepth = -1;
+    init();
+
+    oxsize = _img.width();
+    oysize = _img.height();
+    ozsize = 1;
+
+    ichannels[I_GRAYVALUES].freeData();
+    ichannels[I_GRAYVALUES].addChannel(_img);
+    hasColorInformation = false;
+}
+
+CachedExample::CachedExample (
+        const NICE::MultiChannelImageT<int> & _img )
+{
+    newWidth = -1;
+    newHeight = -1;
+    newDepth = -1;
+    init();
+
+    oxsize = _img.width();
+    oysize = _img.height();
+    ozsize = _img.channels();
+
+    for ( unsigned int i = 0; i < ozsize; i++ )
+        imgfn.push_back("");
+
+    ichannels3[I_GRAYVALUES].freeData();
+    ichannels3[I_GRAYVALUES].addChannel(_img);
+    hasColorInformation = false;
 }
 
 CachedExample::CachedExample ( const NICE::ColorImage & img, bool disableGrayConversion )
 {
-  imgfn = "";
-  oxsize = img.width();
-  oysize = img.height();
-  newWidth = -1;
-  newHeight = -1;
-  init();
-
-  if ( ! disableGrayConversion )
-  {
-    // refactor-nice.pl: check this substitution
-    // old: Image imggray;
-    NICE::Image imggray;
-    ICETools::calcGrayImage ( img, imggray );
+    imgfn.push_back("");
+    oxsize = img.width();
+    oysize = img.height();
+    ozsize = 1;
+    newWidth = -1;
+    newHeight = -1;
+    newDepth = -1;
+    init();
+
+    if ( ! disableGrayConversion )
+    {
+        // refactor-nice.pl: check this substitution
+        // old: Image imggray;
+        NICE::Image imggray;
+        ICETools::calcGrayImage ( img, imggray );
 
-    ichannels[I_GRAYVALUES].freeData();
-    ichannels[I_GRAYVALUES].addChannel(imggray);
-  }
+        ichannels[I_GRAYVALUES].freeData();
+        ichannels[I_GRAYVALUES].addChannel(imggray);
+    }
+
+    ichannels[I_COLOR].reInit ( oxsize, oysize, 3);
+
+    for ( int y = 0 ; y < oysize ; y++ )
+        for ( int x = 0 ; x < oxsize ; x++ )
+        {
+            ichannels[I_COLOR](x,y,0) = img.getPixel ( x, y, 0 );
+            ichannels[I_COLOR](x,y,1) = img.getPixel ( x, y, 1 );
+            ichannels[I_COLOR](x,y,2) = img.getPixel ( x, y, 2 );
+        }
+
+    hasColorInformation = true;
+}
 
-  ichannels[I_COLOR].reInit ( oxsize, oysize, 3);
+CachedExample::CachedExample (
+        const NICE::MultiChannelImage3DT<int> & img,
+        bool disableGrayConversion )
+{
+    oxsize = img.width();
+    oysize = img.height();
+    ozsize = img.depth();
+    newWidth = -1;
+    newHeight = -1;
+    newDepth = -1;
+    for ( unsigned int i = 0; i < ozsize; i++ )
+        imgfn.push_back("");
+
+    init();
 
-  for ( int y = 0 ; y < oysize ; y++ )
-    for ( int x = 0 ; x < oxsize ; x++ )
+    int ochannels = img.channels();
+
+    if ( ! disableGrayConversion && (ochannels > 2) )
     {
-      ichannels[I_COLOR](x,y,0) = img.getPixel ( x, y, 0 );
-      ichannels[I_COLOR](x,y,1) = img.getPixel ( x, y, 1 );
-      ichannels[I_COLOR](x,y,2) = img.getPixel ( x, y, 2 );
+        ichannels3[I_GRAYVALUES].freeData();
+        ichannels3[I_GRAYVALUES].addChannel(1);
+        for ( int z = 0; z < ozsize; z++ )
+        {
+            NICE::Image imggray;
+            ICETools::calcGrayImage ( img.getColor(z), imggray );
+
+            for ( int y = 0; y < oysize; y++ )
+                for ( int x = 0; x < oxsize; x++ )
+                    ichannels3[I_GRAYVALUES](x,y,z,0) = imggray.getPixel(x,y);
+        }
     }
 
-  hasColorInformation = true;
+    ichannels3[I_COLOR].addChannel ( img );
+
+    hasColorInformation = true;
 }
 
 CachedExample::~CachedExample()
 {
-  delete [] dchannels;
-  delete [] ichannels;
-  delete [] lchannels;
-
-  for ( uint k = 0 ; k < SVNUMCHANNELS ; k++ )
-    if ( svmap[k] != NULL )
-      delete [] ( svmap[k] );
-
-  delete [] svmap;
-  delete [] svmap_xsize;
-  delete [] svmap_ysize;
-
-  // remove all temporary files
-  for ( map<int, string>::const_iterator j = dtemps.begin();
-        j != dtemps.end();
-        j++ )
-  {
-    //fprintf (stderr, "CachedExample: removing temp file %s\n", j->second.c_str() );
-    FileMgt::deleteTempFile ( j->second );
-  }
-
-  for ( map<int, string>::const_iterator j = itemps.begin();
-        j != itemps.end();
-        j++ )
-  {
-    //fprintf (stderr, "CachedExample: removing temp file %s\n", j->second.c_str() );
-    FileMgt::deleteTempFile ( j->second );
-  }
-
-  for ( map<int, string>::const_iterator j = ltemps.begin();
-        j != ltemps.end();
-        j++ )
-  {
-    //fprintf (stderr, "CachedExample: removing temp file %s\n", j->second.c_str() );
-    FileMgt::deleteTempFile ( j->second );
-  }
+    delete [] dchannels;
+    delete [] ichannels;
+    delete [] lchannels;
+
+    delete [] dchannels3;
+    delete [] ichannels3;
+    delete [] lchannels3;
+
+    for ( uint k = 0 ; k < SVNUMCHANNELS ; k++ )
+        if ( svmap[k] != NULL )
+            delete [] ( svmap[k] );
+
+    delete [] svmap;
+    delete [] svmap_xsize;
+    delete [] svmap_ysize;
+
+    // remove all temporary files
+    for ( std::map<int, std::string>::const_iterator j = dtemps.begin();
+          j != dtemps.end();
+          j++ )
+    {
+        //fprintf (stderr, "CachedExample: removing temp file %s\n", j->second.c_str() );
+        NICE::FileMgt::deleteTempFile ( j->second );
+    }
+
+    for ( std::map<int, std::string>::const_iterator j = itemps.begin();
+          j != itemps.end();
+          j++ )
+    {
+        //fprintf (stderr, "CachedExample: removing temp file %s\n", j->second.c_str() );
+        NICE::FileMgt::deleteTempFile ( j->second );
+    }
+
+    for ( std::map<int, std::string>::const_iterator j = ltemps.begin();
+          j != ltemps.end();
+          j++ )
+    {
+        //fprintf (stderr, "CachedExample: removing temp file %s\n", j->second.c_str() );
+        NICE::FileMgt::deleteTempFile ( j->second );
+    }
 
 }
 
 void CachedExample::readImageData ()
 {
-  if ( imgfn == "" ) return;
-
-  NICE::Image orig = Preprocess::ReadImgAdv ( imgfn );
-  NICE::Image imggray;
+    ozsize = imgfn.size();
 
-  if ( newWidth > 0 )
-    Conversions::resizeImage ( orig, imggray, newWidth, newHeight );
-  else
-    imggray = orig;
+    if ( ozsize == 0 || imgfn[0] == "" )
+        return;
 
-  oxsize = imggray.width();
-  oysize = imggray.height();
-
-  ichannels[I_GRAYVALUES].freeData();
-  ichannels[I_GRAYVALUES].addChannel(imggray);
+    for ( int z = 0; z < ozsize; z++ )
+    {
+        NICE::Image orig = Preprocess::ReadImgAdv ( imgfn[z] );
+        NICE::Image imggray;
+
+        if ( newWidth > 0 )
+            Conversions::resizeImage ( orig, imggray, newWidth, newHeight );
+        else
+            imggray = orig;
+
+        if ( z == 0 )
+        {
+            oxsize = imggray.width();
+            oysize = imggray.height();
+
+            if ( ozsize > 1 )
+                ichannels3[I_GRAYVALUES].reInit( oxsize, oysize, ozsize, 1);
+            else
+            {
+                ichannels[I_GRAYVALUES].freeData();
+                ichannels[I_GRAYVALUES].addChannel(imggray);
+            }
+        }
+
+        if ( ozsize > 1 )
+            for ( int y = 0; y < oysize; y++ )
+                for ( int x = 0; x < oxsize; x++ )
+                    ichannels3[I_GRAYVALUES](x,y,z,0) = imggray.getPixel(x,y);
+    }
 }
 
 void CachedExample::readImageDataRGB ()
 {
-  if ( imgfn == "" ) return;
-
-  NICE::ColorImage img;
-  try {
-    img = Preprocess::ReadImgAdvRGB ( imgfn );
-  } catch ( NICE::ImageException & ) {
-    fprintf ( stderr, "error reading rgb image %s\n", imgfn.c_str() );
-    hasColorInformation = false;
-    return;
-  }
-
-  oxsize = img.width();
-  oysize = img.height();
+    ozsize = imgfn.size();
 
-  hasColorInformation = true;
+    if ( ozsize == 0 || imgfn[0] == "" )
+        return;
 
-  ichannels[I_COLOR].reInit ( oxsize, oysize, 3);
-  
-  for ( int y = 0 ; y < oysize ; y++ )
-    for ( int x = 0 ; x < oxsize ; x++)
+    for ( int z = 0; z < ozsize; z++ )
     {
-      ichannels[I_COLOR](x,y,0) = img.getPixel ( x, y, 0 );
-      ichannels[I_COLOR](x,y,1) = img.getPixel ( x, y, 1 );
-      ichannels[I_COLOR](x,y,2) = img.getPixel ( x, y, 2 );
+        NICE::ColorImage img;
+        try {
+            img = Preprocess::ReadImgAdvRGB ( imgfn[z] );
+        } catch ( NICE::ImageException & ) {
+            fprintf ( stderr, "error reading rgb image %s\n", imgfn[z].c_str() );
+            hasColorInformation = false;
+            return;
+        }
+
+        if ( z == 0 )
+        {
+            oxsize = img.width();
+            oysize = img.height();
+
+            hasColorInformation = true;
+
+            if ( ozsize > 1 )
+                ichannels3[I_COLOR].reInit ( oxsize, oysize, ozsize, 3);
+            else
+                ichannels[I_COLOR].reInit ( oxsize, oysize, 3);
+        }
+
+        for ( int y = 0; y < oysize; y++ )
+            for ( int x = 0; x < oxsize; x++ )
+            {
+                if ( ozsize > 1 )
+                {
+                    ichannels3[I_COLOR](x,y,z,0) = img.getPixel(x,y,0);
+                    ichannels3[I_COLOR](x,y,z,1) = img.getPixel(x,y,1);
+                    ichannels3[I_COLOR](x,y,z,2) = img.getPixel(x,y,2);
+                }
+                else
+                {
+                    ichannels[I_COLOR](x,y,0) = img.getPixel ( x, y, 0 );
+                    ichannels[I_COLOR](x,y,1) = img.getPixel ( x, y, 1 );
+                    ichannels[I_COLOR](x,y,2) = img.getPixel ( x, y, 2 );
+                }
+            }
     }
 }
 
 void CachedExample::calcIntegralImage ()
 {
-  if ( ichannels[I_GRAYVALUES].width() == 0 )
-  {
-    readImageData ();
-    if ( ichannels[I_GRAYVALUES].width() == 0 )
+    // in case of standard 2D images
+    if ( ozsize == 1 )
     {
-      fprintf ( stderr, "CachedExample::getChannel: unable to recover data channel\n" );
-      exit ( -1 );
+        if ( ichannels[I_GRAYVALUES].width() == 0 )
+        {
+            readImageData ();
+            if ( ichannels[I_GRAYVALUES].width() == 0 )
+            {
+                fprintf ( stderr, "CachedExample::getChannel: unable to recover data channel\n" );
+                exit ( -1 );
+            }
+        }
+
+        lchannels[L_INTEGRALIMAGE].reInit (
+                    ichannels[I_GRAYVALUES].width(),
+                    ichannels[I_GRAYVALUES].height(),
+                    1 );
+
+        NICE::ImageT<long int> tmp = lchannels[L_INTEGRALIMAGE][0];
+
+        GenericImageTools::calcIntegralImage (
+                    tmp,
+                    ichannels[I_GRAYVALUES][0],
+                    ichannels[I_GRAYVALUES].width(),
+                    ichannels[I_GRAYVALUES].height() );
+    }
+    // in case of a 3D images
+    else
+    {
+        if ( ichannels[I_GRAYVALUES].width() == 0 )
+        {
+            readImageData ();
+            if ( ichannels[I_GRAYVALUES].width() == 0 )
+            {
+                fprintf ( stderr, "CachedExample::getChannel: unable to recover data channel\n" );
+                exit ( -1 );
+            }
+        }
+
+        int nwidth = ichannels3[I_GRAYVALUES].width();
+        int nheight = ichannels3[I_GRAYVALUES].height();
+        int ndepth = ichannels3[I_GRAYVALUES].depth();
+        int nchannels = ichannels3[I_GRAYVALUES].channels();
+        lchannels3[L_INTEGRALIMAGE].reInit( nwidth, nheight, ndepth, nchannels);
+        for ( int c = 0; c < nchannels; c++ )
+        {
+            for ( int z = 0; z < ndepth; z++ )
+                for ( int y = 0; y < nheight; y++ )
+                    for ( int x = 0; x < nwidth; x++ )
+                    {
+                        lchannels3[L_INTEGRALIMAGE](x,y,z,c) =
+                                (long)ichannels3[L_INTEGRALIMAGE].get(x,y,z,c);
+                    }
+
+            lchannels3[L_INTEGRALIMAGE].calcIntegral(c);
+        }
     }
-  }
-
-  lchannels[L_INTEGRALIMAGE].reInit ( ichannels[I_GRAYVALUES].width(),
-                                      ichannels[I_GRAYVALUES].height(),
-                                      1);
-
-  ImageT<long int> tmp = lchannels[L_INTEGRALIMAGE][0];
-
-  GenericImageTools::calcIntegralImage (
-    tmp,
-    ichannels[I_GRAYVALUES][0],
-    ichannels[I_GRAYVALUES].width(),
-    ichannels[I_GRAYVALUES].height() );
 }
 
 void CachedExample::buildIntegralSV ( int svchannel,
-                                      SparseVector *_map,
+                                      NICE::SparseVector *_map,
                                       int xsize_s, int ysize_s )
 {
-  SparseVector *map = _map;
-  svmap[svchannel] = _map;
-  svmap_xsize[svchannel] = xsize_s;
-  svmap_ysize[svchannel] = ysize_s;
+    NICE::SparseVector *map = _map;
+    svmap[svchannel] = _map;
+    svmap_xsize[svchannel] = xsize_s;
+    svmap_ysize[svchannel] = ysize_s;
 
-  int k = xsize_s;
-  for ( int y = 1 ; y < ysize_s; y++, k += xsize_s )
-    map[k].add ( ( map[k-xsize_s] ) );
+    int k = xsize_s;
+    for ( int y = 1 ; y < ysize_s; y++, k += xsize_s )
+        map[k].add ( ( map[k-xsize_s] ) );
 
-  k = 1;
-  for ( int x = 1 ; x < xsize_s; x++, k++ )
-    map[k].add ( ( map[k-1] ) );
+    k = 1;
+    for ( int x = 1 ; x < xsize_s; x++, k++ )
+        map[k].add ( ( map[k-1] ) );
 
-  k = xsize_s + 1;
+    k = xsize_s + 1;
 
-  for ( int y = 1 ; y < ysize_s ; y++, k++ )
-  {
-    for ( int x = 1 ; x < xsize_s ; x++, k++ )
+    for ( int y = 1 ; y < ysize_s ; y++, k++ )
     {
-      map[k].add ( ( map[k-1] ) );
-      map[k].add ( ( map[k-xsize_s] ) );
-      map[k].add ( ( map[k-xsize_s-1] ), -1.0 );
+        for ( int x = 1 ; x < xsize_s ; x++, k++ )
+        {
+            map[k].add ( ( map[k-1] ) );
+            map[k].add ( ( map[k-xsize_s] ) );
+            map[k].add ( ( map[k-xsize_s-1] ), -1.0 );
+        }
     }
-  }
 }
 
 void CachedExample::setSVMap ( int svchannel,
-                               SparseVector *_map,
+                               NICE::SparseVector *_map,
                                int xsize_s, int ysize_s )
 {
-  svmap[svchannel] = _map;
-  svmap_xsize[svchannel] = xsize_s;
-  svmap_ysize[svchannel] = ysize_s;
+    svmap[svchannel] = _map;
+    svmap_xsize[svchannel] = xsize_s;
+    svmap_ysize[svchannel] = ysize_s;
 }
 
-SparseVector *CachedExample::getSVMap ( int svchannel,
+NICE::SparseVector *CachedExample::getSVMap ( int svchannel,
                                         int & _xsize, int & _ysize,
                                         int & _tm_xsize, int & _tm_ysize ) const
 {
-  _xsize = oxsize;
-  _ysize = oysize;
-  _tm_xsize = svmap_xsize[svchannel];
-  _tm_ysize = svmap_ysize[svchannel];
-  assert ( svmap[svchannel] != NULL );
-  return svmap[svchannel];
+    _xsize = oxsize;
+    _ysize = oysize;
+    _tm_xsize = svmap_xsize[svchannel];
+    _tm_ysize = svmap_ysize[svchannel];
+    assert ( svmap[svchannel] != NULL );
+    return svmap[svchannel];
 }
 
 bool CachedExample::colorInformationAvailable() const
 {
-  if ( hasColorInformation ) return true;
-  else {
-    if ( imgfn.size() == 0 ) return false;
-
-//     int tmp_xsize, tmp_ysize, tmp_maxval, tmp_nr;
-    // refactor: InfImgFile ( imgfn, tmp_xsize, tmp_ysize, tmp_maxval, tmp_nr );
-    ImageFile imgf ( imgfn );
-    const ImageFile::Header & imgfheader = imgf.getHeader();
-//     tmp_xsize = imgfheader.width;
-//     tmp_ysize = imgfheader.height;
-//     tmp_maxval = 255;
-    int tmp_nr = imgfheader.channel;
-
-    if ( tmp_nr > 1 ) return true;
-    else return false;
-  }
+    if ( hasColorInformation ) return true;
+    else {
+        if ( imgfn.size() == 0 ) return false;
+
+        //     int tmp_xsize, tmp_ysize, tmp_maxval, tmp_nr;
+        // refactor: InfImgFile ( imgfn, tmp_xsize, tmp_ysize, tmp_maxval, tmp_nr );
+        NICE::ImageFile imgf ( imgfn[0] );
+        const NICE::ImageFile::Header & imgfheader = imgf.getHeader();
+        //     tmp_xsize = imgfheader.width;
+        //     tmp_ysize = imgfheader.height;
+        //     tmp_maxval = 255;
+        int tmp_nr = imgfheader.channel;
+
+        if ( tmp_nr > 1 ) return true;
+        else return false;
+    }
 }
 
 void CachedExample::dropPreCached()
 {
-  dropImages<double> ( dchannels, dtemps, D_NUMCHANNELS );
-  dropImages<int> ( ichannels, itemps, I_NUMCHANNELS );
-  dropImages<long> ( lchannels, ltemps, L_NUMCHANNELS );
+    dropImages<double> ( dchannels, dtemps, D_NUMCHANNELS );
+    dropImages<int> ( ichannels, itemps, I_NUMCHANNELS );
+    dropImages<long> ( lchannels, ltemps, L_NUMCHANNELS );
 }

+ 167 - 13
cbaselib/CachedExample.h

@@ -1,8 +1,8 @@
 /**
 * @file CachedExample.h
 * @brief data caching of several feature images and many more
-* @author Erik Rodner
-* @date 04/21/2008
+* @author Erik Rodner, Sven Sickert
+* @date 04/21/2008 (modified 03/18/2016)
 
 */
 #ifndef CACHEDEXAMPLEINCLUDE
@@ -13,6 +13,7 @@
 
 #include "core/vector/SparseVectorT.h"
 #include "core/image/MultiChannelImageT.h"
+#include "core/image/MultiChannelImage3DT.h"
 #include "core/basics/FileMgt.h"
 
 namespace OBJREC
@@ -31,23 +32,30 @@ class CachedExample
     int newWidth;
     /** resize image to this fixed height */
     int newHeight;
+    /** resize image to this fixed depth */
+    int newDepth;
 
     /** original image width */
     int oxsize;
     /** original image height */
     int oysize;
+    /** original image depth */
+    int ozsize;
 
-    /** filename of image */
-    std::string imgfn;
+    /** list of filenames of images */
+    std::vector<std::string> imgfn;
 
     /** array of double images */
     NICE::MultiChannelImageT<double> *dchannels;
+    NICE::MultiChannelImage3DT<double> *dchannels3;
 
     /** array of integer images */
     NICE::MultiChannelImageT<int> *ichannels;
+    NICE::MultiChannelImage3DT<int> *ichannels3;
 
     /** array of histogram images */
     NICE::MultiChannelImageT<long> *lchannels;
+    NICE::MultiChannelImage3DT<long> *lchannels3;
 
     /** maps for temporary files */
     std::map<int, std::string> dtemps;
@@ -118,20 +126,44 @@ class CachedExample
         @param newWidth resize raw image to this width
         @param newHeight resize raw image to this height
     */
-    CachedExample ( const std::string & imgfn, int newWidth = -1,
+    CachedExample ( const std::string & imgfn,
+                    int newWidth = -1,
                     int newHeight = -1 );
 
+    /** simple 3d constructor
+        @param imgfn image filename
+        @param newWidth resize raw image to this width
+        @param newHeight resize raw image to this height
+        @param newDepth resize raw image to this depth
+    */
+    CachedExample ( const std::vector<std::string> & imgfn,
+                    int newWidth = -1,
+                    int newHeight = -1,
+                    int newDepth = -1 );
+
     /** constructor (disabled buffering)
         @param img gray-value image
     */
     CachedExample ( const NICE::Image & img );
 
+    /** constructor (disabled buffering)
+        @param img gray-value multi channel image
+    */
+    CachedExample ( const NICE::MultiChannelImageT<int> & img );
+
     /** constructor (disabled buffering)
         @param img rgb image
         @param disableGrayConversion whether to provide gray values or not
     */
     CachedExample ( const NICE::ColorImage & img, bool disableGrayConversion = false );
 
+    /** constructor (disabled buffering)
+        @param img multi channel image 3D
+        @param disableGrayConversion whether to provide gray values or not
+    */
+    CachedExample ( const NICE::MultiChannelImage3DT<int> & img,
+                    bool disableGrayConversion = false );
+
     /** simple destructor */
     virtual ~CachedExample();
 
@@ -139,17 +171,26 @@ class CachedExample
      * get the NICE::Image Filename
      * @return NICE::Image Filename
      */
-    inline std::string getFilename();
+    inline std::string getFilename(const int z = 0);
 
+    /**
+     * @brief get amount of images
+     * @return amount of images
+     */
+    inline int getNumImages ();
 
     /** get double image channel
         @param channel channel type (choose from enum type)
-        @param[out] xsize width of image
-        @param[out] ysize height of image
         @return buffer to image data
     */
     inline NICE::MultiChannelImageT<double> & getDChannel ( int channel );
 
+    /** get double image channel 3d
+        @param channel channel type (choose from enum type)
+        @return buffer to image data
+    */
+    inline NICE::MultiChannelImage3DT<double> & getDChannel3 ( int channel );
+
     /** get integer image channel
         @param channel channel type (choose from enum type)
         @param[out] xsize width of image
@@ -158,6 +199,12 @@ class CachedExample
     */
     inline NICE::MultiChannelImageT<int> & getIChannel ( int channel );
 
+    /** get integer image channel 3d
+        @param channel channel type (choose from enum type)
+        @return buffer to image data
+    */
+    inline NICE::MultiChannelImage3DT<int> & getIChannel3 ( int channel );
+
     /** get long image channel
         @param channel channel type (choose from enum type)
         @param[out] xsize width of image
@@ -166,6 +213,12 @@ class CachedExample
     */
     inline NICE::MultiChannelImageT<long> & getLChannel ( int channel );
 
+    /** get long image channel 3d
+        @param channel channel type (choose from enum type)
+        @return buffer to image data
+    */
+    inline NICE::MultiChannelImage3DT<long> & getLChannel3 ( int channel );
+
     /** get histogram image
         @param svchannel channel type (choose from histogram channel enum)
         @param[out] xsize width of raw image
@@ -200,7 +253,16 @@ class CachedExample
     {
       xsize = oxsize;
       ysize = oysize;
-    };
+    }
+
+    /** get image sizes 3d */
+    void getImageSize3 ( int & xsize, int & ysize, int & zsize ) const
+    {
+        xsize = oxsize;
+        ysize = oysize;
+        zsize = ozsize;
+    }
+
 
     /** drop precached data:
      (1) this is only possible if an image filename is given
@@ -216,6 +278,16 @@ class CachedExample
 
 
 /********************** INLINE FUNCTIONS *****************************/
+inline std::string CachedExample::getFilename( const int z )
+{
+    return imgfn[z];
+}
+
+inline int CachedExample::getNumImages ()
+{
+    return imgfn.size();
+}
+
 inline NICE::MultiChannelImageT<double> & CachedExample::getDChannel ( int channel )
 {
   assert ( ( channel >= 0 ) && ( channel < D_NUMCHANNELS ) );
@@ -239,9 +311,27 @@ inline NICE::MultiChannelImageT<double> & CachedExample::getDChannel ( int chann
   return dchannels[channel];
 }
 
-inline std::string CachedExample::getFilename()
+inline NICE::MultiChannelImage3DT<double> & CachedExample::getDChannel3 ( int channel )
 {
-  return imgfn;
+    assert ( ( channel >= 0 ) && ( channel < D_NUMCHANNELS ) );
+
+    if ( dchannels3[channel].channels() == 0 )
+    {
+        std::map<int, std::string>::const_iterator j = dtemps.find ( channel );
+        if ( j == dtemps.end() )
+        {
+            //fprintf (stderr, "NICE::MultiChannelImageT: unable to recover data channel %s (double %d)!\n",
+            // imgfn.c_str(), channel);
+        }
+        else
+        {
+            //fprintf (stderr, "NICE::MultiChannelImageT: restoring data from %s ", j->second.c_str() );
+            dchannels3[channel].restore ( j->second );
+            //fprintf (stderr, "(%d x %d)\n", dchannels[channel].xsize, dchannels[channel].ysize );
+        }
+    }
+
+    return dchannels3[channel];
 }
 
 inline NICE::MultiChannelImageT<int> & CachedExample::getIChannel ( int channel )
@@ -250,11 +340,11 @@ inline NICE::MultiChannelImageT<int> & CachedExample::getIChannel ( int channel
 
   if ( ( ichannels[channel].channels() == 0 ) )
   {
-    if ( ( imgfn != "" ) && ( channel == I_GRAYVALUES ) )
+      if ( ( imgfn[0] != "" ) && ( channel == I_GRAYVALUES ) )
     {
       readImageData();
     }
-    else if ( ( imgfn != "" ) && ( channel == I_COLOR ) )
+      else if ( ( imgfn[0] != "" ) && ( channel == I_COLOR ) )
     {
       readImageDataRGB();
       assert ( hasColorInformation );
@@ -278,6 +368,40 @@ inline NICE::MultiChannelImageT<int> & CachedExample::getIChannel ( int channel
   return ichannels[channel];
 }
 
+inline NICE::MultiChannelImage3DT<int> & CachedExample::getIChannel3 ( int channel )
+{
+    assert ( ( channel >= 0 ) && ( channel < I_NUMCHANNELS ) );
+
+    if ( ( ichannels3[channel].channels() == 0 ) )
+    {
+        if ( ( imgfn[0] != "" ) && ( channel == I_GRAYVALUES ) )
+        {
+            readImageData();
+        }
+        else if ( ( imgfn[0] != "" ) && ( channel == I_COLOR ) )
+        {
+            readImageDataRGB();
+            assert ( hasColorInformation );
+        }
+        else
+        {
+            std::map<int, std::string>::const_iterator j = itemps.find ( channel );
+            if ( j == itemps.end() )
+            {
+                //fprintf (stderr, "NICE::MultiChannelImageT: unable to recover data channel (int %d)!\n", channel);
+                //exit(-1);
+            }
+            else
+            {
+                //fprintf (stderr, "NICE::MultiChannelImageT: restoring data from %s\n", j->second.c_str() );
+                ichannels3[channel].restore ( j->second );
+            }
+        }
+    }
+
+    return ichannels3[channel];
+}
+
 inline NICE::MultiChannelImageT<long> & CachedExample::getLChannel ( int channel )
 {
   assert ( ( channel >= 0 ) && ( channel < L_NUMCHANNELS ) );
@@ -308,6 +432,36 @@ inline NICE::MultiChannelImageT<long> & CachedExample::getLChannel ( int channel
   return lchannels[channel];
 }
 
+inline NICE::MultiChannelImage3DT<long> & CachedExample::getLChannel3 ( int channel )
+{
+    assert ( ( channel >= 0 ) && ( channel < L_NUMCHANNELS ) );
+
+    if ( lchannels3[channel].channels() == 0 )
+    {
+        std::map<int, std::string>::const_iterator j = ltemps.find ( channel );
+        if ( j == ltemps.end() )
+        {
+
+            if ( channel == L_INTEGRALIMAGE )
+            {
+                calcIntegralImage();
+            }
+            else
+            {
+                //fprintf (stderr, "NICE::MultiChannelImageT: unable to recover data channel (long %d)!\n", channel);
+                //exit(-1);
+            }
+        }
+        else
+        {
+            //fprintf (stderr, "NICE::MultiChannelImageT: restoring data from %s\n", j->second.c_str() );
+            lchannels3[channel].restore ( j->second );
+        }
+    }
+
+    return lchannels3[channel];
+}
+
 template<class ImgPixelValue>
 void CachedExample::dropImages ( NICE::MultiChannelImageT<ImgPixelValue> *images, std::map<int, std::string> & temps, int numImages )
 {

+ 97 - 17
cbaselib/Example.cpp

@@ -12,12 +12,12 @@ Example::Example()
 {
 	weight = 0.0;
 	height = 0;
+    depth = 0;
 	width = 0;
-	x = 0;
-	y = 0;
+    x = y = z = 0;
 	vec = NULL;
 	svec = NULL;
-  ce = NULL;
+    ce = NULL;
 	position = 0;
 }
 
@@ -27,16 +27,25 @@ Example::~Example ()
 
 Example::Example ( CachedExample *_ce )
 {
-    _ce->getImageSize ( width, height );
+    if ( _ce->getNumImages() > 1 )
+    {
+        _ce->getImageSize3 ( width, height, depth );
+    }
+    else
+    {
+        _ce->getImageSize( width, height );
+        depth = 1;
+    }
 
-    if ( width % 2 == 0 )
-	width--;
+    if ( width % 2 == 0 ) width--;
 
-    if ( height % 2 == 0 )
-	height--;
+    if ( height % 2 == 0 ) height--;
+
+    if ( depth % 2 == 0 ) depth--;
 
     x = width/2;
     y = height/2;
+    z = depth/2;
 
     ce = _ce; 
     vec = NULL;
@@ -53,14 +62,35 @@ Example::Example ( CachedExample *_ce,
     ce = _ce;
     x  = _x;
     y  = _y;
+    z  = 0;
     width = 0;
     height = 0;
+    depth = 0;
     vec = NULL;
     svec = NULL;
     weight = _weight;
 	position = 0;
 }
 
+Example::Example ( CachedExample *_ce,
+                           int _x,
+                           int _y,
+                           int _z,
+                           double _weight )
+{
+    ce = _ce;
+    x  = _x;
+    y  = _y;
+    z  = _z;
+    width = 0;
+    height = 0;
+    depth = 0;
+    vec = NULL;
+    svec = NULL;
+    weight = _weight;
+    position = 0;
+}
+
 Example::Example ( CachedExample *_ce, 
 						   int _x,
 						   int _y,
@@ -71,8 +101,10 @@ Example::Example ( CachedExample *_ce,
     ce = _ce;
     x  = _x;
     y  = _y;
+    z  = 0;
     width = _width;
     height = _height;
+    depth = 1;
     assert ( (width > 0) && (height > 0) );
 
     vec = NULL;
@@ -81,11 +113,35 @@ Example::Example ( CachedExample *_ce,
 	position = 0;
 }
 
+Example::Example ( CachedExample *_ce,
+                           int _x,
+                           int _y,
+                           int _z,
+                           int _width,
+                           int _height,
+                           int _depth,
+                           double _weight )
+{
+    ce = _ce;
+    x  = _x;
+    y  = _y;
+    z  = _z;
+    width = _width;
+    height = _height;
+    depth = _depth;
+    assert ( (width > 0) && (height > 0) && assert(depth > 0) );
+
+    vec = NULL;
+    svec = NULL;
+    weight = _weight;
+    position = 0;
+}
+
 Example::Example ( NICE::Vector *_vec, 
 						   double _weight )
 {
-    x = y = 0;
-    width = height = 0;
+    x = y = z = 0;
+    width = height = depth = 0;
     ce = NULL;
     vec = _vec;
     svec = NULL;
@@ -128,20 +184,40 @@ void Example::copy ( const Example &ex)
 	position = ex.position;
 	width = ex.width;
 	height = ex.height;
+    depth = ex.depth;
 	x = ex.x;
 	y = ex.y;
+    z = ex.z;
 	ce = ex.ce;
 	scale = ex.scale;
 }
 
 void Example::restore (istream & is, int format)
 {
-	is >> weight;
-	is >> x;
-	is >> y;
-	is >> width;
-	is >> height;
-	is >> position;
+    if ( format == 1 )
+    {
+        is >> weight;
+        is >> x;
+        is >> y;
+        is >> z;
+        is >> width;
+        is >> height;
+        is >> depth;
+        is >> position;
+    }
+    else
+    {
+        is >> weight;
+        is >> x;
+        is >> y;
+        is >> width;
+        is >> height;
+        is >> position;
+
+        depth = 1;
+        z = 0;
+    }
+
 	int tmp;
 	is >> tmp;
 
@@ -167,7 +243,11 @@ void Example::restore (istream & is, int format)
 
 void Example::store (ostream & os, int format) const
 {
-	os << weight << " " <<  x << " " << y << " " << width << " " << height << " " << position << endl;
+    if ( format == 1 )
+        os << weight << " " <<  x << " " << y << " " << z << " " << width << " " << height << " " << depth << " " << position << endl;
+    else
+        os << weight << " " <<  x << " " << y << " " << width << " " << height << " " << position << endl;
+
 	if(svec == NULL)
 		os << 0 << endl;
 	else

+ 26 - 0
cbaselib/Example.h

@@ -26,11 +26,15 @@ class Example
     long long int x;
     /** y position of window */
     long long int y;
+    /** z position of window */
+    long long int z;
 
     /** width of window */
     int width;
     /** height of window */
     int height;
+    /** depth of window */
+    int depth;
 
     //! if some examples are related, they have the same position
     int position;
@@ -61,6 +65,15 @@ class Example
     */
     Example ( CachedExample *ce, int x, int y, double weight = 1.0 );
 
+    /** constructor 3d
+        @param ce associated image data
+        @param x x position of window
+        @param y y position of window
+        @param z z position of window
+        @param weight weight of example
+    */
+    Example ( CachedExample *ce, int x, int y, int z, double weight = 1.0 );
+
     /** constructor
         @param ce associated image data
         @param x x position of window
@@ -69,6 +82,19 @@ class Example
     */
     Example ( CachedExample *ce, int x, int y, int width, int height, double weight = 1.0 );
 
+    /** constructor 3d
+        @param ce associated image data
+        @param x x position of window
+        @param y y position of window
+        @param z z position of window
+        @param width width of window
+        @param height height of window
+        @param depth depth of window
+        @param weight weight of example
+    */
+    Example ( CachedExample *ce, int x, int y, int z,
+                int width, int height, int depth, double weight = 1.0 );
+
     /** evil workaround: simple constructors for std::vector examples
         @param vec simple feature vector
         @param weight optional weight