-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadDCMTK.cxx
105 lines (81 loc) · 2.57 KB
/
ReadDCMTK.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// from https://itk.org/Wiki/ITK/Examples/DICOM/ResampleDICOM
#include "itkVersion.h"
#include "itkImage.h"
#include "itkMinimumMaximumImageFilter.h"
#include "itkDCMTKImageIO.h"
#include "itkDCMTKSeriesFileNames.h"
#include "itkNumericSeriesFileNames.h"
#include "itkImageSeriesReader.h"
#include "itkImageFileWriter.h"
#include "itkResampleImageFilter.h"
#if ( ( ITK_VERSION_MAJOR == 4 ) && ( ITK_VERSION_MINOR < 6 ) )
#include "itkShiftScaleImageFilter.h"
#endif
#include "itkIdentityTransform.h"
#include "itkLinearInterpolateImageFunction.h"
#include <itksys/SystemTools.hxx>
#if ITK_VERSION_MAJOR >= 4
#include "gdcmUIDGenerator.h"
#else
#include "gdcm/src/gdcmFile.h"
#include "gdcm/src/gdcmUtil.h"
#endif
#include <string>
#include <sstream>
static void CopyDictionary (itk::MetaDataDictionary &fromDict,
itk::MetaDataDictionary &toDict);
int main( int argc, char* argv[] )
{
// Validate input parameters
if( argc < 3 )
{
std::cerr << "Usage: "
<< argv[0]
<< " InputDicomDirectory OutputFile"
<< std::endl;
return EXIT_FAILURE;
}
const unsigned int InputDimension = 3;
typedef signed short PixelType;
typedef itk::Image< PixelType, InputDimension >
InputImageType;
typedef itk::ImageSeriesReader< InputImageType >
ReaderType;
typedef itk::ImageFileWriter<InputImageType>
WriterType;
typedef itk::DCMTKImageIO
ImageIOType;
typedef itk::DCMTKSeriesFileNames
InputNamesGeneratorType;
typedef itk::NumericSeriesFileNames
OutputNamesGeneratorType;
#if ( ( ITK_VERSION_MAJOR == 4 ) && ( ITK_VERSION_MINOR < 6 ) )
typedef itk::ShiftScaleImageFilter< InputImageType, InputImageType >
ShiftScaleType;
#endif
////////////////////////////////////////////////
// 1) Read the input series
ImageIOType::Pointer gdcmIO = ImageIOType::New();
InputNamesGeneratorType::Pointer inputNames = InputNamesGeneratorType::New();
inputNames->SetInputDirectory( argv[1] );
const ReaderType::FileNamesContainer & filenames =
inputNames->GetInputFileNames();
ReaderType::Pointer reader = ReaderType::New();
reader->SetImageIO( gdcmIO );
reader->SetFileNames( filenames );
try
{
reader->Update();
}
catch (itk::ExceptionObject &excp)
{
std::cerr << "Exception thrown while reading the series" << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
WriterType::Pointer writer = WriterType::New();
writer->SetInput(reader->GetOutput());
writer->SetFileName(argv[2]);
writer->Update();
return 0;
}