DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testITKDicomReader.cpp
Go to the documentation of this file.
1
16
29
31
#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/images/ImageContainerByITKImage.h"
38
#include "DGtal/io/readers/ITKDicomReader.h"
39
// Required ITK files to read series DICOM files
40
// DGtal must be compiled with " -DDGTAL_WITH_ITK=true" option
41
#if defined(__clang__)
42
#pragma clang diagnostic push
43
#pragma clang diagnostic ignored "-Wdocumentation"
44
#endif
45
#include <itkGDCMSeriesFileNames.h>
46
#if defined(__clang__)
47
#pragma clang diagnostic pop
48
#endif
49
50
52
53
using namespace
std
;
54
using namespace
DGtal
;
55
57
// Functions for testing class ITKReader.
59
60
std::vector<std::string>
61
getFirstDicomSerieFileNames
(
const
std::string &path)
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
}
77
78
79
template
<
typename
Image>
80
void
81
testImportDICOM
()
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
}
97
98
template
<
typename
PixelType>
99
void
testSpatialInformation
()
100
{
101
std::vector<std::string> fileNames =
getFirstDicomSerieFileNames
( testPath +
"samples/dicomSample"
);
102
103
typedef
ImageContainerByITKImage<Z3i::Domain, PixelType>
DGtalImage;
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
}
123
124
125
126
127
128
TEST_CASE
(
"Testing ITKReader"
)
129
{
130
// Default image selector = STLVector
131
132
SECTION
(
133
"Testing ITKDicomReader with 8 bits ImageContainerBySTLVector images"
)
134
{
135
typedef
ImageContainerBySTLVector<Z3i::Domain, unsigned char>
Image
;
136
testImportDICOM<Image>
();
137
}
138
139
SECTION
(
140
"Testing ITKDicomReader with 8 bits ImageContainerByITKImage images"
)
141
{
142
typedef
ImageContainerByITKImage<Z3i::Domain, unsigned char>
Image
;
143
testImportDICOM<Image>
();
144
}
145
146
SECTION
(
147
"Testing ITKDicomReader with 16 bits ImageContainerBySTLVector images"
)
148
{
149
typedef
ImageContainerBySTLVector<Z3i::Domain, uint16_t>
Image
;
150
testImportDICOM<Image>
();
151
}
152
153
SECTION
(
154
"Testing ITKDicomReader with 16 bits ImageContainerByITKImage images"
)
155
{
156
typedef
ImageContainerByITKImage<Z3i::Domain, uint16_t>
Image
;
157
testImportDICOM<Image>
();
158
}
159
160
161
162
SECTION
(
163
"Testing behavior of ITKDicomReader on empty filenames vector"
)
164
{
165
typedef
ImageContainerBySTLVector<Z3i::Domain, unsigned char>
Image
;
166
std::vector<std::string> filenames;
167
bool
caughtException =
false
;
168
try
169
{
170
Image
im =
ITKDicomReader<Image>::importDICOM
(filenames);
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
}
194
DGtal::ImageContainerByITKImage
Aim: implements a model of CImageContainer using a ITK Image.
Definition
ImageContainerByITKImage.h:94
DGtal::ImageContainerBySTLVector
Definition
ImageContainerBySTLVector.h:127
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstIterator
std::vector< Value >::const_iterator ConstIterator
Definition
ImageContainerBySTLVector.h:265
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstRange
SimpleRandomAccessConstRangeFromPoint< ConstIterator, DistanceFunctorFromPoint< Self > > ConstRange
Definition
ImageContainerBySTLVector.h:274
DGtal::Image
Aim: implements association between points lying in a digital domain and values.
Definition
Image.h:70
DGtal::Image::constRange
ConstRange constRange() const
Definition
Image.h:203
DGtal::SimpleRandomAccessConstRangeFromPoint::begin
ConstIterator begin() const
Definition
SimpleRandomAccessConstRangeFromPoint.h:192
DGtal::SimpleRandomAccessConstRangeFromPoint::end
ConstIterator end() const
Definition
SimpleRandomAccessConstRangeFromPoint.h:212
DGtal::Trace::info
std::ostream & info()
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::ITKDicomReader::importDICOM
static Image importDICOM(const std::vector< std::string > &filenames, const TFunctor &aFunctor=TFunctor())
TEST_CASE
TEST_CASE("int container traits", "[int][traits]")
Definition
testContainerTraits.cpp:53
testSpatialInformation
bool testSpatialInformation()
Definition
testDicomReader.cpp:116
getFirstDicomSerieFileNames
std::vector< std::string > getFirstDicomSerieFileNames(const std::string &path)
Definition
testITKDicomReader.cpp:61
testImportDICOM
void testImportDICOM()
Definition
testITKDicomReader.cpp:81
image
Image image(domain)
SECTION
SECTION("Testing constant forward iterators")
Definition
testSimpleRandomAccessRangeFromPoint.cpp:66
REQUIRE
REQUIRE(domain.isInside(aPoint))
tests
io
readers
testITKDicomReader.cpp
Generated on
for DGtal by
1.18.0