How to write a recursive script to crop volumes with ROI?


(Jenaflex) #1
  1. How to write recursive script to run ‘crop volume’ (like attached screenshot) on all 3D volumes (3D volumes extracted from 4D nifti)? I have ‘UtBox.acsv’ ROI file already.

  2. (Am I supposed to, OR, ) how to make function call ‘slicer.modules.cropvolume’ in built-in Python console to crop 3D volumes with ROI (instead of using GUI).
    The documentation seems to be very limited.

Thanks!


(Jenaflex) #2

Up. Please help. Thanks!


(Steve Pieper) #3

You could start by looking at the SlicerCaseIterator. Once you can iterate through your volumes you could add some code to do the cropping. I agree it’s not well documented but the building blocks are there and you can see example scripts.


(Jenaflex) #4

Thanks!
I think I should be able to figure out iteration method.
My main concern is how to call cropvolume function with input ROI being UtBox ROI file (like the screenshot).


(Simon Oxenford) #5

Hi, this is a part of a script I used to call cropvolume from a python script:

parameters = slicer.vtkMRMLCropVolumeParametersNode()
slicer.mrmlScene.AddNode(parameters)

parameters.SetInputVolumeNodeID(input.GetID())
parameters.SetOutputVolumeNodeID(output.GetID())
parameters.SetROINodeID(roiNode.GetID())
slicer.modules.cropvolume.logic().Apply(parameters)