[vtkusers] How to extract a specific DICOM Tag using vtkDICOMReader

David Gobbi david.gobbi at gmail.com
Thu Feb 8 08:52:10 EST 2018


Hi Jonathan,

Here's a short example of getting values from meta data:

# get the meta data from the reader
metadata = readerSPECT.GetMetaData()
# tags are in hexadecimal, so "0x" must be used
positionTag = vtkDICOMPython.vtkDICOMTag(0x0020,0x0032)
# GetAttributeValue has an optional index argument, to select one file in
the series,
# each file will have a different position
positionValue = metadata.GetAttributeValue(0, positionTag)
# you can get tags by name, instead, by using the DC namespace
positionValue = metadata.GetAttributeValue(0,
vtkDICOMPython.DC.ImagePositionPatient)
# use GetDouble() to extract the x,y,z position values (use list
comprehension)
position = [positionValue.GetDouble(i) for i in
range(positionValue.GetNumberOfValues())]

More info is here (though all the examples are C++):
http://dgobbi.github.io/vtk-dicom/doc/api/attributes.html

Also, since you're interested in position, here is info on position,
orientation:
http://dgobbi.github.io/vtk-dicom/doc/api/image_orientation.html

I recommend using "reader.GetPatientMatrix()" to get the position info.

Make sure that you read the documentation for the
vtkDICOMReader.SetMemoryRowOrderToFileNative() method.  It controls whether
the data is re-ordered when it is read.

Cheers,
 - David



On Thu, Feb 8, 2018 at 2:35 AM, Jojobus <jojotranel at hotmail.com> wrote:

> Hello vtk(-dicom) users,
>
> I am attempting to extract the ImagePatientPosition tag (0020,0032) from a
> SPECT DICOM image using vtk-dicom library and python. However, I am
> encountering some trouble to find the right combinaison between the
> vtkDICOMTag and vtkDICOMReader. My written code so far is below:
>
> directory = vtkDICOMPython.vtkDICOMDirectory()
> directory.SetDirectoryName(PathDicomSPECT)
> directory.Update()
> readerSPECT = vtkDICOMPython.vtkDICOMReader()
> readerSPECT.SetFileNames(directory.GetFileNamesForSeries(0))
> readerSPECT.Update()
>
> # No encountered troubles so far but for the next step...
>
> TagPatientPosition=vtkDICOMPython.vtkDICOMTag(20,32)
> MetaPatientPosition=vtkDICOMPython.vtkDICOMMetaData()
> MetaPatientPosition.GetAttributeValue(TagPatientPosition)
>
> #What is the right thing to code in order to be linked with readerSPECT?
>
> How can code the vtkDICOMImageReader equivalent of GetImagePositionPatient
> ()  ?
>
> Many thanks in advance !
>
> Jonathan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180208/a979125e/attachment.html>


More information about the vtkusers mailing list