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

Mathew Guilfoyle mrguilfoyle at gmail.com
Sat Jun 28 21:58:30 EDT 2014


Thanks very much for looking into this; look forward to the fix.

Cheers


On 27 June 2014 14:21, Michka Popoff <michkapopoff at gmail.com> wrote:

> Hi
>
> I looked further into this, seems you found a bug.
> In fact we do not support passing strings by reference to a method (for
> the moment).
> I opened an issue on the bugtracker [1], you can register yourself and
> follow it.
>
> I found a way to fix this, I just need to implement it in ITK (and see if
> it does not break the build).
> I will work on this during the weekend.
>
> [1] https://issues.itk.org/jira/browse/ITK-3285
>
>
> Le 25 juin 2014 à 15:45, Michka Popoff a écrit :
>
> To get the label, I suppose you may want to use the GetLabelFromTag
> method. (I never used Dicom before, so I suppose it's what you want).
>
> GetLabelFromTag and GetValueFromTag have the same problem ... they fail
> with the same error message.
> It's because in C++ you pass the argument as a string by reference, which
> you can't in Python.
> I don't know how Swig is wrapping this, so I'll have to investigate a
> little bit.
>
> I'll look at this soon and I'll keep you updated.
>
>
> Le 25 juin 2014 à 14:22, Mathew Guilfoyle a écrit :
>
> 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/insight-users/attachments/20140629/aae6b8f3/attachment.html>


More information about the Insight-users mailing list