I am hoping to write some python script that can work with the slicer software interactively to semi-automate the process of vessel segmentation and centerline extraction. Specifically, after loading a volume file into slicer, I want to prompt the user to drag the ROI box (in volume rendering module) around to define an ROI that contains the vessels of interest. Then I want to execute some script to automatically read the location of the ROI box, run my customised segmentation pipeline, and display the segmentation result on the running slicer window. Next, I will need the user to correct parts of the segmentation using eraser, paint, etc. Once this is done, the user may click some button to start the process of extracting the centerlines using the vmtk module in slicer automatically.
I understand that you can copy and paste your python script into the python console of a running slicer to automatically execute some tasks. However, this can be quite tedious when processing a lot of data or if the script is very long. Thus, I was wondering if I can just run a python script locally, which can interact with slicer by having the user clicking some buttons, and achieve the pipeline described above.
I am quite new to the python API of slicer and interactive programming in general. Thus, your suggestions will be highly appreciated!
You can achieve the functionality you mentioned by writing a script module. Write down your workflow in a UI-based manner, where you can complete your tasks by clicking pre-designed buttons in a specific order. You can learn how to write a script module to accomplish this.
On scripted modules: Extensions — 3D Slicer documentation
You can get started using the extension wizard
It can be helpful to look at examples that are in slicer: https://github.com/Slicer/Slicer/tree/main/Modules/Scripted
Since your workflow is interactive, you may consider ‘Quick artery segmentation’ module in SlicerVMTK extension, available via the extensions manager. It works with an ROI and can extract centerlines by remote controlling the ‘Extract centerline’ module.
Thank you for your suggestion. I tried searching for this module in the Extensions Manager but with no success. There does not seem to be any extension with ‘quick’ in its name at all. Do you know if the full name of the extension is just “Quick Artery Segmentation” or anything else?
You are mixing up ‘Extensions’ and ‘Modules’.
An extension is a collection of modules.
The extension name here is SlicerVMTK, which you will find in the ‘Extensions manager’. The latter does not search for modules in extensions, but for the extensions themselves.
Thank you very much for the clarification. I have installed the SlicerVMTK extension. However, when I looked for the quick artery segmentation module, it does not seem to be available. My Slicer version is 5.2.2 on MacOS. Do you know whether this is a compatibility problem or anything else?
It’s probably not finding the ‘FloodFilling’ effect of the ‘Segment editor’, it’s not a native effect that it requires. You should install the ‘SegmentEditorExtraEffects’ extension too.
It’s always a good idea to go through the application log (View/Error log) to have more information to resolve some runtime problems yourself, or to post here.
That worked. Thank you so much!