DGtal  0.9.3
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 141 of file testITKio.cpp.

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

142 {
143  bool res = testITKio(); // && ... other tests
144  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
145  return res ? 0 : 1;
146 }
Trace trace
Definition: Common.h:137
std::ostream & emphase()
bool testITKio()
Definition: testITKio.cpp:101

◆ test_image()

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

Definition at line 49 of file testITKio.cpp.

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

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  for (typename Domain::Size kk=0; kk<domain.size(); kk++)
69  values.push_back(rand());
70 
71  std::copy(values.begin(), values.end(), image.range().outputIterator());
72 
73  trace.info() << image << endl;
74  trace.info() << "writing " << filename << endl;
75  if (!ITKWriter<Image>::exportITK(filename, image)) return false;
76 
77  trace.info() << "reading " << filename << endl;
78  Image image_read = ITKReader<Image>::importITK(filename);
79  trace.info() << image_read << endl;
80 
81  if (image_read.domain().lowerBound() != image.domain().lowerBound()) trace.warning() << "lowerBound mismatch!!" << endl;
82  if (image_read.domain().upperBound() != image.domain().upperBound()) trace.warning() << "upperBound mismatch!!" << endl;
83 
84  typename Image::ConstRange::ConstIterator iter_read = image_read.constRange().begin();
85  typename Image::ConstRange::ConstIterator iter_read_end = image_read.constRange().end();
86  typename Values::const_iterator iter_value = values.begin();
87  typename Values::const_iterator iter_value_end = values.end();
88  while (iter_value!=iter_value_end && iter_read!=iter_read_end)
89  {
90  if ((*iter_read)!=(*iter_value)) {
91  trace.error() << "values mismatch" << endl;
92  return false;
93  }
94  iter_value++;
95  iter_read++;
96  }
97 
98  return true;
99 }
HyperRectDomain< Space > Domain
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
const Domain domain(Point(1, 2), Point(6, 5))
Trace trace
Definition: Common.h:137
ConstRange constRange() const
Definition: Image.h:203
Aim: Import a 2D/3D Image using the ITK formats.
Definition: ITKReader.h:60
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

◆ testITKio()

bool testITKio ( )

Definition at line 101 of file testITKio.cpp.

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

Referenced by main().

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