DGtal  1.3.beta
Functions
testITKDicomReader.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "ConfigTest.h"
#include "DGtalCatch.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ImageContainerByITKImage.h"
#include "DGtal/io/readers/ITKDicomReader.h"
#include <itkGDCMSeriesFileNames.h>
Include dependency graph for testITKDicomReader.cpp:

Go to the source code of this file.

Functions

std::vector< std::string > getFirstDicomSerieFileNames (const std::string &path)
 
template<typename Image >
void testImportDICOM ()
 
template<typename PixelType >
void testSpatialInformation ()
 
 TEST_CASE ("Testing ITKReader")
 

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
Boris Mansencal (boris.nosp@m..man.nosp@m.senca.nosp@m.l@la.nosp@m.bri.f.nosp@m.r ) LaBRI (CNRS, UMR 5800, University of Bordeaux, Bordeaux-INP), France
Date
2019/02/05

Functions for testing class ITKDicomReader.

This file is part of the DGtal library.

Definition in file testITKDicomReader.cpp.

Function Documentation

◆ getFirstDicomSerieFileNames()

std::vector<std::string> getFirstDicomSerieFileNames ( const std::string &  path)

Definition at line 61 of file testITKDicomReader.cpp.

62 {
63  typedef itk::GDCMSeriesFileNames NamesGeneratorType;
64  NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
65  nameGenerator->SetUseSeriesDetails( true );
66  nameGenerator->SetDirectory( path );
67 
68  typedef itk::GDCMSeriesFileNames::SeriesUIDContainerType SeriesIdContainer;
69  const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
70 
71  if (! seriesUID.empty() )
72  {
73  return nameGenerator->GetFileNames( *(seriesUID.begin()) );
74  }
75  return std::vector<std::string>();
76 }

Referenced by testImportDICOM(), and testSpatialInformation().

◆ TEST_CASE()

TEST_CASE ( "Testing ITKReader )

Definition at line 128 of file testITKDicomReader.cpp.

129 {
130  // Default image selector = STLVector
131 
132  SECTION(
133  "Testing ITKDicomReader with 8 bits ImageContainerBySTLVector images" )
134  {
136  testImportDICOM<Image>();
137  }
138 
139  SECTION(
140  "Testing ITKDicomReader with 8 bits ImageContainerByITKImage images" )
141  {
143  testImportDICOM<Image>();
144  }
145 
146  SECTION(
147  "Testing ITKDicomReader with 16 bits ImageContainerBySTLVector images" )
148  {
150  testImportDICOM<Image>();
151  }
152 
153  SECTION(
154  "Testing ITKDicomReader with 16 bits ImageContainerByITKImage images" )
155  {
157  testImportDICOM<Image>();
158  }
159 
160 
161 
162  SECTION(
163  "Testing behavior of ITKDicomReader on empty filenames vector" )
164  {
166  std::vector<std::string> filenames;
167  bool caughtException = false;
168  try
169  {
171  }
172  catch(exception &)
173  {
174  caughtException = true;
175  trace.info() <<"Exception was correctly caught" << std::endl;
176  }
177  REQUIRE( caughtException == true);
178  }
179 
180  SECTION(
181  "Testing ITKDicomReader with 8 bits ImageContainerByITKImage images keeps spatial information" )
182  {
183  testSpatialInformation<unsigned char>();
184  }
185 
186  SECTION(
187  "Testing ITKDicomReader with 16 bits ImageContainerByITKImage images keeps spatial information" )
188  {
189  testSpatialInformation<int16_t>();
190  }
191 
192 
193 }

References DGtal::Trace::info(), REQUIRE(), SECTION(), and DGtal::trace.

◆ testImportDICOM()

template<typename Image >
void testImportDICOM ( )

Definition at line 81 of file testITKDicomReader.cpp.

82 {
83  std::vector<std::string> fileNames = getFirstDicomSerieFileNames( testPath + "samples/dicomSample" );
84 
85  Image image = ITKDicomReader<Image>::importDICOM( fileNames );
86 
87  unsigned int nbVal=0, nbPos = 0;
88  typename Image::ConstRange r = image.constRange();
89  for ( typename Image::ConstRange::ConstIterator it=r.begin(), itend=r.end() ; it != itend ; ++it )
90  {
91  ++nbVal;
92  if ( (*it) > 0 ) ++nbPos;
93  }
94 
95  REQUIRE( ( nbVal==2130048 && nbPos==296030 ) );
96 }

References getFirstDicomSerieFileNames(), and REQUIRE().

◆ testSpatialInformation()

template<typename PixelType >
void testSpatialInformation ( )

Definition at line 99 of file testITKDicomReader.cpp.

100 {
101  std::vector<std::string> fileNames = getFirstDicomSerieFileNames( testPath + "samples/dicomSample" );
102 
104  DGtalImage img = ITKDicomReader<DGtalImage>::importDICOM( fileNames );
105  typename DGtalImage::ITKImagePointer dgtal_itk = img.getITKImagePointer();
106 
107  typedef itk::Image<PixelType, 3> ItkImage;
108  typedef itk::ImageSeriesReader<ItkImage> ItkReader;
109  typename ItkReader::Pointer reader = ItkReader::New();
110  reader->SetFileNames( fileNames );
111 
112  reader->Update();
113 
114  typename ItkImage::Pointer itk = reader->GetOutput();
115 
116  INFO( "Checking spacing" )
117  REQUIRE( dgtal_itk->GetSpacing() == itk->GetSpacing() );
118  INFO( "Checking origin" )
119  REQUIRE( dgtal_itk->GetOrigin() == itk->GetOrigin() );
120  INFO( "Checking direction" )
121  REQUIRE( dgtal_itk->GetDirection() == itk->GetDirection() );
122 }

References getFirstDicomSerieFileNames(), and REQUIRE().

DGtal::SimpleRandomAccessConstRangeFromPoint
Aim: model of CConstBidirectionalRangeFromPoint that adapts any range of elements bounded by two iter...
Definition: SimpleRandomAccessConstRangeFromPoint.h:73
DGtal::ImageContainerByITKImage
Aim: implements a model of CImageContainer using a ITK Image.
Definition: ImageContainerByITKImage.h:93
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
getFirstDicomSerieFileNames
std::vector< std::string > getFirstDicomSerieFileNames(const std::string &path)
Definition: testITKDicomReader.cpp:61
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstIterator
std::vector< Value >::const_iterator ConstIterator
Definition: ImageContainerBySTLVector.h:265
REQUIRE
REQUIRE(domain.isInside(aPoint))
DGtal::Trace::info
std::ostream & info()
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
SECTION
SECTION("Testing constant forward iterators")
Definition: testSimpleRandomAccessRangeFromPoint.cpp:66
DGtal::ITKDicomReader
Aim: Import a 2D/3D DICOM Image from file series.
Definition: ITKDicomReader.h:81