How han I introduce in the Python code a different shift value?
Next, as you can see in the CT, there is a platform below the skull, of approximate 2-3 cm. In all my scans this platform exists. So I would like to remove it by cropping this volume (and generating another _cropped) by using ROI.
I tried cropping in empty volume, which is a script in the Slicer documentation. But I do not know how can I apply to an existing volume and creating another.
When you are converting/processing 1000s of files, you do not want to interactively do anything, including visualization. So for your purposes visualization step is probably not necessary and will add additional time to your pipeline (but it is total fine, if you are using as a way to learn scripting).
First thing I would do is to interactively create a ROI box from that will crop most of the foam out in one sample, save it to disk, and reload and test it interactively with few other samples to get a sense of how consistent the sample placement, and whether you can use this fixed size ROI for most (if not all) of your samples. If the answer is no (samples have different orientation, origins etc), you will have to find a heuristic that will get you to crop box automatically. This might involve fitting an ROI to the volume, and then reducing in the I plane a few centimeters (again if all your samples are consistently oriented).
this example here shows how to load NRRD file and fit a ROI and resample it to a lower resolution. You can modify it to fit your needs (namely modify the dimensions of the ROI box).
# find the files NodeID
volumeNode = getNode('2: Facial Bones 0.75 H70h')
#create a blank Markup ROI
roiNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsROINode")
#set the new markup ROI to the dimensions of the volume
cropVolumeParameters = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLCropVolumeParametersNode")
cropVolumeParameters.SetInputVolumeNodeID(volumeNode.GetID())
cropVolumeParameters.SetROINodeID(roiNode.GetID())
slicer.modules.cropvolume.logic().SnapROIToVoxelGrid(cropVolumeParameters) # optional (rotates the ROI to match the volume axis directions)
slicer.modules.cropvolume.logic().FitROIToInputVolume(cropVolumeParameters)
slicer.mrmlScene.RemoveNode(cropVolumeParameters)
#set the cropping parameters
cropVolumeLogic = slicer.modules.cropvolume.logic()
cropVolumeParameterNode = slicer.vtkMRMLCropVolumeParametersNode()
cropVolumeParameterNode.SetIsotropicResampling(True)
You have to look up the API, I don’t actually know the python call to set the ROI bounds @lassoan?
But if you are certain that orientation is consistent, then you don’t have to recreate the ROI every time and fit to the volume. I would adjust one manually, save it, and write the script in a way that will use it (load from the disk).
As @muratmaga said, a saved ROI might be the best approach.
I had a more or less similar workflow with CT angiograms and came up with a custom script. You may find some insight here to set Window/Level, load a known ROI from disk and apply cropping. Full automation should be possible the way you laid out the problem.