[Insight-users] Problems reading DICOM header
Luis Ibanez
luis.ibanez at kitware.com
Mon Oct 23 09:59:15 EDT 2006
Hi Clemens,
In the code that you are using, you are explicitly filtering the
tag of the DICOM files, for keeping only the ones that are known
to the GDCM DICOM dictionary. This, of course, will not include
the private tags that you are looking for.
What you can do is to modify the lines:
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++;
To have an "else" were you still print out a tag, even if it
is not found in the standard GDCM dictionary.
The code should look like:
if (found)
{
fstream f;
f.open("header.txt", ios::out|ios::app);
f << h << " (" << tagkey << ") " << labelId;
f << " = " << tagvalue.c_str() << std::endl;
f.close();
}
else
{ // private tags
fstream f;
f.open("header.txt", ios::out|ios::app);
f << h << " (" << tagkey << ") ";
f << " = " << tagvalue.c_str() << std::endl;
f.close();
}
++itr; h++;
Note that the main difference, is that in the second
case you don't have available the "labelId", which is
the label provided by the GDCM standard dictionaries.
A second, more sophisticated option is for you to
create a dictionary with these private tags and
put it in one of the directories that GDCM search
for custom dictionaries.
Regards,
Luis
=========================
Clemens Hentschke wrote:
> 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 << ") ";
More information about the Insight-users
mailing list