Hello everyone,
I am currently working on my engineering thesis and I am developing a module for 3D Slicer that aims to detect and segment blood vessels from CT scan images. This module will be part of my research project, and my goal is to automate the process of extracting vascular structures from medical imaging data.
At the moment, I am in the early stages of the project, and I have written some code that allows me to segment the blood vessels from CT images. I would greatly appreciate any feedback or suggestions regarding my approach.
Below is the code I have written so far. If anyone has experience with blood vessel segmentation or working with medical image data in 3D Slicer, your help in reviewing and improving this code would be invaluable.
# Retrieve the volume node
volumeNode = slicer.util.getNode("CTChest") # Replace with your volume node's actual name
if not volumeNode:
raise ValueError("Volume node 'CTChest' not found. Check the name and ensure it's loaded into the scene.")
# Create a new segmentation node
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentationNode.CreateDefaultDisplayNodes() # Ensure display nodes are initialized
# Initialize the Segment Editor
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorWidget.setSegmentationNode(segmentationNode)
# Explicitly set the Master Volume Node
segmentEditorWidget.setMasterVolumeNode(volumeNode)
# Debugging: Ensure the Master Volume Node is set correctly
if not segmentEditorWidget.masterVolumeNode():
raise RuntimeError("Master volume node is not set correctly in the Segment Editor Widget.")
# Activate the Threshold effect
segmentEditorWidget.setActiveEffectByName("Threshold")
effect = segmentEditorWidget.activeEffect()
if effect:
print("Threshold effect activated successfully!")
# Set threshold values
effect.setParameter("MinimumThreshold", "100") # Replace with your desired lower threshold
effect.setParameter("MaximumThreshold", "300") # Replace with your desired upper threshold
effect.self().onApply() # Apply the threshold effect
print("Threshold segmentation applied successfully.")
else:
raise RuntimeError("Failed to activate the Threshold effect. Check Slicer configuration and plugins.")
# Optional: Smooth the segmentation to refine it
segmentEditorWidget.setActiveEffectByName("Smoothing")
effect = segmentEditorWidget.activeEffect()
if effect:
effect.setParameter("SmoothingMethod", "Gaussian")
effect.setParameter("KernelSizeMm", "1.5")
effect.self().onApply()
print("Smoothing applied successfully.")
else:
print("Smoothing effect could not be activated.")
# Finalize (clean up resources)
segmentEditorWidget = None
Thank you in advance for any help you can provide!