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

**URL:** https://discourse.slicer.org/t/slicer-batch-processing-question-no-main-window-python-script/1863
**Category:** Support
**Tags:** python, batch
**Created:** [January 17, 2018, 4:06pm UTC](https://discourse.slicer.org/t/slicer-batch-processing-question-no-main-window-python-script/1863 "2018-01-17T16:06:41Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![NaglisR](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/naglisr/32/16280_2.png) [@NaglisR](https://discourse.slicer.org/u/NaglisR)
#### Post date: [January 17, 2018, 4:06pm UTC](https://discourse.slicer.org/t/slicer-batch-processing-question-no-main-window-python-script/1863/1 "2018-01-17T16:06:41Z")

</div>

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](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:

```auto
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

---

<div class="post-metadata">

### Author: ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)
#### Post date: [January 17, 2018, 4:19pm UTC](https://discourse.slicer.org/t/slicer-batch-processing-question-no-main-window-python-script/1863/2 "2018-01-17T16:19:12Z")

</div>

There’s a module for a similar task

> **[SlicerRT/BatchProcessing at master · SlicerRt/SlicerRT](https://github.com/SlicerRt/SlicerRT/tree/master/BatchProcessing)**
>
> master/BatchProcessing

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.

---

<div class="post-metadata">

### Author: ![NaglisR](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/naglisr/32/16280_2.png) [@NaglisR](https://discourse.slicer.org/u/NaglisR)
#### Post date: [January 17, 2018, 4:34pm UTC](https://discourse.slicer.org/t/slicer-batch-processing-question-no-main-window-python-script/1863/3 "2018-01-17T16:34:58Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)
#### Post date: [January 17, 2018, 11:03pm UTC](https://discourse.slicer.org/t/slicer-batch-processing-question-no-main-window-python-script/1863/4 "2018-01-17T23:03:14Z")

</div>

This module does something similar to what you want to do: [https://github.com/SlicerProstate/mpReview/blob/master/mpReviewPreprocessor.py](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](https://github.com/SlicerProstate/mpReview).

---

<div class="post-metadata">

### Author: ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)
#### Post date: [January 18, 2018, 1:31am UTC](https://discourse.slicer.org/t/slicer-batch-processing-question-no-main-window-python-script/1863/5 "2018-01-18T01:31:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Davide\_Punzo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/davide_punzo/32/66104_2.png) [@Davide\_Punzo](https://discourse.slicer.org/u/Davide_Punzo)
#### Post date: [January 19, 2018, 4:28pm UTC](https://discourse.slicer.org/t/slicer-batch-processing-question-no-main-window-python-script/1863/6 "2018-01-19T16:28:33Z")

</div>

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](http://slicer-devel-archive.65872.n3.nabble.com/Slicer-batch-mode-td4033551.html))

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [January 19, 2018, 4:59pm UTC](https://discourse.slicer.org/t/slicer-batch-processing-question-no-main-window-python-script/1863/7 "2018-01-19T16:59:57Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)
#### Post date: [January 19, 2018, 9:24pm UTC](https://discourse.slicer.org/t/slicer-batch-processing-question-no-main-window-python-script/1863/8 "2018-01-19T21:24:42Z")

</div>

> [@Davide\_Punzo](#):
>
> Slicer in batch mode (on a cluster)

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