Python - Get Node copy to Modify

I want to modify a copy of the input node and output it. I’m not being able to do that without modifying the input node. How to make a copy?

What kind of node do you want to copy? What do you mean that the input is modified?

Maybe look at vtkSlicerVolumesLogic::CloneVolume

I’m using python. I want to extract a numpy array from a volumeNode (CT Scan) and apply my modifications and then deploy in a different node but with the same characteristics as the input Volume. I’m not being able to ‘clone’ the volume. It always refer to the same data array and it modifies both input and output volume node

ok, so using this:

outputVolume = slicer.vtkSlicerVolumesLogic().CloneVolume(inputVolume,'out')

arr = vtk_to_numpy(outputVolume.GetImageData().GetPointData().GetScalars())

results in

:‘NoneType’ object has no attribute ‘GetImageData’

CloneVolume only works for scalar volume. Use CloneVolumeGeneric() method to clone other types of volumes.

1 Like

This worked:

outputVolume = slicer.vtkSlicerVolumesLogic().CloneVolume(slicer.mrmlScene,inputVolume,‘out’,True)

Thanks @lassoan and @pieper . Great job!

1 Like