ITK/VTK对DICOM文件的读取
发布时间
阅读量:
阅读量
前言
ITK框架中对DICOM文件进行读取操作时采用的是GDCM库,在VTK框架中则采用的是VTK DICOM File Reader。
1 ITK对DICOM的读取
1.1 单个DICOM文件
在ITK中,读取DICOM文件的程序示例如下:
typedef signed short InputPixelType;
const unsigned int InputDimension = 2;
typedef itk::Image< InputPixelType, InputDimension > InputImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
reader->SetImageIO( gdcmImageIO );
try
{
reader->Update();
}
catch (itk::ExceptionObject & e)
{
std::cerr << "exception in file reader " << std::endl;
std::cerr << e << std::endl;
return EXIT_FAILURE;
}
1.2 DICOM序列的读取
在ITK中,读取DICOM文件序列的程序如下:
const unsigned int InputDimension = 3;
const unsigned int OutputDimension = 2;
typedef signed short PixelType;
typedef itk::Image< PixelType, InputDimension >
InputImageType;
typedef itk::Image< PixelType, OutputDimension >
OutputImageType;
typedef itk::ImageSeriesReader< InputImageType >
ReaderType;
typedef itk::GDCMImageIO
ImageIOType;
typedef itk::GDCMSeriesFileNames
InputNamesGeneratorType;
typedef itk::NumericSeriesFileNames
OutputNamesGeneratorType;
typedef itk::IdentityTransform< double, InputDimension >
TransformType;
typedef itk::LinearInterpolateImageFunction< InputImageType, double >
InterpolatorType;
typedef itk::ResampleImageFilter< InputImageType, InputImageType >
ResampleFilterType;
#if ( ( ITK_VERSION_MAJOR == 4 ) && ( ITK_VERSION_MINOR < 6 ) )
typedef itk::ShiftScaleImageFilter< InputImageType, InputImageType >
ShiftScaleType;
#endif
typedef itk::ImageSeriesWriter< InputImageType, OutputImageType >
SeriesWriterType;
// 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;
}
2 VTK对DICOM文件读取
<pre name="code" class="cpp"> // Read all the DICOM files in the specified directory.
vtkSmartPointer<vtkDICOMImageReader> reader =
vtkSmartPointer<vtkDICOMImageReader>::New();
reader->SetDirectoryName(folder.c_str());
reader->Update();
// Visualize
vtkSmartPointer<vtkImageViewer2> imageViewer =
vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection(reader->GetOutputPort());
imageViewer->SetSliceIndex(1);
参考文献:
全部评论 (0)
还没有任何评论哟~
