Cropping existing volume with ROI and shifting display via Python scripting

paleomariomm
Thu, 18 Jan 2024 15:51:15 +0000
Support

Hi community. I am writing a Python script to automate a pipeline that will be used in around 1000 CT scans.

Now I am able to load 1 DICOM folder and to display Volume rendering with Python

# Load DICOM files
  # https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#dicom
dicomDataDir = "C:/Users/mario.modesto/Desktop/DICOM/W111"  # input folder with DICOM files
loadedNodeIDs = []  # this list will contain the list of all loaded node IDs

from DICOMLib import DICOMUtils
with DICOMUtils.TemporaryDICOMDatabase() as db:
  DICOMUtils.importDicom(dicomDataDir, db)
  patientUIDs = db.patients()
  for patientUID in patientUIDs:
    loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUID))

# Display volume rendering
# https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#display-volume-using-volume-rendering
logic = slicer.modules.volumerendering.logic()
volumeNode = slicer.mrmlScene.GetNodeByID('vtkMRMLScalarVolumeNode1')
displayNode = logic.CreateVolumeRenderingDisplayNode()
displayNode.UnRegister(logic)
slicer.mrmlScene.AddNode(displayNode)
volumeNode.AddAndObserveDisplayNodeID(displayNode.GetID())
logic.UpdateDisplayNodeFromVolumeNode(displayNode, volumeNode)

However, I would like to know, in my progress, two things I am struggling right now. When volume rendering is shown, it is almost all black.

Therefore, I need to move to right the Shift option in Display to show the skull.

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.

How can it be done?

Best

5 posts - 3 participants