Using Resample Scalar/Vector/DWI Volume in python

Resample Scalar/Vector/DWI Volume — 3D Slicer documentation

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!

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

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.

Yes, please make any suggestions as a pull request on the docs.