DGtal  1.0.0
Functions
testITKio.cpp File Reference
#include "ConfigTest.h"
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/CImage.h"
#include "DGtal/io/writers/ITKWriter.h"
#include "DGtal/io/readers/ITKReader.h"
#include <string>
Include dependency graph for testITKio.cpp:

Go to the source code of this file.

Functions

template<typename Image >
bool test_image (const string &filename)
 
bool testITKio ()
 
int main (int, char **)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Pierre Gueth (pierr.nosp@m.e.gu.nosp@m.eth@g.nosp@m.mail.nosp@m..com ) Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2013/10/28

Functions for testing class ITKio.

This file is part of the DGtal library.

Definition in file testITKio.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 146 of file testITKio.cpp.

147 {
148  bool res = testITKio(); // && ... other tests
149  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
150  return res ? 0 : 1;
151 }
Trace trace
Definition: Common.h:144
std::ostream & emphase()
bool testITKio()
Definition: testITKio.cpp:102

References DGtal::Trace::emphase(), testITKio(), and DGtal::trace.

◆ test_image()

template<typename Image >
bool test_image ( const string &  filename)

Definition at line 49 of file testITKio.cpp.

50 {
51  BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
52 
53  typedef typename Image::Domain::Point Point;
54  Point point0;
55  Point point1;
56  for (typename Image::Domain::Dimension kk=0; kk<Image::Domain::dimension; kk++)
57  {
58  point0[kk] = 5;
59  point1[kk] = 10;
60  }
61 
62  typedef typename Image::Domain Domain;
63  const Domain domain(point0, point1);
65 
66  typedef typename std::vector<typename Image::Value> Values;
67  Values values;
68  values.reserve(domain.size());
69  for (typename Domain::Size kk=0; kk<domain.size(); kk++)
70  values.push_back(rand());
71 
72  std::copy(values.begin(), values.end(), image.range().outputIterator());
73 
74  trace.info() << image << endl;
75  trace.info() << "writing " << filename << endl;
76  if (!ITKWriter<Image>::exportITK(filename, image)) return false;
77 
78  trace.info() << "reading " << filename << endl;
79  Image image_read = ITKReader<Image>::importITK(filename);
80  trace.info() << image_read << endl;
81 
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;
84 
85  typename Image::ConstRange::ConstIterator iter_read = image_read.constRange().begin();
86  typename Image::ConstRange::ConstIterator iter_read_end = image_read.constRange().end();
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)
90  {
91  if ((*iter_read)!=(*iter_value)) {
92  trace.error() << "values mismatch" << endl;
93  return false;
94  }
95  iter_value++;
96  iter_read++;
97  }
98 
99  return true;
100 }
HyperRectDomain< Space > Domain
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
Trace trace
Definition: Common.h:144
Domain domain
ConstRange constRange() const
Definition: Image.h:203
Aim: Import a 2D/3D Image using the ITK formats.
Definition: ITKReader.h:78
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & warning()
std::ostream & info()
const Domain & domain() const
Definition: Image.h:192
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:102
std::ostream & error()
Image image(domain)
Export a 2D/3D Image using the ITK formats.
Definition: ITKWriter.h:63

References DGtal::Image< TImageContainer >::constRange(), domain, DGtal::Image< TImageContainer >::domain(), DGtal::Trace::error(), image(), DGtal::ITKReader< TImage >::importITK(), DGtal::Trace::info(), DGtal::HyperRectDomain< TSpace >::size(), DGtal::trace, and DGtal::Trace::warning().

◆ testITKio()

bool testITKio ( )

Definition at line 102 of file testITKio.cpp.

103 {
104  unsigned int nbok = 0;
105  unsigned int nb = 0;
106 
107  nb += 8;
108  trace.beginBlock ( "Testing 2D ITK image value types ..." );
109  nbok += test_image<ImageSelector<Z2i::Domain, int>::Type>("image_2d_int.mha");
110  nbok += test_image<ImageSelector<Z2i::Domain, bool>::Type>("image_2d_bool.mha");
111  nbok += test_image<ImageSelector<Z2i::Domain, unsigned int>::Type>("image_2d_unsigned_int.mha");
112  nbok += test_image<ImageSelector<Z2i::Domain, unsigned char>::Type>("image_2d_unsigned_char.mha");
113  nbok += test_image<ImageSelector<Z2i::Domain, unsigned long>::Type>("image_2d_unsigned_long.mha");
114  nbok += test_image<ImageSelector<Z2i::Domain, long>::Type>("image_2d_long.mha");
115  nbok += test_image<ImageSelector<Z2i::Domain, float>::Type>("image_2d_float.mha");
116  nbok += test_image<ImageSelector<Z2i::Domain, double>::Type>("image_2d_double.mha");
117  trace.endBlock();
118 
119  nb += 8;
120  trace.beginBlock ( "Testing 3D ITK image value types ..." );
121  nbok += test_image<ImageSelector<Z3i::Domain, int>::Type>("image_3d_int.mha");
122  nbok += test_image<ImageSelector<Z3i::Domain, bool>::Type>("image_3d_bool.mha");
123  nbok += test_image<ImageSelector<Z3i::Domain, unsigned int>::Type>("image_3d_unsigned_int.mha");
124  nbok += test_image<ImageSelector<Z3i::Domain, unsigned char>::Type>("image_3d_unsigned_char.mha");
125  nbok += test_image<ImageSelector<Z3i::Domain, unsigned long>::Type>("image_3d_unsigned_long.mha");
126  nbok += test_image<ImageSelector<Z3i::Domain, long>::Type>("image_3d_long.mha");
127  nbok += test_image<ImageSelector<Z3i::Domain, float>::Type>("image_3d_float.mha");
128  nbok += test_image<ImageSelector<Z3i::Domain, double>::Type>("image_3d_double.mha");
129  trace.endBlock();
130 
131  nb += 3;
132  trace.beginBlock ( "Testing 2D ITK image formats ..." );
133  nbok += test_image<ImageSelector<Z2i::Domain, unsigned char>::Type>("image_unsigned_char.jpg"); nb--; // jpg is lossy
134  nbok += test_image<ImageSelector<Z2i::Domain, unsigned char>::Type>("image_unsigned_char.png");
135  nbok += test_image<ImageSelector<Z2i::Domain, unsigned char>::Type>("image_unsigned_char.bmp");
136  trace.endBlock();
137 
138  trace.info() << "(" << nbok << "/" << nb << ") " << endl;
139 
140  return nbok == nb;
141 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:144
double endBlock()
std::ostream & info()

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().