I am new to slice and working on incorporating our own 3D segmentation model with slicer. And we would like to assume the slicer user does not know anything about code, so intend to write a python CLI code to do everything. I am wondering is it possible? If not, can you provide me some lights that what should I do?
But I would like to use this external python code (note not the interpreter provided in slicer) to render /plot/show the segmentation mask in slicer, is it possible? I know how to do this with the interpreter provided in slicer but not sure whether I can do this with totally external python code?
I don’t know how to edit the original post so I reply here.
After more search, I think CLI is designed to not interact with slicer core. I find an alternative way to do it.
I only want the computed label map to be received by Slicer, currently, I did this by return the label map as a grayscale volume and convert it manually through the volume module. Is there a way to explicitly denote the returned object as a label map in Slicer Execution Model?
CLI modules are Python scripts or command-line applications that do not rely on Slicer. They can be executed within Slicer’s environment or without Slicer. What Slicer offers is displaying automatically-generated GUI, writing all inputs to file, executing the application, continuous progress reporting, and in the end reading back all outputs into the scene.
The automatically generated GUI is typically convenient enough for development, testing, and research/engineering use. For clinical use, often a Python scripted loadable module is developed as a front-end, which provides a more sophisticated GUI and calls the CLI module in the background.
To designate an output image as labelmap, specify type="label", as it is done for example in ModelToLabelMap module:
BTW, on MAC, I cannot install packages through the python interaction by “pip.main([…])”
AttributeError: ‘PythonQtStdInRedirect’ object has no attribute ‘isatty’ this error occurs and it seems to have something to do with the mac python framework.
You need to activate Slicer’s Python environment before you can run any Python executables (this is required in any other Python or Conda virtual environments, too). You can activate the Slicer Python environment for an executable by launching it using the PythonSlicer launcher (it sets up the Python enrivonment and starts the executable).
However, most Python executables just call python -m ModuleName ..., so instead of using that executable, it is simply to directly run PythonSlicer -m ModuleName .... This is what the slicer.util.pip_install convenience function calls internally:
Installing the required Python packages is easier, because you don’t need to ask your users to set up a new Python environment.