# How to export dicom file after I use transformation?

**URL:** https://discourse.slicer.org/t/how-to-export-dicom-file-after-i-use-transformation/18297
**Category:** Support
**Tags:** segmentation, dicom
**Created:** [June 23, 2021, 12:33pm UTC](https://discourse.slicer.org/t/how-to-export-dicom-file-after-i-use-transformation/18297 "2021-06-23T12:33:28Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![yllgl](https://avatars.discourse-cdn.com/v4/letter/y/8e7dd6/32.png) [@yllgl](https://discourse.slicer.org/u/yllgl)
#### Post date: [June 23, 2021, 12:33pm UTC](https://discourse.slicer.org/t/how-to-export-dicom-file-after-i-use-transformation/18297/1 "2021-06-23T12:33:28Z")

</div>

I import my local dicom dataset. There are two study of one patient : one about CT, the other about MR. Then I use registration between them, and automatically generate a linear transformation and apply on CT. Now I want to export the series after applying the tranformation.  
I have three questions:

1. Why are there no “export to dicom” option when I right-click on patient node? Only study node and series node have “export to dicom” option. And Must I export dicom one study by one study? Can’t I select multiple patients at once and export them all at once?
2. When I export dicom, the directory was named ScalarVolume\_xxx , (xxx is some digits) I don’t know what the name mean so I can’t correspond them to the information in the software. Can I change the name to some meaningful string?  
3、After I export dicom, I found no difference between my original dicom file and output file after registration. The transformation only contains translation, so I think the output file should modified the dicom tag (0020,0032) which is image position. But nothing was modified. How could I export dicom file after transformation?

---

<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: [June 25, 2021, 6:40pm UTC](https://discourse.slicer.org/t/how-to-export-dicom-file-after-i-use-transformation/18297/2 "2021-06-25T18:40:08Z")

</div>

> [@yllgl](#):
>
> Why are there no “export to dicom” option when I right-click on patient node? Only study node and series node have “export to dicom” option. And Must I export dicom one study by one study? Can’t I select multiple patients at once and export them all at once?

Yes, the GUI only allows you to export one study at a time. If it is too tedious for your workflow then you can implement fully automatic export of everything that you need with a short Python script.

> [@yllgl](#):
>
> When I export dicom, the directory was named ScalarVolume\_xxx , (xxx is some digits) I don’t know what the name mean so I can’t correspond them to the information in the software. Can I change the name to some meaningful string?

DICOM does not know anything about filenames. All file content is described in DICOM tags in the files. During DICOM export, you can specify values for many DICOM tags, which you can use to identify data sets.

> [@yllgl](#):
>
> After I export dicom, I found no difference between my original dicom file and output file after registration. The transformation only contains translation, so I think the output file should modified the dicom tag (0020,0032) which is image position. But nothing was modified. How could I export dicom file after transformation?

You need to harden the transform on the data images if you want to export a modified image. Alternatively, you can export the transform as a DICOM Spatial Registration Object if you install SlicerRT extension.

---

<div class="post-metadata">

### Author: ![yllgl](https://avatars.discourse-cdn.com/v4/letter/y/8e7dd6/32.png) [@yllgl](https://discourse.slicer.org/u/yllgl)
#### Post date: [June 26, 2021, 12:34pm UTC](https://discourse.slicer.org/t/how-to-export-dicom-file-after-i-use-transformation/18297/4 "2021-06-26T12:34:02Z")

</div>

How to get original dicom tag from volumeNode? I just use the code:

```python
volumeNode = slicer.util.getNode(pattern='8002: 3D_Default_2_9', index=0, scene=None)
plugin = slicer.modules.dicomPlugins['DICOMScalarVolumePlugin']()
shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)
subjectHierarchyItemID = shNode.GetItemByDataNode(volumeNode)
exportables = plugin.examineForExport(subjectHierarchyItemID)
for exportable in exportables :
...

```

But `exportable` 's tag is different from original one, which modality is CT but original one is MR, how could I get original tag so I could save it ?

---

<div class="post-metadata">

### Author: ![yllgl](https://avatars.discourse-cdn.com/v4/letter/y/8e7dd6/32.png) [@yllgl](https://discourse.slicer.org/u/yllgl)
#### Post date: [June 27, 2021, 2:47am UTC](https://discourse.slicer.org/t/how-to-export-dicom-file-after-i-use-transformation/18297/5 "2021-06-27T02:47:41Z")

</div>

Why can’t I get original study ID? I use the following code:

```python
subjectHierarchyItemID = shNode.GetItemByDataNode(volumeNode)
studyItemID = shNode.GetItemParent(subjectHierarchyItemID)
print(shNode.GetItemAttribute(studyItemID,'DICOM.StudyID'))# this line return empty string

```

---

<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: [June 27, 2021, 2:54am UTC](https://discourse.slicer.org/t/how-to-export-dicom-file-after-i-use-transformation/18297/6 "2021-06-27T02:54:42Z")

</div>

The attribute name is `StudyID` (not `DICOM.StudyID`). You can get the list of all attribute names available for the item by calling `shNode.GetItemAttributeNames(studyItemID)`.

---

<div class="post-metadata">

### Author: ![yllgl](https://avatars.discourse-cdn.com/v4/letter/y/8e7dd6/32.png) [@yllgl](https://discourse.slicer.org/u/yllgl)
#### Post date: [June 27, 2021, 5:02am UTC](https://discourse.slicer.org/t/how-to-export-dicom-file-after-i-use-transformation/18297/7 "2021-06-27T05:02:41Z")

</div>

it’s very strange, if I change DICOM.StudyID to StudyID, it will fail to save. I don’t know why. Maybe it’s a bug?

```python
shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)
for name,volumeNode in slicer.util.getNodes(pattern='*3D*[!m]', scene=None, useLists=False).items():
    subjectHierarchyItemID = shNode.GetItemByDataNode(volumeNode)
    if volumeNode is None or not volumeNode.IsA('vtkMRMLScalarVolumeNode'):
        error = "Series '" + shNode.GetItemName(subjectHierarchyItemID) + "' cannot be exported"
        print(error)
        continue
    studyItemID = shNode.GetItemParent(subjectHierarchyItemID)
    if not studyItemID:
        error = "Unable to get study for series '" + volumeNode.GetName() + "'"
        print(error)
        continue
    patientItemID = shNode.GetItemParent(studyItemID)
    if not patientItemID:
        error = "Unable to get patient for series '" + volumeNode.GetName() + "'"
        print(error)
        continue
    tags = {}
    tags['Patient Name'] = shNode.GetItemAttribute(patientItemID,'DICOM.PatientName')
    tags['Patient ID'] = shNode.GetItemAttribute(patientItemID,'DICOM.PatientID')
    tags['Patient Birth Date'] = shNode.GetItemAttribute(patientItemID,'DICOM.PatientBirthDate')
    tags['Patient Sex'] = shNode.GetItemAttribute(patientItemID,'DICOM.PatientSex')
    tags['Patient Comments'] = shNode.GetItemAttribute(patientItemID,'DICOM.PatientComments')
    tags['Study ID'] = shNode.GetItemAttribute(studyItemID,'DICOM.StudyID')#if change DICOM.StudyID to StudyID, it will fail to save.
    tags['Study Date'] = shNode.GetItemAttribute(studyItemID,'DICOM.StudyDate')
    tags['Study Time'] = shNode.GetItemAttribute(studyItemID,'DICOM.StudyTime')
    tags['Study Description'] = shNode.GetItemAttribute(studyItemID,'DICOM.StudyDescription')
    tags['Modality'] = shNode.GetItemAttribute(subjectHierarchyItemID,'DICOM.Modality')
    tags['Manufacturer'] = shNode.GetItemAttribute(subjectHierarchyItemID,'DICOM.Manufacturer')
    tags['Model'] = shNode.GetItemAttribute(subjectHierarchyItemID,'DICOM.Model')
    tags['Series Description'] = shNode.GetItemAttribute(subjectHierarchyItemID,'DICOM.SeriesDescription')
    tags['Series Number'] = shNode.GetItemAttribute(subjectHierarchyItemID,'DICOM.SeriesNumber')
    tags['Series Date'] = shNode.GetItemAttribute(subjectHierarchyItemID,'DICOM.SeriesDate')
    tags['Series Time'] = shNode.GetItemAttribute(subjectHierarchyItemID,'DICOM.SeriesTime')
    tags['Content Date'] = shNode.GetItemAttribute(subjectHierarchyItemID,'DICOM.ContentDate')
    tags['Content Time'] = shNode.GetItemAttribute(subjectHierarchyItemID,'DICOM.ContentTime')
    tags['Study Instance UID'] = shNode.GetItemAttribute(studyItemID,'StudyInstanceUID')
    tags['Series Instance UID'] = shNode.GetItemAttribute(subjectHierarchyItemID,'DICOM.SeriesInstanceUID')
    tags['Frame of Reference Instance UID'] = shNode.GetItemAttribute(subjectHierarchyItemID,'DICOM.ReferencedInstanceUIDs')
    if tags['Modality'] == "":
        error = "Empty modality for series '" + volumeNode.GetName() + "'"
        print(error)
        continue
    directoryName = str(tags['Series Number'])
    directoryDir = qt.QDir(f"D:/data/{str(tags['Patient Name'])}/{str(tags['Modality'])}")
    directoryDir.mkpath(directoryName)
    directoryDir.cd(directoryName)
    directory = directoryDir.absolutePath()
    exporter = DICOMExportScalarVolume(tags['Study ID'], volumeNode, tags, directory)
    if not exporter.export():
        print("Creating DICOM files from scalar volume failed")
        continue

```

---

<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: [June 27, 2021, 1:44pm UTC](https://discourse.slicer.org/t/how-to-export-dicom-file-after-i-use-transformation/18297/8 "2021-06-27T13:44:11Z")

</div>

> [@yllgl](#):
>
> if I change DICOM.StudyID to StudyID, it will fail to save

If you use DICOM.StudyID then you pass an empty string for StudyID, so a new one is generated for you.

It seems that you have problem when you pass the actual existing StudyID to the exporter. It should work, too. What is the error message that you get?

---

<div class="post-metadata">

### Author: ![yllgl](https://avatars.discourse-cdn.com/v4/letter/y/8e7dd6/32.png) [@yllgl](https://discourse.slicer.org/u/yllgl)
#### Post date: [June 27, 2021, 1:48pm UTC](https://discourse.slicer.org/t/how-to-export-dicom-file-after-i-use-transformation/18297/9 "2021-06-27T13:48:41Z")

</div>

just output :

```auto
True
True
Creating DICOM files from scalar volume failed

```

I don’t know why.

---

<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: [June 27, 2021, 1:54pm UTC](https://discourse.slicer.org/t/how-to-export-dicom-file-after-i-use-transformation/18297/10 "2021-06-27T13:54:34Z")

</div>

Do you see errors in the application log (menu: Help / Report a bug)?
