# Saving transformed Volumes

**URL:** <https://discourse.slicer.org/t/saving-transformed-volumes/1266>\
**Category:** Support\
**Tags:** transforms, binarylabelmap\
**Created:** [October 23, 2017, 4:06pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266 "2017-10-23T16:06:37Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [October 23, 2017, 4:06pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/1 "2017-10-23T16:06:37Z")

</div>

Hi, I am trying to save binary labelmaps that I have transformed with specific transform files. The problem is that I have clicked the harden transform button, but when I go to save the files, they do not save in the correct orientation, but rather the initial orientation. Is there an easy way to save the new matrices corresponding to the transformed labelmaps?

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [October 23, 2017, 4:19pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/2 "2017-10-23T16:19:02Z")

</div>

In addition, is there a way to save a transformed segmentation? Again, I have tried hardening the renasform and saving the seg.nrrd file, but the outcome is the original segmentation orientation, and not the transformed orientation.

---

<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:** [October 23, 2017, 5:24pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/3 "2017-10-23T17:24:14Z")

</div>

Hardening linear transforms on volumes don’t require changing voxel values, you’ll only see result of hardening as an update in axis direction information. This operation is fast, reversible, and no information is lost.

To deal with software that don’t work in physical space (ignores axis direction information, etc) you can export the segmentation into a labelmap volume. You can specify any volume as a reference volume and voxels will be resampled into that voxel grid. See [https://www.slicer.org/wiki/Documentation/Nightly/Modules/Segmentations](https://www.slicer.org/wiki/Documentation/Nightly/Modules/Segmentations) for details.

---

<div class="post-metadata">

**Author:** ![stevenagl12](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stevenagl12/32/3391_2.png) [@stevenagl12](https://discourse.slicer.org/u/stevenagl12)\
**Post date:** [October 23, 2017, 7:51pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/4 "2017-10-23T19:51:20Z")

</div>

How would you go about saving the volume that is transformed then?

---

<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:** [October 23, 2017, 9:14pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/5 "2017-10-23T21:14:58Z")

</div>

To resample volumes, use Resample Scalar Volume and similar resample modules.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [October 24, 2017, 5:14am UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/6 "2017-10-24T05:14:23Z")

</div>

Here is a summary of the great answers of @lassoan :

### What is the effect of Hardening linear transforms ?

> [@lassoan](#):
>
> Hardening linear transforms on volumes don’t require changing voxel values, you’ll only see result of hardening as an update in axis direction information. This operation is fast, reversible, and no information is lost.

### How to deal with software that don’t work in physical space ?

#### For segmentations

> [@lassoan](#):
>
> To deal with software that don’t work in physical space (ignores axis direction information, etc) you can export the segmentation into a labelmap volume. You can specify any volume as a reference volume and voxels will be resampled into that voxel grid. See [Documentation/Nightly/Modules/Segmentations - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/Modules/Segmentations) for details.

#### For Volumes

> [@lassoan](#):
>
> To resample volumes, use Resample Scalar Volume and similar resample modules.

---

<div class="post-metadata">

**Author:** ![Trang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/trang/32/12938_2.png) [@Trang](https://discourse.slicer.org/u/Trang)\
**Post date:** [September 10, 2021, 4:33pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/7 "2021-09-10T16:33:22Z")

</div>

Hi there, don’t know have you resolved your dilemma or not. I faced the same trouble when trying to save transformed model. It turned out that we need to select the files ( right click) in the transformed object box before hitting the hardening button. After clicking hardening, the files from the transformed object box will move back to the transformable box. Then you can save the transformed files.  
Hope it helps^^

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [February 24, 2022, 7:23am UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/8 "2022-02-24T07:23:21Z")

</div>

how to do harden transform using python script?

regards,  
Saima

---

<div class="post-metadata">

**Author:** ![ebrahim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ebrahim/32/13403_2.png) [@ebrahim](https://discourse.slicer.org/u/ebrahim)\
**Post date:** [February 24, 2022, 12:09pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/9 "2022-02-24T12:09:21Z")

</div>

Once you have a transformable node that has an associated transform (e.g. [like this](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#apply-a-transform-to-a-transformable-node)), you can call the `HardenTransform()` method on that node: `transformableNode.HardenTransform()`.

---

<div class="post-metadata">

**Author:** ![Tiberiu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tiberiu/32/66666_2.png) [@Tiberiu](https://discourse.slicer.org/u/Tiberiu)\
**Post date:** [June 13, 2023, 9:54am UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/10 "2023-06-13T09:54:54Z")

</div>

This does not work for me.

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [January 11, 2024, 4:12pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/11 "2024-01-11T16:12:09Z")

</div>

> [@lassoan](#):
>
> resample

Has anyone solved this issue? I want to transform a volume and create another one with the same size. So then I can export it in dcm format and open it with pydicom or export the slices in .npy format. How can I do it?

Now I’m:

1. Creating the transformation matrix and applying it with the Transformation module.
2. In data module right click and harden transform
3. Export as DICOM

---

<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:** [January 11, 2024, 5:04pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/12 "2024-01-11T17:04:13Z")

</div>

I don’t think there is an issue. There are many ways to apply a transform to a volume and you need to use the tools in Slicer that correspond to what you would like to achieve.

> I want to transform a volume and create another one with the same size.

Do you want to resample the transformed volume into the same geometry (origin, spacing, axis direction, and extents) as the original volume? Then you can use “Resample scalar/vector/DWI volume” module and set the original volume as “Reference volume” and set the transform as “Transform node”.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 11, 2024, 6:41pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/13 "2024-01-11T18:41:55Z")

</div>

> [@lassoan](#):
>
> Do you want to resample the transformed volume into the same geometry (origin, spacing, axis direction, and extents) as the original volume? Then you can use “Resample scalar/vector/DWI volume” module and set the original volume as “Reference volume” and set the transform as “Transform node”.

How do you deal with cases when the transformed volume gets cropped? Because this procedure takes the image size from the input node.

---

<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:** [January 11, 2024, 7:02pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/14 "2024-01-11T19:02:43Z")

</div>

You can create a larger target volume using the CropVolume module.

It would be an interesting feature to consider automatically creating a target volume that includes all of the transformed range of the volume, but I don’t think we have that.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 11, 2024, 7:05pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/15 "2024-01-11T19:05:28Z")

</div>

Yes, i tried that. it turns into a multi-step process, where you do one resample, notice that it is cut, use the CropVolume to expand in the regions where there is cut. Go back to resample, set the new volume as the reference volume, and repeat the procedure until FOV is no longer cut.

While it works, it is a quite tedious. Would be nice to automatically figure out what the resultant image size need to be.

---

<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:** [January 11, 2024, 7:15pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/16 "2024-01-11T19:15:23Z")

</div>

If you apply the transform to the volume you can look at it in the slice views and adjust the ROI to fit it, so it shouldn’t be too hard. But I agree, the process could be automated.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [January 11, 2024, 8:23pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/17 "2024-01-11T20:23:58Z")

</div>

It would be great, if this is actually a feature of CropVolume. A third option, which will create a resampled output image using the ROI.

Resample DWI has so many options that is intimidating to begin with.

---

<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:** [January 11, 2024, 10:31pm UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/18 "2024-01-11T22:31:14Z")

</div>

When you harden a transform on a volume, [Slicer performs this extent computation automatically](https://github.com/Slicer/Slicer/blob/d8c2d883412c0aaf7a6fa8dcfb3703d4dce91dae/Libs/MRML/Core/vtkMRMLVolumeNode.cxx#L892-L979). It takes into account all translation/rotarion/warping of the volume and does not compute the new extent based on only the 8 corners but many points on the bounding box of the volume.

This automatic extent computation is used by Crop volume module, too, when the “Fit to volume” button is pressed. However, when you transform and resample you most often want to cut into the volume (to cut off the wavy sides of the warped volume). Maybe what is needed would be to have an option to reset the ROI size without changing its orientation. Or maybe to have a minimal ROI option (where the ROI is the largest box that fits within the warped volume).

---

<div class="post-metadata">

**Author:** ![bserrano](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bserrano/32/17034_2.png) [@bserrano](https://discourse.slicer.org/u/bserrano)\
**Post date:** [January 15, 2024, 8:36am UTC](https://discourse.slicer.org/t/saving-transformed-volumes/1266/19 "2024-01-15T08:36:21Z")

</div>

Thanks, that’s what I wanted.  
I have another question. I’ve noticed that when I apply a transformation to a volume via the Transforms module, Slicer selects automatically a “Reformat” view in the red slice. How can I use this “Reformat” view as the axial view and save the volume accordingly?  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/f/9f871c4d639f4b23077fcb41c29ba98780ef8410.png)

Many thanks 🙂
