DGtal  1.2.0
testHDF5Reader.cpp
Go to the documentation of this file.
1 
30 #include <iostream>
31 #include "DGtal/base/Common.h"
32 #include "DGtal/helpers/StdDefs.h"
33 #include "DGtal/io/writers/PPMWriter.h"
34 #include "DGtal/io/readers/HDF5Reader.h"
35 #include "DGtal/images/ImageSelector.h"
36 #include "DGtal/io/colormaps/GrayscaleColorMap.h"
37 #include "ConfigTest.h"
38 
40 
41 using namespace std;
42 using namespace DGtal;
43 
45 // Functions for testing class HDF5Reader.
48 {
49  unsigned int nbok = 0;
50  unsigned int nb = 0;
51 
52  trace.beginBlock ( "Testing hdf5 reader ..." );
53  nbok += true ? 1 : 0;
54  nb++;
55  std::string filename = testPath + "samples/ex_image2.h5";
56 
57  trace.info() << "Loading filename: " << filename << std::endl;
58 
59  typedef GrayscaleColorMap<unsigned char> Gray; // a simple GrayscaleColorMap varying on 'unsigned char' values
61 
62  Image image = HDF5Reader<Image>::importHDF5( filename, "/image8bit" );
63  trace.info() << "image8bitFromHDF5image image: " << image << endl;
64  PPMWriter<Image,Gray>::exportPPM("image8bitFromHDF5image.ppm", image, Gray(0,255));
65 
66  image = HDF5Reader<Image>::importHDF5( filename, "/image24bitpixel" );
67  trace.info() << "image24bitFromHDF5image image: " << image << endl;
68  PPMWriter<Image,Gray>::exportPPM("image24bitFromHDF5image.ppm", image, Gray(0,255));
69 
70  trace.info() << "(" << nbok << "/" << nb << ") " << "true == true" << std::endl;
71  trace.endBlock();
72 
73  return nbok == nb;
74 }
75 
77 {
78  unsigned int nbok = 0;
79  unsigned int nb = 0;
80 
81  trace.beginBlock ( "Testing hdf5 3D reader ..." );
82 
83  typedef SpaceND<3> Space4Type;
84  typedef HyperRectDomain<Space4Type> TDomain;
85 
86  //Default image selector = STLVector
88 
89 
90  std::string filename = testPath + "samples/cat10.h5";
91  Image image = HDF5Reader<Image>::importHDF5_3D( filename, "/UInt8Array3D" );
92 
93  trace.info() << image <<endl;
94 
95  nbok += true ? 1 : 0;
96  nb++;
97 
98  unsigned int nbval=0;
99  for(Image::ConstIterator it=image.begin(), itend=image.end();
100  it != itend; ++it)
101  if ( (*it) != 0)
102  nbval++;
103 
104  trace.info() << "Number of points with (val!=0) = "<<nbval<<endl;
105 
106  nbok += ( nbval == 8043) ? 1 : 0;
107  nb++;
108 
109  trace.info() << "(" << nbok << "/" << nb << ") "
110  << "true == true" << std::endl;
111  trace.endBlock();
112 
113  return nbok == nb;
114 }
115 
117 // Standard services - public :
118 
119 int main( int argc, char** argv )
120 {
121  trace.beginBlock ( "Testing class HDF5Reader" );
122  trace.info() << "Args:";
123  for ( int i = 0; i < argc; ++i )
124  trace.info() << " " << argv[ i ];
125  trace.info() << endl;
126 
127  bool res = testHDF5Reader() && testHDF5_3DReader(); // && ... other tests
128  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
129  trace.endBlock();
130  return res ? 0 : 1;
131 }
132 
133 // //
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
Aim: Import a HDF5 file.
Definition: HDF5Reader.h:63
Aim: Export a 2D and a 3D Image using the Netpbm PPM formats (ASCII mode).
Definition: PPMWriter.h:73
int main(int argc, char **argv)
bool testHDF5_3DReader()
bool testHDF5Reader()
ImageContainerBySTLVector< Domain, Value > Image