[ITK-users] [Insight-users] GDCM custom tag dictionary
Harnish, Roy
Roy.Harnish at ucsf.edu
Tue Jul 15 22:19:03 EDT 2014
Hi,
I'm revisiting the thread below since I'm having trouble getting the DicomImageReadPrintTags.cxx example to use the .dic file I provide. I am trying to correctly interpret the (0119,1030) tag from a dicom file. The element is very similar to an ImageOrientationPatient, but defines direction cosines for slices in addition to rows and columns. I'm wondering if I should continue trying to specify my own .dic (or is it XML?), of if there is an alternative. Perhaps I could try to parse the output ((0119|1030) is: LTFcLTBcMFwtMFwtMVwwXDBcMFwxIA==) as a 9 element DS. Syntax suggestions for that would be much appreciated.
Yours,
Roy
This is a comparison of dcmdumps:
cbl-mbp-3369:data rharnish$ dcmdump dce.dcm | grep 0119,1030
(0119,1030) DS [-1\-0\0\-0\-1\0\0\0\1] # 22, 9 Unknown Tag & Data
cbl-mbp-3369:data rharnish$ dcmdump dce.dcm | grep ImageOri
(0020,0037) DS [-1\-0\0\-0\-1\0] # 16, 6 ImageOrientationPatient
cbl-mbp-3369:data rharnish$
This is the modified version of DicomImageReadPrintTags.cxx I'm using:
#include "itkImageFileReader.h"
#include "itkGDCMImageIO.h"
#include "itkMetaDataObject.h"
#include "gdcmGlobal.h"
int
main (int argc, char* argv[])
{
if (argc < 2)
{
std::cerr << "Usage: " << argv[0] << " DicomFile [user defined dict]" << std::endl;
return EXIT_FAILURE;
}
typedef unsigned short PixelType;
const unsigned int Dimension = 3;
typedef itk::Image<PixelType, Dimension> ImageType;
if (argc == 3)
{
// Specify a path where XML dicts can be found (Part 3/4 & 6)
gdcm::Global::GetInstance ().Prepend (itksys::SystemTools::GetFilenamePath (argv[2]).c_str ());
// Load them !
gdcm::Global::GetInstance ().LoadResourcesFiles ();
std::cout << argv[2] << std::endl;
std::cout << itksys::SystemTools::GetFilenamePath (argv[2]).c_str () << std::endl;
}
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New ();
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer dicomIO = ImageIOType::New ();
dicomIO->LoadSequencesOn ();
dicomIO->LoadPrivateTagsOn ();
reader->SetFileName (argv[1]);
reader->SetImageIO (dicomIO);
try
{
reader->Update ();
}
catch (itk::ExceptionObject &ex)
{
std::cout << ex << std::endl;
return EXIT_FAILURE;
}
std::cout << "has key: " << dicomIO->GetMetaDataDictionary ().HasKey ("0119|1030") << std::endl;
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 ();
// try to print value of 0119|1030
std::string entryId = "0119|1030";
DictionaryType::ConstIterator tagItr = dictionary.Find (entryId);
if (tagItr != end)
{
MetaDataStringType::ConstPointer entryvalue = dynamic_cast<const MetaDataStringType *> (tagItr->second.GetPointer ());
if (entryvalue)
{
std::string tagvalue = entryvalue->GetMetaDataObjectValue ();
std::cout << "(" << entryId << ") ";
std::cout << " is: " << tagvalue.c_str () << std::endl;
}
}
// try to print value of ImageOrientationPatient
entryId = "0020|0037";
tagItr = dictionary.Find (entryId);
if (tagItr != end)
{
MetaDataStringType::ConstPointer entryvalue = dynamic_cast<const MetaDataStringType *> (tagItr->second.GetPointer ());
if (entryvalue)
{
std::string tagvalue = entryvalue->GetMetaDataObjectValue ();
std::cout << "(" << entryId << ") ";
std::cout << " is: " << tagvalue.c_str () << std::endl;
}
}
return EXIT_SUCCESS;
}
This is the program output:
/Users/rharnish/Projects/itkImageProcessing/io/DicomTags/data/test.dic
/Users/rharnish/Projects/itkImageProcessing/io/DicomTags/data
has key: 1
(0119|1030) is: LTFcLTBcMFwtMFwtMVwwXDBcMFwxIA==
(0020|0037) is: -1\-0\0\-0\-1\0
This is the contents of test.dic:
0119 1030 DS 9 3DDirectionCosines
Angela.Y Wang wrote:
> I am trying to read processed data in dicom file format and would like
> to create a GDCM dictionary for the private tags. In a previous
> message, it was suggested to create a custom tag dictionary and put it
> in the GDCM search path. Could somebody please tell me how to go about
> doing this?
Hi Angela,
I have added an example on how to user dynamically loaded user defined
DICOM dictionary:
$ cvs ci -m"ENH: Add example on how to use a user defined dict"
/cvsroot/Insight/Insight/Examples/IO/DicomImageReadPrintTags.cxx,v <--
DicomImageReadPrintTags.cxx
new revision: 1.16; previous revision: 1.15
/cvsroot/Insight/Insight/Examples/IO/itk.dic,v <-- itk.dic
initial revision: 1.1
You should be able to now type in:
$ ./bin/DicomImageReadPrintTags /path/to/012345.002.050
/path/to/Insight/Examples/IO/itk.dic
First argument is the DICOM file, second (optional) argument is a user
defined dictionary which should look like:
http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/Examples/IO/itk.dic?rev=1.1&root=Insight
HTH
Mathieu
More information about the Insight-users
mailing list