[Insight-users] Problems reading DICOM header
Clemens Hentschke
Paradise.Devil at gmx.net
Thu Oct 19 15:37:57 EDT 2006
Hi,
i just tried to read DICOM header in ITK, i used the example from software guide. All works fine, but i recognized that some tags are missing (i read the DICOM with matlab). Both, some private and public tags are missing i need to read. I tried to access them directly via find function, but that didnt work, i got a runtime error (Segmentation fault).
Is there any possibiliy to access these Tags? ITK seems to find the Tag, but couldnt read it.
I am using Suse Linux 9.2 and ITK 2.81 and gcc 3.3.4
here is my code:
ReaderType::Pointer reader = m_image;
InputImageType::Pointer inputImage = reader->GetOutput();
typedef itk::MetaDataDictionary DictionaryType;
DictionaryType & dictionary = inputImage->GetMetaDataDictionary();
typedef itk::MetaDataObject< std::string > MetaDataStringType;
DictionaryType::ConstIterator itr = dictionary.Begin();
DictionaryType::ConstIterator end = dictionary.End();
int h = 0;
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 labelId;
bool found = itk::GDCMImageIO::GetLabelFromTag( tagkey, labelId );
std::string tagvalue = entryvalue->GetMetaDataObjectValue();
if (found)
{
fstream f;
f.open("header.txt", ios::out|ios::app);
f << h << " (" << tagkey << ") " << labelId;
f << " = " << tagvalue.c_str() << std::endl;
f.close();
}
++itr; h++;
}
}
std::string entryId = "0054|0016";
DictionaryType::ConstIterator tagItr = dictionary.Find( entryId );
MetaDataStringType::ConstPointer entryvalue = dynamic_cast<const MetaDataStringType *>(tagItr->second.GetPointer() );
std::string v = entryvalue->GetMetaDataObjectValue();
std::cout << "gefunden: (" << v << ") ";
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
More information about the Insight-users
mailing list