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"
41 using namespace DGtal;
53 template <
typename PixelType>
60 typename DGtalImage::ITKImagePointer dgtal_itk = img.getITKImagePointer();
63 typedef itk::Image<PixelType, 3> ItkImage;
64 typedef itk::ImageFileReader<ItkImage> ReaderType;
65 typename ReaderType::Pointer reader = ReaderType::New();
66 reader->SetFileName(filename);
70 typename ItkImage::Pointer itk = reader->GetOutput();
72 INFO(
"Checking spacing" )
73 REQUIRE( dgtal_itk->GetSpacing() == itk->GetSpacing() );
74 INFO(
"Checking origin" )
75 REQUIRE( dgtal_itk->GetOrigin() == itk->GetOrigin() );
76 INFO(
"Checking direction" )
77 REQUIRE( dgtal_itk->GetDirection() == itk->GetDirection() );
90 "Testing feature io/readers of ITKReader with 16 bits (uint16) images" )
93 testPath +
"samples/lobsterCroped16b.mhd" );
98 "Testing feature io/readers of ITKReader with rescaled 16 bits (uint16) "
102 RescalFCT resc = RescalFCT( 0, 65535, 0, 255 );
104 testPath +
"samples/lobsterCroped16b.mhd", resc );
108 "Testing behavior of ITKReader on non existent image file" )
110 bool caughtException =
false;
111 const std::string filename = testPath +
"samples/null.mhd";
118 caughtException =
true;
119 trace.
info() <<
"Exception was correctly caught" << std::endl;
121 REQUIRE( caughtException ==
true);
125 "Checking spatial information when loading through DGtal" )
127 testSpatialInformation<int16_t>(testPath +
"samples/lobsterCroped16b.mhd" );
128 testSpatialInformation<int16_t>(testPath +
"samples/lobsterCropedB16b.mhd" );
132 "Checking import with/without shifted domain")
143 auto i = 101*pTarget[1]+pTarget[0]+pTarget[2]*101*101;
144 trace.
info() <<
"value:" << *(imNonShifted.range().begin()+i);
145 REQUIRE( ( *(imNonShifted.range().begin()+i) == *(imShifted.range().begin()+i ) ));
146 REQUIRE( ( *(imNonShifted.range().begin()+i) == 68 ));
Aim: implements a model of CImageContainer using a ITK Image.
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Import a 2D/3D Image using the ITK formats.
static Image importITK(const std::string &filename, const TFunctor &aFunctor=TFunctor(), bool shiftDomainUsingOrigin=true)
Aim: Define a simple functor using the static cast operator.
Aim: Functor allowing to rescale a value. Values of the initial scale [initMin,initMax] are rescaled ...
void testSpatialInformation(const std::string &filename)
TEST_CASE("Testing ITKReader")
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))