How to write the code for resample in 3D slicer

Hi all,

Does anyone know what is the correct code for resampling and resave the volume file as mhd format?
Basically, what I have is a nrrd file named disp, a reference nrrd file named ref, and a tranform file named tran.
I would like to go to the module of ’ Resample Scalar/Vector/DWI Volume’ and output a new vector volume, and save this new output vector volume as mhd format.
image


This is what I used.

############# save as mhd file
parameters = {}
parameters[‘inputVolume’] = slicer.util.getNode(‘DISP’)
#Set output as vector volume
parameters[‘outputVolume’] = slicer.util.getNode(‘DISP’)
parameters[‘referenceVolume’] = slicer.util.getNode(REF)
parameters[‘transformationFile’] = slicer.util.getNode(‘TRAN’)
parameters[‘interpolationType’] = interpolationType

cliNode = slicer.cli.runSync(slicer.modules.resamplescalarvectordwivolume,None,parameters)

volumeNode = slicer.mrmlScene.GetFirstNodeByClass(‘vtkMRMLScalarVolumeNode’)
slicer.util.saveNode(volumeNode , outputDisplacementfield_resampled,{“useCompression”: 0})

But this is wrong, I am so confused that I can not get the correct output from my code. Does anyone help me to check my code?

Thanks for any kinds of discussion and help.
Best,
Chuan

I use below code, and seems work!

############# save as mhd file
outputVectorNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLVectorVolumeNode”)
outputVectorNode.SetName(‘disp_PIPER_skinskel_afterDemons_afterresample’)

parameters = {}
parameters[‘inputVolume’] = slicer.util.getNode(‘disp_PIPER_skinskel_afterDemons’)
#Set output as vector volume
parameters[‘outputVolume’] = slicer.util.getNode(‘disp_PIPER_skinskel_afterDemons_afterresample’)
parameters[‘referenceVolume’] = slicer.util.getNode(name_ref)
parameters[‘transformationFile’] = slicer.util.getNode(‘LinearTransform_3’)
parameters[‘interpolationType’] = interpolationType

cliNode = slicer.cli.runSync(slicer.modules.resamplescalarvectordwivolume,None,parameters)

slicer.util.saveNode(outputVectorNode, outputDisplacementfield_resampled,{“useCompression”: 0})