# Export Deformation Field as Dicom

**URL:** <https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657>\
**Category:** Support\
**Tags:** registration, dicom\
**Created:** [September 23, 2020, 12:56pm UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657 "2020-09-23T12:56:18Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![iTheoch](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/itheoch/32/12435_2.png) [@iTheoch](https://discourse.slicer.org/u/iTheoch)\
**Post date:** [September 23, 2020, 12:56pm UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/1 "2020-09-23T12:56:18Z")

</div>

Dear all,

I am looking if 3D Slicer is capable of exporting Deformable Registration Objects as DICOM. Of course my first priority was to search your forum and see if anyone else had a similar request. Indeed I found a couple related issues (links below)

> [@Import of registration DICOM files](https://discourse.slicer.org/t/import-of-registration-dicom-files/368/23):
>
> Hi, Thanks for your reply. I have downloaded the most recently nightly Slicer (Slicer 4.11.0-2019-05-19) but I still can’t export the deformable transform (done in “General Registration (BRAINS)” module)? I have succeeded in exporting linear transform and got the SRO (.dcm) which I could import to mim software as REG. Is there any wrong with my Slicer version? Your help is highly appreciated. Crayon [01] [02]

> [@Export deformable transform to DICOM](https://discourse.slicer.org/t/export-deformable-transform-to-dicom/7997):
>
> Thanks for the clarification. I have succeeded in installing the extensions using yesterday’s preview release version. But I still have two other questions. I want to export deformable transform, but when I install “SlicerRT” extension, “DICOM Registration Export” module didn’t show up. I have followed this [thread](https://discourse.slicer.org/t/import-of-registration-dicom-files/368/22) but don’t know how to use that? Could you give some advice? I was a bit confused about the warning(?) in Python Interactor (shown below). I have installed “SlicerRT” extension a…

Following your suggestions on these threads I have downloaded the latest nightly build at that moment 4.11.0-2020-09-21 r29383 / c299952. Though I cannot find the proper way of using the DICOM Spatial Registration Object Import Export plugin. I have tried SAVE scene option and selected only the Deformation Grid but in the File format combo box I can’t see any DICOM option. Also some options are giving me error on saving (like MHA. MHD) while saving as h5 or txt works.  
Also tried right click on scene → Dicom Export but again there when REG object is selected there are no Dicom Tags visible.  
Am I doing something completely wrong here or the functionality is still not implemented?

Thank you for your patience, excellent work and assistance.  
Kind regards  
Yiannis

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [September 23, 2020, 1:11pm UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/2 "2020-09-23T13:11:12Z")

</div>

It sounds like you don’t have your registration transform under a patient and study. You either need to drag&drop it under an existing study (if your input came from DICOM you have it), or you need to create a new one. You need to do both in the Data module. To create a new patient right-click the empty space and choose Create new subject, and then Create new study under the new patient. Then when the transform is under a study, right-click the study and choose Export to DICOM. Make sure the REG plugin is selected on the bottom left. You can set DICOM tags in this window.

---

<div class="post-metadata">

**Author:** ![iTheoch](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/itheoch/32/12435_2.png) [@iTheoch](https://discourse.slicer.org/u/iTheoch)\
**Post date:** [September 24, 2020, 10:15am UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/3 "2020-09-24T10:15:20Z")

</div>

Dear cpinter,

Thanks for the quick reply. I have created manually a new patient/study/series tree like this  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/2/f229e9f5df55c0c103af236da027615b95215cf0.png)

When selecting Export Dicom from the study I get the dialog below

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/a/9a9ededb99609b665d40f08b97d8e9080aed045a.png)

And when I focus on the Deformable Reg node I get no options to select.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/a/0af3ecc8a7b34fe173b0c15f3a8976c758d3a8ef.png)

Do I need to install separately the REG plugin? I have installed SlicerRT and SlicerElastix extensions.

Thanks again for your help.

Kind regards  
Yiannis

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [September 24, 2020, 10:26am UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/4 "2020-09-24T10:26:24Z")

</div>

If the transforms are directly under the study then what happens?

The REG plugin is in SlicerRT.

---

<div class="post-metadata">

**Author:** ![iTheoch](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/itheoch/32/12435_2.png) [@iTheoch](https://discourse.slicer.org/u/iTheoch)\
**Post date:** [September 24, 2020, 10:43am UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/5 "2020-09-24T10:43:40Z")

</div>

Similar behavior

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/6/c65c749dfaa3bd8b6f913300eab367b82655c73e.png)

For some reason also I cannot drag and drop in the data tree control. When I click and drag is starting selecting other nodes also. (something different from my initial problem but thought to report it).

the tree that you see above is how is loaded by slicer and by default as I can see the REG is under the study and not the series. But again I don’t get the option to export.

Thanks

update: The drag and drop is now back and running. not sure what was wrong.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [September 24, 2020, 10:58am UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/6 "2020-09-24T10:58:32Z")

</div>

> For some reason also I cannot drag and drop in the data tree control. When I click and drag is starting selecting other nodes also.

You can drag&drop in the Data module, and not in other views (@lassoan the same is happening in the DICOM module, and it’s quite annoying. We should do something with this, maybe just enable single selection, otherwise it seems like a bug that drag&drop is not enabled in those views. What do you think?)

Is there any error in your log? For example “Failed to find moving and/or fixed image for transform…”. Because the transform can only be exported to DICOM if it was created by one of Slicer’s registration modules and the proper references set.

Btw here’s a tutorial about DICOM SROs:

> <https://github.com/SlicerRt/SlicerRtDoc/blob/master/tutorials/SlicerRT_Tutorial_DICOMRegistrationObject.pptx>

---

<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:** [September 24, 2020, 11:17am UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/7 "2020-09-24T11:17:44Z")

</div>

I remember I was surprised by disabled drag-and-drop, too. Could we just enable drag-and-drop in the subject hierarchy tree widget by default?

---

<div class="post-metadata">

**Author:** ![iTheoch](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/itheoch/32/12435_2.png) [@iTheoch](https://discourse.slicer.org/u/iTheoch)\
**Post date:** [September 24, 2020, 11:25am UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/8 "2020-09-24T11:25:28Z")

</div>

Thanks for the tutorial, I will study it.  
You are absolutely right on the reason of not exporting. I indeed have a “Failed to find moving…” error. And indeed also I am loading a DVF file from Varian Ethos manufacturer. So I assume that importing a DVF from another vendor means that I cannot export again? Is export only available for Slicer created fields?

Thanks again,  
Yiannis

---

<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:** [September 24, 2020, 11:38am UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/9 "2020-09-24T11:38:37Z")

</div>

We could probably automatically guess the two images from the scene (if there are multiple candidate image pairs then we could choose the first). Maybe we could also add the series instance uids of the fixed and moving image it to the list of editable DICOM fields in export dialog (just in case someone wants to select.a different one)? Or, could we add node reference selector in the DICOM export info window? @cpinter what do you think?

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [September 24, 2020, 12:27pm UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/10 "2020-09-24T12:27:36Z")

</div>

> [@lassoan](#):
>
> Could we just enable drag-and-drop in the subject hierarchy tree widget by default?

Yes probably that would be a good idea too

> [@lassoan](#):
>
> Or, could we add node reference selector in the DICOM export info window?

While reading the first part of your comment this was the idea that popped up in my head. Maybe we should allow series to define the necessary node references and expose them in the export dialog.

Another thing that many people miss is exporting from under a patient/study. There are many things to do in the DICOM export dialog. There may be a project in terms of which we can do some of these in a few months. I’ll ask.

For the specific issue of @iTheoch, what I’d suggest so that progress can be made is to set the node references manually. @lassoan there is a module exposing node references in one of the developer extensions right?  
The two references that need to be set are

```auto
>>> slicer.vtkMRMLTransformNode.GetMovingNodeReferenceRole()
'spatialRegistrationMoving'
>>> slicer.vtkMRMLTransformNode.GetFixedNodeReferenceRole()
'spatialRegistrationFixed'

```

---

<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:** [September 24, 2020, 12:58pm UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/11 "2020-09-24T12:58:45Z")

</div>

> [@cpinter](#):
>
> > [@lassoan](#):
> >
> > Could we just enable drag-and-drop in the subject hierarchy tree widget by default?
> 
> Yes probably that would be a good idea too

OK. I’ll try this and see if it works as expected or there are side effects that we haven’t thought about.

> [@cpinter](#):
>
> There are many things to do in the DICOM export dialog. There may be a project in terms of which we can do some of these in a few months. I’ll ask.

Sounds good. It would be nice to have node selectors and enumerated values. Maybe we could reuse parts of the CLI module widget factory.

> [@cpinter](#):
>
> For the specific issue of @iTheoch, what I’d suggest so that progress can be made is to set the node references manually

Agreed.

> [@cpinter](#):
>
> there is a module exposing node references in one of the developer extensions right?

Yes, “Node info” module in DebuggingTools extension can show node references (you cannot change them, but if the need to add/remove/modify node references comes up frequently enough then it should be easy to implement this).

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [September 24, 2020, 1:00pm UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/12 "2020-09-24T13:00:44Z")

</div>

> [@lassoan](#):
>
> OK. I’ll try this and see if it works as expected or there are side effects that we haven’t thought about.

I’m about to push a PR. Do you have anyhing particular in mind that I should test?

---

<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:** [September 24, 2020, 1:21pm UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/13 "2020-09-24T13:21:05Z")

</div>

> [@cpinter](#):
>
> I’m about to push a PR. Do you have anyhing particular in mind that I should test?

Nothing specific, just test drag-and-drop in DICOM module widget (I don’t expect any issues, as its role is essentially the same as in Data module), DICOM export dialog (probably we want to disable drag&drop there), and run the automatic tests. Models and Markups module widgets already have drag&drop enabled, so we don’t need to test there.

---

<div class="post-metadata">

**Author:** ![iTheoch](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/itheoch/32/12435_2.png) [@iTheoch](https://discourse.slicer.org/u/iTheoch)\
**Post date:** [September 24, 2020, 2:25pm UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/14 "2020-09-24T14:25:27Z")

</div>

Hi both,  
Thank you for looking at the issue. Is there anything I can do as it is now to apply the workaround or should I wait for some future nightly release version?

Regards  
Yiannis

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [September 24, 2020, 7:28pm UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/15 "2020-09-24T19:28:37Z")

</div>

I added drag&drop to the data tree, see the pull request [https://github.com/Slicer/Slicer/pull/5201](https://github.com/Slicer/Slicer/pull/5201)

@iTheoch If you want, you can do everything from Python right now, but as @lassoan said we can help you do this from the UI after adding a small feature.

---

<div class="post-metadata">

**Author:** ![iTheoch](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/itheoch/32/12435_2.png) [@iTheoch](https://discourse.slicer.org/u/iTheoch)\
**Post date:** [September 25, 2020, 8:34am UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/16 "2020-09-25T08:34:20Z")

</div>

Hi both.  
Thank you for your assistance and effort. I will check Python to see if I can work around the issue and will be looking forward for a future version.

Kind regards  
Yiannis

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [September 25, 2020, 9:06am UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/17 "2020-09-25T09:06:36Z")

</div>

Please note that you will need to have two volumes: both the fixed and the moving.

In order to set the references:

```auto
transformNode = getNode('TransformName') # Double-click node in Data module and copy-paste name
fixedVolumeNode = getNode('FixedVolumeName')
transformNode.SetNodeReferenceID(slicer.vtkMRMLTransformNode.GetFixedNodeReferenceRole(), fixedVolumeNode.GetID())
movingVolumeNode = getNode('MovingVolumeName')
transformNode.SetNodeReferenceID(slicer.vtkMRMLTransformNode.GetMovingNodeReferenceRole(), movingVolumeNode.GetID())

```

This should do it

---

<div class="post-metadata">

**Author:** ![marianaslicer](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/marianaslicer/32/8555_2.png) [@marianaslicer](https://discourse.slicer.org/u/marianaslicer)\
**Post date:** [July 14, 2021, 10:20am UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/18 "2021-07-14T10:20:31Z")

</div>

Hi everyone,

I exported my DVFs to DICOM as reported in this topic, but I noticed that they have about 400 MB size. Is there any to make DVFs more lightweight? E.g. downsample the data before saving?

---

<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:** [July 14, 2021, 8:32pm UTC](https://discourse.slicer.org/t/export-deformation-field-as-dicom/13657/19 "2021-07-14T20:32:09Z")

</div>

Dense displacement fields are usually this big, it should not cause issues.

You can resample transform using Transforms module → Convert, by specifying a downsampled volume as reference.

However, if you need lower resolution displacement field then probably you can get much better results if you use bspline transform. Bspline transform is the same as grid transform except it uses bspline interpolation instead of trilinear interpolation, therefore a smooth displacement field can be described with several magnitudes less control points.
