DGtal  1.0.0
testITKReader.cpp
Go to the documentation of this file.
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "ConfigTest.h"
34 #include "DGtalCatch.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/images/ImageContainerBySTLVector.h"
37 #include "DGtal/io/readers/ITKReader.h"
39 
40 using namespace std;
41 using namespace DGtal;
42 
44 // Functions for testing class ITKReader.
46 
47 TEST_CASE( "Testing ITKReader" )
48 {
49  // Default image selector = STLVector
52 
53  SECTION(
54  "Testing feature io/readers of ITKReader with 16 bits (unit16) images" )
55  {
56  Image3D16b im = ITKReader<Image3D16b>::importITK(
57  testPath + "samples/lobsterCroped16b.mhd" );
58  REQUIRE( ( im( Z3i::Point( 35, 29, 3 ) ) == 60400 ) );
59  }
60 
61  SECTION(
62  "Testing feature io/readers of ITKReader with rescaled 16 bits (unit16) "
63  "images" )
64  {
66  RescalFCT resc = RescalFCT( 0, 65535, 0, 255 );
67  Image3DUC im = ITKReader<Image3DUC>::importITK(
68  testPath + "samples/lobsterCroped16b.mhd", resc );
69  REQUIRE( ( im( Z3i::Point( 35, 29, 3 ) ) == resc( 60400 ) ) );
70  }
71  SECTION(
72  "Testing behavior of ITKReader on non existent image file" )
73  {
74  bool caughtException = false;
75  const std::string filename = testPath + "samples/null.mhd"; //non existent file
76  try
77  {
78  Image3DUC im = ITKReader<Image3DUC>::importITK(filename);
79  }
80  catch(exception &)
81  {
82  caughtException = true;
83  trace.info() <<"Exception was correctly caught" << std::endl;
84  }
85  REQUIRE( caughtException == true);
86  }
87 
88 
89 }
90 
Trace trace
Definition: Common.h:144
REQUIRE(domain.isInside(aPoint))
Aim: Import a 2D/3D Image using the ITK formats.
Definition: ITKReader.h:78
TEST_CASE("Testing ITKReader")
Aim: Functor allowing to rescale a value. Values of the initial scale [initMin,initMax] are rescaled ...
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
SECTION("Testing constant forward iterators")