# From DICOM scalar volume to retrieve header attributes/tags

**URL:** <https://discourse.slicer.org/t/from-dicom-scalar-volume-to-retrieve-header-attributes-tags/11740>\
**Category:** Development\
**Created:** [May 27, 2020, 11:16pm UTC](https://discourse.slicer.org/t/from-dicom-scalar-volume-to-retrieve-header-attributes-tags/11740 "2020-05-27T23:16:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![szhang](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@szhang](https://discourse.slicer.org/u/szhang)\
**Post date:** [May 27, 2020, 11:16pm UTC](https://discourse.slicer.org/t/from-dicom-scalar-volume-to-retrieve-header-attributes-tags/11740/1 "2020-05-27T23:16:43Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![szhang](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@szhang](https://discourse.slicer.org/u/szhang)\
**Post date:** [May 28, 2020, 1:43pm UTC](https://discourse.slicer.org/t/from-dicom-scalar-volume-to-retrieve-header-attributes-tags/11740/2 "2020-05-28T13:43:45Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [May 28, 2020, 2:26pm UTC](https://discourse.slicer.org/t/from-dicom-scalar-volume-to-retrieve-header-attributes-tags/11740/3 "2020-05-28T14:26:22Z")

</div>

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:](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:)

---

<div class="post-metadata">

**Author:** ![szhang](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@szhang](https://discourse.slicer.org/u/szhang)\
**Post date:** [May 28, 2020, 3:53pm UTC](https://discourse.slicer.org/t/from-dicom-scalar-volume-to-retrieve-header-attributes-tags/11740/4 "2020-05-28T15:53:06Z")

</div>

Got it, thank you, Steve!

---

<div class="post-metadata">

**Author:** ![szhang](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@szhang](https://discourse.slicer.org/u/szhang)\
**Post date:** [May 28, 2020, 10:23pm UTC](https://discourse.slicer.org/t/from-dicom-scalar-volume-to-retrieve-header-attributes-tags/11740/5 "2020-05-28T22:23:46Z")

</div>

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](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!

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [May 28, 2020, 11:52pm UTC](https://discourse.slicer.org/t/from-dicom-scalar-volume-to-retrieve-header-attributes-tags/11740/6 "2020-05-28T23:52:37Z")

</div>

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](https://github.com/lassoan/SlicerDicomPatcher/blob/master/DicomPatcher.py).

---

<div class="post-metadata">

**Author:** ![szhang](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@szhang](https://discourse.slicer.org/u/szhang)\
**Post date:** [May 29, 2020, 12:42am UTC](https://discourse.slicer.org/t/from-dicom-scalar-volume-to-retrieve-header-attributes-tags/11740/7 "2020-05-29T00:42:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 29, 2020, 12:42am UTC](https://discourse.slicer.org/t/from-dicom-scalar-volume-to-retrieve-header-attributes-tags/11740/8 "2020-05-29T00:42:21Z")

</div>

> [@szhang](#):
>
> the tags do not get saved in DICOM output attributes

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](https://github.com/SlicerRt/SlicerRT/blob/7f56d8ee6c54ab98a80113075beaac7d2c7ed921/DicomRtImportExport/DicomRtImportExportPlugin.py#L67-L127).
