SkillAgentSearch skills...

SlicerPythonCLIExample

Example extension for 3D Slicer that demonstrates how to make a Python script available as a CLI module

Install / Use

/learn @lassoan/SlicerPythonCLIExample
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

SlicerPythonCLIExample

Example extension for 3D Slicer that demonstrates how to make a Python script available as a CLI module

Let's assume you have a BlurImage.py Python script that you can run from the command line as python BlurImage.py input.nrrd 5.0 output.nrrd. You can make this Python script available in Slicer using a nice auto-generated GUI just by adding a description of input and output parameters in a Slicer Execution Model module descriptor XML file: BlurImage.xml.

Once BlurImage folder is added to additional module paths (or the extension package is installed), "Blur Image" module will show up in the module list (in Filtering / Denoising category) and can be used in Slicer as any other module.

Auto-generated graphical user interface for Python script

The script can be executed from any other module, the same way as other CLI modules.

Example:

import SampleData
inputImage = SampleData.downloadSample('MRHead')
outputImage = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLScalarVolumeNode', inputImage.GetName()+' blurred')

param = {}
param["inputVolume"] = inputImage.GetID()
param["outputVolume"] = outputImage.GetID()
param["sigma"] = 3.0
slicer.cli.runSync(slicer.modules.blurimage, parameters=param)
View on GitHub
GitHub Stars20
CategoryDevelopment
Updated1y ago
Forks2

Languages

CMake

Security Score

75/100

Audited on Mar 27, 2025

No findings