# Script transform application

**URL:** <https://discourse.slicer.org/t/script-transform-application/26509>\
**Category:** Development\
**Tags:** transforms\
**Created:** [November 30, 2022, 1:39pm UTC](https://discourse.slicer.org/t/script-transform-application/26509 "2022-11-30T13:39:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_Tempier](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nicolas_tempier/32/17463_2.png) [@Nicolas\_Tempier](https://discourse.slicer.org/u/Nicolas_Tempier)\
**Post date:** [November 30, 2022, 1:39pm UTC](https://discourse.slicer.org/t/script-transform-application/26509/1 "2022-11-30T13:39:20Z")

</div>

Operating system: Linux Mint  
Slicer version: 5.0.3

Hi,  
I have a transforms file (from ANTs registration) .mat and I would like to script the application of this transform via slicer on another image. When I was using CLI modules I could get the bash code and adapt it but with the transforms module, I can’t script the application of the transform on the image I want. How to do it please?  
Thanks already,

N.

---

<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:** [December 1, 2022, 1:52am UTC](https://discourse.slicer.org/t/script-transform-application/26509/2 "2022-12-01T01:52:18Z")

</div>

There are CLI modules for applying transforms on an image. For example, you can use “Resample Scalar/Vector/DWI volume” - it is the `.../Slicer 5.0.3/bin/../lib/Slicer-5.0/cli-modules/ResampleScalarVectorDWIVolume.exe`.

You can use loadable modules via the module logic class. For example, you can use the Crop volume module for applying a transform to a volume, along with cropping and resampling as shown in this [code snippet in the script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#fit-markups-roi-to-volume).

---

<div class="post-metadata">

**Author:** ![Nicolas\_Tempier](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nicolas_tempier/32/17463_2.png) [@Nicolas\_Tempier](https://discourse.slicer.org/u/Nicolas_Tempier)\
**Post date:** [December 7, 2022, 10:13am UTC](https://discourse.slicer.org/t/script-transform-application/26509/3 "2022-12-07T10:13:05Z")

</div>

Thanks !  
Sort of works 🙂  
I don’t really understand how for example the ResampleScalarVectorDWIVolume.exe module interprets  
the ROI to create a transform that crops but it works !

---

<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 7, 2023, 5:52am UTC](https://discourse.slicer.org/t/script-transform-application/26509/4 "2023-02-07T05:52:44Z")

</div>

> [@lassoan](#):
>
> for applying a transform to a volume, along with cropping and resam

Hi Andras,  
How to get the invert transform and then apply it onto a volume using python scripting.

regards,  
Saima

---

<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:** [February 7, 2023, 1:39pm UTC](https://discourse.slicer.org/t/script-transform-application/26509/5 "2023-02-07T13:39:36Z")

</div>

You can invert a transform node by calling the `Inverse()` method. You can apply a transform as shown [here](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#apply-a-transform-to-a-transformable-node).
