ITK-读取系列DICOM并打印tags
程序员文章站
2022-04-01 07:57:32
...
#include "itkImageSeriesReader.h"
#include "itkGDCMImageIO.h"
#include "itkGDCMSeriesFileNames.h"
int main(int argc, char *argv[]) {
typedef signed short PixelType;
const unsigned int Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageSeriesReader< ImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer dicomIO = ImageIOType::New();
reader->SetImageIO(dicomIO);
typedef itk::GDCMSeriesFileNames NamesGeneratorType;
NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
nameGenerator->SetInputDirectory("../data/CT/CTP-dicom/17380000");
typedef std::vector<std::string> FileNamesContainer;
FileNamesContainer fileNames = nameGenerator->GetInputFileNames();
reader->SetFileNames(fileNames);
try {
reader->Update();
} catch(itk::ExceptionObject &ex) {
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
typedef itk::MetaDataDictionary DictionaryType;
const DictionaryType &dictionary = dicomIO->GetMetaDataDictionary();
typedef itk::MetaDataObject< std::string > MetaDataStringType;
DictionaryType::ConstIterator itr = dictionary.Begin();
DictionaryType::ConstIterator end = dictionary.End();
while(itr != end) {
itk::MetaDataObjectBase::Pointer entry = itr->second;
MetaDataStringType::Pointer entryvalue =
dynamic_cast<MetaDataStringType *>(entry.GetPointer());
if(entryvalue) {
std::string tagkey = itr->first;
std::string tagvalue = entryvalue->GetMetaDataObjectValue();
std::cout << tagkey << " = " << tagvalue << std::endl;
}
++itr;
}
std::string entryId = "0010|0010";
DictionaryType::ConstIterator tagItr = dictionary.Find(entryId);
if(tagItr == end) {
std::cerr << "Tag " << entryId;
std::cerr << " not found in the DICOM header" << std::endl;
return EXIT_FAILURE;
}
MetaDataStringType::ConstPointer entryvalue =
dynamic_cast<const MetaDataStringType *>(tagItr->second.GetPointer());
if(entryvalue) {
std::string tagvalue = entryvalue->GetMetaDataObjectValue();
std::cout << "Patient's Name (" << entryId << ") ";
std::cout << " is: " << tagvalue << std::endl;
} else {
std::cerr << "Entry was not of string type" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
上一篇: 我就知道,你会帮我的
下一篇: openFOAM中的forAll
推荐阅读