31 #include "ConfigTest.h"
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/images/ImageSelector.h"
35 #include "DGtal/images/CImage.h"
36 #include "DGtal/io/writers/ITKWriter.h"
37 #include "DGtal/io/readers/ITKReader.h"
38 using namespace DGtal;
47 template <
typename Image>
66 typedef typename std::vector<typename Image::Value> Values;
70 values.push_back(rand());
72 std::copy(values.begin(), values.end(), image.range().outputIterator());
75 trace.
info() <<
"writing " << filename << endl;
78 trace.
info() <<
"reading " << filename << endl;
82 if (image_read.
domain().lowerBound() != image.domain().lowerBound())
trace.
warning() <<
"lowerBound mismatch!!" << endl;
83 if (image_read.
domain().upperBound() != image.domain().upperBound())
trace.
warning() <<
"upperBound mismatch!!" << endl;
87 typename Values::const_iterator iter_value = values.begin();
88 typename Values::const_iterator iter_value_end = values.end();
89 while (iter_value!=iter_value_end && iter_read!=iter_read_end)
91 if ((*iter_read)!=(*iter_value)) {
108 Image3DITK copy(input.domain());
109 Image3DITK::ImageSpacing s (0.2, 0.3, 0.4);
110 trace.
info() <<
"setting image spacing to 0.2, 0.3, 0.4" << std::endl;
111 copy.setImageSpacing(s);
112 for (
auto p: input.domain() ) {copy.setValue(p, input(p));}
115 s = check.getImageSpacing();
116 trace.
info() <<
"reading image spacing after write (should be 0.2, 0.3, 0.4)" << std::endl;
117 trace.
info() <<
"spacing: " << s[0] <<
" " << s[1] <<
" " << s[2] << std::endl;
118 Image3D img (input.domain());
121 auto s3 = check3.getImageSpacing();
122 trace.
info() <<
"reading image spacing after export with spacing mention (should be 0.8, 0.9, 1.0)" << std::endl;
123 trace.
info() <<
"spacing: " << s3[0] <<
" " << s3[1] <<
" " << s3[2] << std::endl;
127 Image2DITK copy2(input2.domain());
128 Image2DITK::ImageSpacing s2 (0.2, 0.3);
129 trace.
info() <<
"setting image spacing to 0.2, 0.3" << std::endl;
130 copy2.setImageSpacing(s2);
131 for (
auto p: input2.domain() ) {copy2.setValue(p, input2(p));}
134 s2 = check2.getImageSpacing();
135 trace.
info() <<
"reading image spacing after write (should be 0.2, 0.3)" << std::endl;
136 trace.
info() <<
"spacing: " << s2[0] <<
" " << s2[1] << std::endl;
139 return s[0] == 0.2 && s[1] == 0.3 && s[2] == 0.4 &&
140 s2[0] == 0.2 && s2[1] == 0.3 &&
141 s3[0] == 0.8 && s3[1] == 0.9 && s3[2] == 1.0;
147 unsigned int nbok = 0;
152 nbok += test_image<ImageSelector<Z2i::Domain, int>::Type>(
"image_2d_int.mha");
153 nbok += test_image<ImageSelector<Z2i::Domain, bool>::Type>(
"image_2d_bool.mha");
154 nbok += test_image<ImageSelector<Z2i::Domain, unsigned int>::Type>(
"image_2d_unsigned_int.mha");
155 nbok += test_image<ImageSelector<Z2i::Domain, unsigned char>::Type>(
"image_2d_unsigned_char.mha");
156 nbok += test_image<ImageSelector<Z2i::Domain, unsigned long>::Type>(
"image_2d_unsigned_long.mha");
157 nbok += test_image<ImageSelector<Z2i::Domain, long>::Type>(
"image_2d_long.mha");
158 nbok += test_image<ImageSelector<Z2i::Domain, float>::Type>(
"image_2d_float.mha");
159 nbok += test_image<ImageSelector<Z2i::Domain, double>::Type>(
"image_2d_double.mha");
164 nbok += test_image<ImageSelector<Z3i::Domain, int>::Type>(
"image_3d_int.mha");
165 nbok += test_image<ImageSelector<Z3i::Domain, bool>::Type>(
"image_3d_bool.mha");
166 nbok += test_image<ImageSelector<Z3i::Domain, unsigned int>::Type>(
"image_3d_unsigned_int.mha");
167 nbok += test_image<ImageSelector<Z3i::Domain, unsigned char>::Type>(
"image_3d_unsigned_char.mha");
168 nbok += test_image<ImageSelector<Z3i::Domain, unsigned long>::Type>(
"image_3d_unsigned_long.mha");
169 nbok += test_image<ImageSelector<Z3i::Domain, long>::Type>(
"image_3d_long.mha");
170 nbok += test_image<ImageSelector<Z3i::Domain, float>::Type>(
"image_3d_float.mha");
171 nbok += test_image<ImageSelector<Z3i::Domain, double>::Type>(
"image_3d_double.mha");
176 nbok += test_image<ImageSelector<Z2i::Domain, unsigned char>::Type>(
"image_unsigned_char.jpg"); nb--;
177 nbok += test_image<ImageSelector<Z2i::Domain, unsigned char>::Type>(
"image_unsigned_char.png");
178 nbok += test_image<ImageSelector<Z2i::Domain, unsigned char>::Type>(
"image_unsigned_char.bmp");
181 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " << endl;
195 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: implements a model of CImageContainer using a ITK Image.
std::vector< Value >::const_iterator ConstIterator
Domain::Dimension Dimension
Aim: implements association bewteen points lying in a digital domain and values.
const Domain & domain() const
ConstRange constRange() const
ConstIterator begin() const
ConstIterator end() const
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
static Image importITK(const std::string &filename, const TFunctor &aFunctor=TFunctor(), bool shiftDomainUsingOrigin=true)
Export a 2D/3D Image using the ITK formats.
static bool exportITK(const std::string &filename, const Image &aImage, const Functor &aFunctor=Functor())
Aim: Defines the concept describing a read/write image, having an output iterator.
bool test_image(const string &filename)
HyperRectDomain< Space > Domain