From DICOM scalar volume to retrieve header attributes/tags

Hello
Probably a very basic question, after loading the DICOM stack as a scalar volume, how in the code can I obtain one of the header tag information (e.g. Patient Position, or Reconstruction Kernel)? If there are some sample code to look up to, that will be great.

Thank you!

To continue on this thread, this is what I have tried on Python interactor window:
shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)
volumeNode = slicer.mrmlScene.GetNodeByID(‘vtkMRMLScalarVolumeNode1’)
shNode.GetAttributeFromItemAncestor(shNode.GetItemByDataNode(volumeNode),‘DICOM.PatientName’)

It can return something, but if I substitute DICOM.PatientName with some other attributes, such as DICOM.modality or DICOM.ConvolutionKernel, there is nothing returned, but I clearly see the value of these attributes, what am I missing?

Thanks a lot in advance!

Hi -

Only some high level tags are stored in the node. To get the rest of the dicom header info you use the instance uid and you can either access via the database or use pydicom to look at the instances directly.

This code will help:

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_access_tag_of_a_volume_loaded_from_DICOM.3F_For_example.2C_get_the_patient_position_stored_in_a_volume:

Got it, thank you, Steve!

The next step I wanted is to save this attribute value together with the output volume for DICOMs, this piece is somewhat useful:https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Export_a_volume_to_DICOM_file_format
but I do not see how to set certain attribute values,
I tried DICOMExportScalarVolume but the tags do not get saved in DICOM output attributes. Any advice?

Thank you again!

Hmm, for that kind of manipulation probably the easiest is to iterate through the exported files and modify attributes with pydicom like is done in the DicomPatcher.

I see, thank you! However, I do not find “pydicom” used anywhere in DicomPatcher.py…

What tags would you like to save? We can add some more of the commonly used standard tags, if that helps.

For adding arbitrary custom tags using pydicom as @pieper suggested should work well. You can integrate the this additional update step nicely in the DICOM export GUI by implementing a custom DICOM export plugin. It should be just a few ten lines of extra code. See an example of a custom DICOM import/export plugin in SlicerRT.