# Using Resample Scalar/Vector/DWI Volume in python

**URL:** <https://discourse.slicer.org/t/using-resample-scalar-vector-dwi-volume-in-python/38271>\
**Category:** Development\
**Tags:** python, resample, slicing, reslicing\
**Created:** [September 8, 2024, 3:18am UTC](https://discourse.slicer.org/t/using-resample-scalar-vector-dwi-volume-in-python/38271 "2024-09-08T03:18:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lord\_bubbacub](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@lord\_bubbacub](https://discourse.slicer.org/u/lord_bubbacub)\
**Post date:** [September 8, 2024, 3:18am UTC](https://discourse.slicer.org/t/using-resample-scalar-vector-dwi-volume-in-python/38271/1 "2024-09-08T03:18:38Z")

</div>

# [Resample Scalar/Vector/DWI Volume — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/user_guide/modules/resamplescalarvectordwivolume.html)

Hi I’m trying to automate use of the resamplescalarvectordwivolume using python in the slicer console. My operation involves rescaling a ct based volume to match the geometry of a registered mri volume. The operation I am trying to do works great using the GUI but I am not making any progress on using this module in python. I’ve tried the docs and forums but have only found examples related to the older deprecated resample scalar volume module which does not work on my data sets.

I’ve got a few hundred operations to perform so would value being able to do this programatically.

My current code is below. The transform is a (previously computed) transform that is applied to register the CT binary labelmap to the MRI. The croppedCT input is cropped to match the exact volume of the mri volume (using ROI tools within python)

```
reslicedVolumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode", final_output)
parameters = {
    "inputVolume":croppedCT.GetID(),
    "interpolationType":'nn',
    "referenceVolume": mriNode.GetID(),
    "outputVolume":reslicedVolumeNode.GetID(),
    "transformationFile":loadedTransform.GetID()}

res = slicer.cli.run(slicer.modules.resamplescalarvectordwivolume, parameters)

```

I would really value some help in finding out how to use the amazing features of this module within python.

Thanks in advance!

---

<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:** [September 8, 2024, 4:00pm UTC](https://discourse.slicer.org/t/using-resample-scalar-vector-dwi-volume-in-python/38271/2 "2024-09-08T16:00:40Z")

</div>

`slicer.cli.run` operates in a thread. Try `runSync` instead?

> <https://github.com/PerkLab/SlicerSandbox/blob/8c2da5d800018289a53bade31802650113140f2c/CurvedPlanarReformat/CurvedPlanarReformat.py#L436-L446>

---

<div class="post-metadata">

**Author:** ![lord\_bubbacub](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@lord\_bubbacub](https://discourse.slicer.org/u/lord_bubbacub)\
**Post date:** [September 8, 2024, 5:44pm UTC](https://discourse.slicer.org/t/using-resample-scalar-vector-dwi-volume-in-python/38271/3 "2024-09-08T17:44:53Z")

</div>

Thank you. That’s magic, Problem solved.  
I wonder if the docs could be improved with some basic information on using this module within python and 3d slicer.

---

<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:** [September 8, 2024, 6:05pm UTC](https://discourse.slicer.org/t/using-resample-scalar-vector-dwi-volume-in-python/38271/4 "2024-09-08T18:05:23Z")

</div>

> [@lord\_bubbacub](#):
>
> I wonder if the docs could be improved

Yes, please make any suggestions as a [pull request on the docs](https://github.com/Slicer/Slicer/blob/main/Docs/index.md).
