32#include "DGtal/images/ImageContainerBySTLVector.h"
33#include "DGtal/images/ImageContainerByITKImage.h"
34#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/io/readers/DicomReader.h"
37#include "ConfigTest.h"
52template <
typename Image3D>
55 const std::string filename = testPath +
"samples/dicomSample/1629.dcm";
60 unsigned int nbVal=0, nbPos = 0;
61 typename Image3D::ConstRange r = image.constRange();
62 for (
typename Image3D::ConstRange::ConstIterator it=r.begin(), itend=r.end() ; it != itend ; ++it )
65 if ( (*it) > 0 ) nbPos++;
68 trace.
info() <<
"Number of points with (val>0) = " << nbVal << endl;
70 return nbVal==2130048 && nbPos==296030;
74std::vector<std::string>
77 typedef itk::GDCMSeriesFileNames NamesGeneratorType;
78 NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
79 nameGenerator->SetUseSeriesDetails(
true );
80 nameGenerator->SetDirectory( path );
82 typedef itk::GDCMSeriesFileNames::SeriesUIDContainerType SeriesIdContainer;
83 const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
85 if (! seriesUID.empty() )
87 return nameGenerator->GetFileNames( *(seriesUID.begin()) );
89 return std::vector<std::string>();
92template <
typename Image3D>
95 const std::string path = testPath +
"samples/dicomSample";
101 unsigned int nbVal=0, nbPos = 0;
102 typename Image3D::ConstRange r = image.constRange();
103 for (
typename Image3D::ConstRange::ConstIterator it=r.begin(), itend=r.end() ; it != itend ; ++it )
106 if ( (*it) > 0 ) nbPos++;
109 trace.
info() <<
"Number of points with (val>0) = " << nbVal << endl;
111 return nbVal==2130048 && nbPos==296030;
115template <
typename PixelType>
118 const std::string path = testPath +
"samples/dicomSample";
124 typename Image3D::ITKImagePointer dgtal_itk = image.getITKImagePointer();
126 typedef itk::Image<PixelType, 3> ItkImage;
127 typedef itk::ImageSeriesReader<ItkImage> ItkReader;
128 typename ItkReader::Pointer reader = ItkReader::New();
129 reader->SetFileNames( fileNames );
133 typename ItkImage::Pointer itk = reader->GetOutput();
135 const bool ok1 = ( dgtal_itk->GetSpacing() == itk->GetSpacing() );
136 const bool ok2 = ( dgtal_itk->GetOrigin() == itk->GetOrigin() );
137 const bool ok3 = ( dgtal_itk->GetDirection() == itk->GetDirection() );
138 return ok1 && ok2 && ok3;
147 std::string filename = testPath +
"samples/null.dcm";
151 catch(exception& e) {
152 trace.
info() <<
"Exception catched. Message : " << e.what()<<endl;
164int main(
int argc,
char** argv )
168 for (
int i = 0; i < argc; ++i )
172 bool res = testDicomReader<ImageContainerBySTLVector<Z3i::Domain, unsigned char> >()
174 && testDicomReader<ImageContainerByITKImage<Z3i::Domain, unsigned char> >()
176 && testDicomReaderFromDirectory<ImageContainerBySTLVector<Z3i::Domain, unsigned char> >()
178 && testSpatialInformation<unsigned char>()
179 && testSpatialInformation<uint16_t>()
181 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: implements a model of CImageContainer using a ITK Image.
void beginBlock(const std::string &keyword="")
DGtal is the top-level namespace which contains all DGtal functions and types.
static ImageContainer importDicomSeries(const std::vector< std::string > &filenames, const Functor &aFunctor=Functor())
static ImageContainer importDicom(const std::string &aFilename, const Functor &aFunctor=Functor())
bool testSpatialInformation()
bool testDicomReaderFromDirectory()
static std::vector< std::string > getFirstDicomSerieFileNames(const std::string &path)