Slicer batch processing question (--no-main-window --python-script)

Hi everyone,

I am trying to find the best way to quickly batch process a number of folders containing head MRI dicom files to .nii files. Basically the pipeline should work like this: import the dicom files > load them as a volume > save the volume as a .nii file.
I am trying to do this using the slicer from terminal: Slicer --no-main-window --python-script (as is described in here https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#How_to_access_a_scripted_module_from_python_scripts)
The python script goes like this:

i = ctk.ctkDICOMIndexer()
i.addDirectory(slicer.dicomDatabase, '/home/me/Documents/25/25')

How can I do the next necessary steps to load the dicom files as volumes and save them as .nii files?

Thank you in advance

There’s a module for a similar task

Your use case seems to be simpler than this, and most of it is contained in this module. What you need to implement in addition is the one-line command to save the loaded volume as nii.

Thank you for your response. What I am looking for is ways to batch process multiple files through scripting with python. Perhaps there is some tutorial or a wiki page about this kind of processing? For example, I am not able to find the command to load the imported dicom files as a volume (without the Slicer GUI because I need to to do it as a batch script). Later on I will probably need to batch process more than just loading and saving.

This module does something similar to what you want to do: https://github.com/SlicerProstate/mpReview/blob/master/mpReviewPreprocessor.py. Readme file here is all the documentation that we have, unfortunately: https://github.com/SlicerProstate/mpReview.

Have you seen my answer above? It is I think exactly what you need.

Hi all,

I have a related question :

it is not possible to run Slicer in batch mode (on a cluster) to make video of the volume rendering using the module Screen Capture, isn’t it? I guess for the rendering is needed to load the GUI to init the 3DView, isn’t it?

Moreover, (by running with only the option --python-script) Do I need to install VirtualGL and turbovnc?

(additional reference http://slicer-devel-archive.65872.n3.nabble.com/Slicer-batch-mode-td4033551.html)

Screen Capture module requires Slicer application GUI. The GUI may not need to be visible, but at least windows need to be created.

1 Like

Images built off GitHub - thewtex/docker-opengl: A docker image that supports rendering graphical applications. should be helpful. This what we is (will be) used for running Slicer tests on CircleCI

1 Like