How to export dicom file after I use transformation?

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?

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.

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.

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.

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

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 ?

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

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

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).

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?

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"
    studyItemID = shNode.GetItemParent(subjectHierarchyItemID)
    if not studyItemID:
        error = "Unable to get study for series '" + volumeNode.GetName() + "'"
    patientItemID = shNode.GetItemParent(studyItemID)
    if not patientItemID:
        error = "Unable to get patient for series '" + volumeNode.GetName() + "'"
    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() + "'"
    directoryName = str(tags['Series Number'])
    directoryDir = qt.QDir(f"D:/data/{str(tags['Patient Name'])}/{str(tags['Modality'])}")
    directory = directoryDir.absolutePath()
    exporter = DICOMExportScalarVolume(tags['Study ID'], volumeNode, tags, directory)
    if not exporter.export():
        print("Creating DICOM files from scalar volume failed")

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?

just output :

Creating DICOM files from scalar volume failed

I don’t know why.

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