什么是DICOM
DICOM(Digital imaging and Communication in Medicine),医学数字成像与通信,它是一个国际标准(ISO 12052),由美国放射学院(ACR)和国家电气制造协会(NEMA)在1970年代共同制定,旨在统一格式,解决医学图像的处理、存储、打印以及传输。
GDCM
GDCM(Grassroots DICOM),开源库,DICOM标准的一种实现。ITK的DICOM设施,就是由它提供的。对应itk::GDCMImageIO类名。
读取单个DICOM数据
定义数据类型
1 2 3 4
| using InputPixelType = signed short; constexpr unsigned int InputDimension = 2;
using InputImageType = itk::Image< InputPixelType, InputDimension >;
|
初始化GDCM接口
1 2
| using ImageIOType = itk::GDCMImageIO; ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
|
设置ImageFileReader
1 2 3 4
| using ReaderType = itk::ImageFileReader< InputImageType >; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); reader->SetImageIO(gdcmImageIO);
|
触发读取
VTK渲染
1 2 3
| QuickView viewer; viewer.AddImage(reader->GetOutput()); viewer.Visualize();
|
ReadDICOMImage.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
| #include "itkImageFileReader.h" #include "itkGDCMImageIO.h"
#include "QuickView.h"
int main(int argc, char *argv[]) { if (argc < 2) { std::cerr << "Usage: " << argv[0] << " DicomImage" << std::endl; return EXIT_FAILURE; }
using InputPixelType = signed short; constexpr unsigned int InputDimension = 2;
using InputImageType = itk::Image< InputPixelType, InputDimension >;
using ImageIOType = itk::GDCMImageIO; ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
using ReaderType = itk::ImageFileReader< InputImageType >; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); reader->SetImageIO(gdcmImageIO);
try { reader->Update(); } catch ( itk::ExceptionObject &ex) { std::cerr << "exception in file reader " << std::endl; std::cerr << ex << std::endl; return EXIT_FAILURE; }
QuickView viewer; viewer.AddImage(reader->GetOutput()); viewer.Visualize();
return EXIT_SUCCESS; }
|
CMakeLists.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| cmake_minimum_required(VERSION 2.8) project(ReadDICOMImage) find_package(ITK REQUIRED) include(${ITK_USE_FILE}) if (ITKVtkGlue_LOADED) find_package(VTK REQUIRED) include(${VTK_USE_FILE}) else() find_package(ItkVtkGlue REQUIRED) include(${ItkVtkGlue_USE_FILE}) set(Glue ItkVtkGlue) endif() add_executable(ReadDICOMImage MACOSX_BUNDLE ReadDICOMImage.cxx) target_link_libraries(ReadDICOMImage ${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES})
|
Example Download
Reference
Examples/IO/DicomImageReadWrite.cxx