DGtal
1.5.beta
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.
47
bool
testHDF5Reader
()
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
60
typedef
ImageSelector < Z2i::Domain, unsigned char>::Type
Image
;
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
76
bool
testHDF5_3DReader
()
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
87
typedef
ImageSelector<TDomain, unsigned char>::Type
Image
;
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
// //
DGtal::GrayscaleColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Definition:
GrayscaleColorMap.h:94
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition:
HyperRectDomain.h:100
DGtal::ImageContainerBySTLVector
Definition:
ImageContainerBySTLVector.h:127
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstIterator
std::vector< Value >::const_iterator ConstIterator
Definition:
ImageContainerBySTLVector.h:265
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition:
Image.h:70
DGtal::SpaceND
Definition:
SpaceND.h:96
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::trace
Trace trace
Definition:
Common.h:153
DGtal::HDF5Reader
Aim: Import a HDF5 file.
Definition:
HDF5Reader.h:63
DGtal::PPMWriter
Aim: Export a 2D and a 3D Image using the Netpbm PPM formats (ASCII mode).
Definition:
PPMWriter.h:73
main
int main(int argc, char **argv)
Definition:
testHDF5Reader.cpp:119
testHDF5_3DReader
bool testHDF5_3DReader()
Definition:
testHDF5Reader.cpp:76
testHDF5Reader
bool testHDF5Reader()
Definition:
testHDF5Reader.cpp:47
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition:
testSimpleRandomAccessRangeFromPoint.cpp:45
tests
io
readers
testHDF5Reader.cpp
Generated on Fri Dec 20 2024 12:44:33 for DGtal by
1.9.1