DGtal 1.4.0
Loading...
Searching...
No Matches
testGenericReader.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/images/ImageContainerBySTLVector.h"
34#include "DGtal/io/readers/GenericReader.h"
35#include "DGtal/helpers/StdDefs.h"
36#include "ConfigTest.h"
37
38
39
40
41
43
45// Functions for testing class GenericReader.
47
52{
53 unsigned int nbok = 0;
54 unsigned int nb = 0;
55
56 DGtal::trace.beginBlock ( "Testing 2D/3D Image Reader" );
57
60
61#ifdef WITH_ITK
63 Image3D16bits;
64#endif // WITH_ITK
65
69
70
71 std::string filenameImage1 = testPath + "samples/cat10.vol";
72 Image3D anImportedImage1= DGtal::GenericReader<Image3D>::import(filenameImage1);
73 DGtal::Z3i::Domain domain1 = anImportedImage1.domain();
74 unsigned int size0Img1= domain1.upperBound()[0]-domain1.lowerBound()[0]+1;
75 unsigned int size1Img1= domain1.upperBound()[1]-domain1.lowerBound()[1]+1;
76 unsigned int size2Img1= domain1.upperBound()[2]-domain1.lowerBound()[2]+1;
77 DGtal::trace.info()<<"Vol image read: size[0]:" << size0Img1 ;
78 DGtal::trace.info()<<"size[1]: " << size1Img1;
79 DGtal::trace.info()<<"size[2]: " << size2Img1 << std::endl;
80 nbok += (size0Img1==40 && size1Img1==40 && size2Img1==40) ? 1 : 0;
81 nb++;
82 std::string filenameImage0 = testPath + "samples/test.longvol";
83 Image3D64bits anImportedImage0= DGtal::GenericReader<Image3D64bits>::import(filenameImage0);
84 DGtal::Z3i::Domain domain0 = anImportedImage0.domain();
85 unsigned int size0Img0= domain0.upperBound()[0]-domain0.lowerBound()[0]+1;
86 unsigned int size1Img0= domain0.upperBound()[1]-domain0.lowerBound()[1]+1;
87 unsigned int size2Img0= domain0.upperBound()[2]-domain0.lowerBound()[2]+1;
88 DGtal::trace.info()<<"Longvol image read: size[0]:" << size0Img0 ;
89 DGtal::trace.info()<<"size[1]: " << size1Img0;
90 DGtal::trace.info()<<"size[2]: " << size2Img0 << std::endl;
91 nbok += (size0Img0==16 && size1Img0==16 && size2Img0==16) ? 1 : 0;
92 nb++;
93 std::string filenameImage2 = testPath + "samples/cat10.pgm3d";
94 Image3D anImportedImage2= DGtal::GenericReader<Image3D>::import(filenameImage2);
95 DGtal::Z3i::Domain domain2 = anImportedImage2.domain();
96 unsigned int size0Img2= domain2.upperBound()[0]-domain2.lowerBound()[0]+1;
97 unsigned int size1Img2= domain2.upperBound()[1]-domain2.lowerBound()[1]+1;
98 unsigned int size2Img2= domain2.upperBound()[2]-domain2.lowerBound()[2]+1;
99 DGtal::trace.info()<<"Pgm3D image read: size[0]:" << size0Img2 ;
100 DGtal::trace.info()<<"size[1]: " << size1Img2;
101 DGtal::trace.info()<<"size[2]: " << size2Img2 << std::endl;;
102 nbok += (size0Img2==40 && size1Img2==40 && size2Img2==40) ? 1 : 0;
103 nb++;
104
106 Image3D imageanImportedImage2 = DGtal::GenericReader<Image3D>::importWithValueFunctor( filenameImage2, RescalFCT(0, 120,
107 0, 255) );
108 domain2 = anImportedImage2.domain();
109 size0Img2= domain2.upperBound()[0]-domain2.lowerBound()[0]+1;
110 size1Img2= domain2.upperBound()[1]-domain2.lowerBound()[1]+1;
111 size2Img2= domain2.upperBound()[2]-domain2.lowerBound()[2]+1;
112 DGtal::trace.info()<<"Pgm3D image read (with scale functor) : size[0]:" << size0Img2 ;
113 DGtal::trace.info()<<"size[1]: " << size1Img2;
114 DGtal::trace.info()<<"size[2]: " << size2Img2 << std::endl;;
115 nbok += (size0Img2==40 && size1Img2==40 && size2Img2==40) ? 1 : 0;
116 nb++;
117
118
119#ifdef WITH_HDF5
120 std::string filenameImageh5 = testPath + "samples/cat10.h5";
121 Image3D anImportedImageh5= DGtal::GenericReader<Image3D>::import(filenameImageh5);
122 DGtal::Z3i::Domain domainh5 = anImportedImageh5.domain();
123 unsigned int size0Imgh5= domainh5.upperBound()[0]-domainh5.lowerBound()[0]+1;
124 unsigned int size1Imgh5= domainh5.upperBound()[1]-domainh5.lowerBound()[1]+1;
125 unsigned int size2Imgh5= domainh5.upperBound()[2]-domainh5.lowerBound()[2]+1;
126 DGtal::trace.info()<<"HDF5 3D image read: size[0]:" << size0Imgh5;
127 DGtal::trace.info()<<"size[1]: " << size1Imgh5;
128 DGtal::trace.info()<<"size[2]: " << size2Imgh5 << std::endl;;
129 nbok += (size0Imgh5==40 && size1Imgh5==40 && size2Imgh5==40) ? 1 : 0;
130 nb++;
131#endif
132 std::string filenameImage3 = testPath + "samples/contourS.pgm";
133 Image2D anImportedImage3= DGtal::GenericReader<Image2D>::import(filenameImage3);
134 DGtal::Z2i::Domain domain3 = anImportedImage3.domain();
135 unsigned int size0Img3= domain3.upperBound()[0]-domain3.lowerBound()[0]+1;
136 unsigned int size1Img3= domain3.upperBound()[1]-domain3.lowerBound()[1]+1;
137
138 DGtal::trace.info()<<"Pgm image read: size[0]:" << size0Img3 ;
139 DGtal::trace.info()<<"size[1]: " << size1Img3 << std::endl;;
140 nbok += (size0Img3==185 && size1Img3==85 ) ? 1 : 0;
141 nb++;
142
143 std::string filenameImage4 = testPath + "samples/raw32bits5x5x5.raw";
144 Image3D32bits anImportedImage4= DGtal::GenericReader<Image3D32bits>::import(filenameImage4, 5, 5, 5);
145 DGtal::Z3i::Domain domain4 = anImportedImage4.domain();
146 unsigned int size0Img4= domain4.upperBound()[0]-domain4.lowerBound()[0]+1;
147 unsigned int size1Img4= domain4.upperBound()[1]-domain4.lowerBound()[1]+1;
148 unsigned int size2Img4= domain4.upperBound()[2]-domain4.lowerBound()[2]+1;
149 DGtal::trace.info()<<"Raw32 bits 3D image read: size[0]:" << size0Img4;
150 DGtal::trace.info()<<"size[1]: " << size1Img4;
151 DGtal::trace.info()<<"size[2]: " << size2Img4 << std::endl;
152 DGtal::trace.info()<<"Image value of Point (2,3,4): " << anImportedImage4(DGtal::Z3i::Point(2,3,4)) << " (should be 250000*2*3*4) "<<std::endl;
153 nbok += (size0Img4==5 && size1Img4==5 && size2Img4==5 && anImportedImage4(DGtal::Z3i::Point(2,3,4))==250000*2*3*4) ? 1 : 0;
154 nb++;
155
156 std::string filenameImage5 = testPath + "samples/raw32bits5x5.raw";
157 Image2D32bits anImportedImage5= DGtal::GenericReader<Image2D32bits>::import(filenameImage5, 5, 5);
158 DGtal::Z2i::Domain domain5 = anImportedImage5.domain();
159 unsigned int size0Img5= domain5.upperBound()[0]-domain5.lowerBound()[0]+1;
160 unsigned int size1Img5= domain5.upperBound()[1]-domain5.lowerBound()[1]+1;
161 DGtal::trace.info()<<"Raw32 bits 3D image read: size[0]:" << size0Img4;
162 DGtal::trace.info()<<"size[1]: " << size1Img5 << std::endl;
163 DGtal::trace.info()<<"Image value of Point (2,3): " << anImportedImage5(DGtal::Z2i::Point(2,3)) << " (should be 250000*2*3*4) "<<std::endl;
164 nbok += (size0Img5==5 && size1Img5==5 && anImportedImage5(DGtal::Z2i::Point(2,3))==250000*2*3*4) ? 1 : 0;
165 nb++;
166
167#ifdef WITH_ITK
168 std::string filenameImage6 = testPath + "samples/lobsterCroped16b.mhd";
170 RescalFCT2 resc2 = RescalFCT2( 0, 65535, 0, 255 );
171 Image3D anImportedImage6 =
173 resc2 );
174 DGtal::Z3i::Domain domain6 = anImportedImage6.domain();
175 unsigned int size0Img6 =
176 domain6.upperBound()[ 0 ] - domain6.lowerBound()[ 0 ] + 1;
177 unsigned int size1Img6 =
178 domain6.upperBound()[ 1 ] - domain6.lowerBound()[ 1 ] + 1;
179 unsigned int size2Img6 =
180 domain6.upperBound()[ 2 ] - domain6.lowerBound()[ 2 ] + 1;
181
182 DGtal::trace.info() << "mhd 16 bits 3D image read: size[0]:" << size0Img6;
183 DGtal::trace.info() << "size[1]: " << size1Img6 << std::endl;
184 DGtal::trace.info() << "Image value of Point (35,29, 3): "
185 << anImportedImage6( DGtal::Z3i::Point( 35, 29, 3 ) )
186 << " (should be" << resc2( 60400 ) << std::endl;
187 nbok +=
188 ( size0Img6 == 51 && size1Img6 == 91 && size2Img6 == 31 &&
189 anImportedImage6( DGtal::Z3i::Point( 35, 29, 3 ) ) == resc2( 60400 ) )
190 ? 1
191 : 0;
192 nb++;
193
194 Image3D16bits anImportedImage7 =
196 DGtal::trace.info() << "Image value of Point (35,29, 3): "
197 << anImportedImage7( DGtal::Z3i::Point( 35, 29, 3 ) )
198 << " (should be" << 60400 << " )" << std::endl;
199 nbok +=
200 ( anImportedImage7( DGtal::Z3i::Point( 35, 29, 3 ) ) == 60400 ) ? 1 : 0;
201 nb++;
202#endif // WITH_ITK
203
204 DGtal::trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
206
207 return nbok == nb;
208}
209
211// Standard services - public :
212
213int main( int argc, char** argv )
214{
215 DGtal::trace.beginBlock ( "Testing class GenericReader" );
216 DGtal::trace.info() << "Args:";
217 for ( int i = 0; i < argc; ++i )
218 DGtal::trace.info() << " " << argv[ i ];
219 DGtal::trace.info() << std::endl;
220
221 bool res = testGenericReader(); // && ... other tests
222 DGtal::trace.emphase() << ( res ? "Passed." : "Error." ) << std::endl;
224 return res ? 0 : 1;
225}
226// //
const Point & lowerBound() const
const Point & upperBound() const
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition Common.h:153
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
static TContainer importWithValueFunctor(const std::string &filename, const TFunctor &aFunctor, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
Aim: Functor allowing to rescale a value. Values of the initial scale [initMin,initMax] are rescaled ...
int main()
Definition testBits.cpp:56
bool testGenericReader()