[ITK] [ITK-users] Accessing DICOM header/meta data with Python ITK

Mathew Guilfoyle mrguilfoyle at gmail.com
Wed Jun 25 08:22:58 EDT 2014


Fantastic!

Is there a way of getting the label as well as the value of the entry? It
would be useful for checking that the dictionary entry is the one expected
from the tag.

Out of interest, do you know the correct way of using the
dicomIO.GetValueFromTag() method?

Thanks again
Mat


On 25 June 2014 13:12, Michka Popoff <michkapopoff at gmail.com> wrote:

> Hi
>
> I think you can directly access it "python style":
>
> tilt = metad['0018|1120']
>
> In fact, the itlMetaDataDictionnary class has a __getitem__ method, which
> downcasts directly the value [1].
>
> [1]
> https://github.com/InsightSoftwareConsortium/ITK/blob/master/Wrapping/Generators/Python/PyBase/pyBase.i#L173
>
> Le 25 juin 2014 à 13:35, Mathew Guilfoyle a écrit :
>
> > Hi,
> >
> > I need some help with how to correctly access the DICOM meta data
> dictionary using Python wrapped ITK (v.4.5).  My CT scans are scanned with
> gantry tilt which I need to correct with a shear transform prior to
> segmenting.  The gantry tilt angle is stored in the DICOM header under tag
> (0018, 1120)
> >
> > example:
> >
> > import itk
> >
> > imdir = '/path/to/images'
> > image_t = itk.Image[itk.F, 3]
> >
> > #set up reader
> > reader = itk.ImageSeriesReader[image_t].New()
> > dicomIO = itk.GDCMImageIO.New()
> > dicomFN = itk.GDCMSeriesFileNames.New()
> > reader.SetImageIO(dicomIO)
> >
> > #get file names
> > dicomFN.SetUseSeriesDetails(True)
> > dicomFN.SetDirectory(imdir)
> >
> > #get the first image series
> > uids = dicomFN.GetSeriesUIDs()
> > fnames = dicomFN.GetFileNames(uids[0])
> >
> > #read in the files
> > reader.SetFileNames(fnames)
> > reader.Update()
> > image = reader.GetOutput()
> >
> > #getting the image works fine.  Now to access the meta data dictionary
> > metad = dicomIO.GetMetaDataDictionary()
> >
> > #get the entry for gantry tilt using the relevant DICOM tag (0018, 1120)
> > tilt = metad.Get('0018|1120')
> >
> > At this point I am stuck.  tilt is of type itkMetaDataObjectBase, rather
> than one the derived classes specific to strings, floats etc..
>  itkMetaDataObjectBase does not contain the GetMetaDataObjectValue()
> method, whereas the derived classes do.
> >
> > In the ITK manual, the C++ example uses a dynamic_cast at the type the
> tag is extracted so that 'tilt' would be of one the derived class types.  I
> have tried the following:
> >
> > sst = itk.MetaDataObject.SS
> > tilt.__class__ = sst
> > tilt.GetMetaDataObjectValue()
> >
> > casting tilt does work, and the GetMetaDataObjectValue() method is now
> present as one of tilt's attributes, but just returns an error if executed.
> >
> > The other approach I have tried is to use the dicomIO.GetValueFromTag()
> method.  From the source file the method signature is
> >
> > GetValueFromTag(self, string tag, string value)
> >
> > 'value' is, I presume, meant to be the name of the variable created
> containing the tilt angle.  However if I try:
> >
> > dicomIO.GetValueFromTag('0018|1120', 't_angle')
> >
> > I get the error
> >    in method 'itkGDCMImageIO_GetValueFromTag', argument 3 of type
> 'std::string &
> >
> > I would be tremendously grateful for any pointers on how to access the
> tag data - it must be a routine operation for people using Python/ITK on
> DICOM images!
> >
> > Many thanks
> > Mat
> >
> > _____________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Kitware offers ITK Training Courses, for more information visit:
> > http://www.kitware.com/products/protraining.php
> >
> > Please keep messages on-topic and check the ITK FAQ at:
> > http://www.itk.org/Wiki/ITK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://public.kitware.com/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140625/32530cda/attachment-0002.html>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list