# How to segment multiple volumes at once?

**URL:** <https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [February 15, 2020, 6:23pm UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280 "2020-02-15T18:23:22Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xi\_Fang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xi_fang/32/6041_2.png) [@Xi\_Fang](https://discourse.slicer.org/u/Xi_Fang)\
**Post date:** [February 15, 2020, 6:23pm UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280/1 "2020-02-15T18:23:22Z")

</div>

Currently I can make use of Clara model in 3D slicer to segment CT scans one by one. But I have tens of scans to segment. Loading and segmenting take a lot of time. Thus I wonder if I can segment tens of volumes at once and save all segmentation files?

Thanks!

---

<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:** [February 15, 2020, 6:29pm UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280/2 "2020-02-15T18:29:55Z")

</div>

You can load data and run automatic segmentation using a couple of lines of Python code. See examples in the [script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_run_segment_editor_effects_from_a_script). You may find “[AI-assisted brain tumor segmentation](https://gist.github.com/lassoan/ef30bc27a22a648ead7f82243f5cc7d5)” particulary relevant.

---

<div class="post-metadata">

**Author:** ![Xi\_Fang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xi_fang/32/6041_2.png) [@Xi\_Fang](https://discourse.slicer.org/u/Xi_Fang)\
**Post date:** [February 16, 2020, 12:08am UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280/3 "2020-02-16T00:08:05Z")

</div>

Thanks for your reply. I’ll try that!

---

<div class="post-metadata">

**Author:** ![Xi\_Fang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xi_fang/32/6041_2.png) [@Xi\_Fang](https://discourse.slicer.org/u/Xi_Fang)\
**Post date:** [February 16, 2020, 1:27am UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280/4 "2020-02-16T01:27:57Z")

</div>

Thank you for your great job. I modified the code in your second link. Now I can segment and visualize the liver organ. However, I didn’t know how to save the segmentation file into ‘nii’ format. The segmentationNode seems to be ‘MRMLCorePython.vtkRMLSegmentationNode’. When I try to save it using ‘slicer.util.saveNode’, it always return ‘False’. Looking forward to your response!

---

<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:** [February 16, 2020, 4:50am UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280/5 "2020-02-16T04:50:44Z")

</div>

Nifti is developed for neuroimaging and for that it is a good choice, but it has several disadvantages when you try to use it as a general-purpose image file format.

Instead, I would recommend to use nrrd format. It has simple, human-readable header, can be easily customized to store custom fields, it has better support for multidimensional images, etc.

If you absolutely must use nifti (again, I would not recommend) then export the segmentation to binary labelmap and then you can save that in any format you want, including nifti.

---

<div class="post-metadata">

**Author:** ![Xi\_Fang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xi_fang/32/6041_2.png) [@Xi\_Fang](https://discourse.slicer.org/u/Xi_Fang)\
**Post date:** [February 16, 2020, 5:23am UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280/6 "2020-02-16T05:23:11Z")

</div>

Thanks for your quick response. The nrrd format works.

---

<div class="post-metadata">

**Author:** ![Xi\_Fang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xi_fang/32/6041_2.png) [@Xi\_Fang](https://discourse.slicer.org/u/Xi_Fang)\
**Post date:** [February 23, 2020, 2:56pm UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280/7 "2020-02-23T14:56:12Z")

</div>

Hi, Lasso,  
I try to use Clara model to segment my local CT data. But currently, it doesn’t work now. The error is shown as below. Do you have any idea about that?  
http.client.RemoteDisconnected: Remote end closed connection without response

---

<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:** [February 23, 2020, 3:20pm UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280/8 "2020-02-23T15:20:36Z")

</div>

There was a few-hour server outage yesterday and NVidia updated their extension in the last few days - any of these might have caused problems.

Which Slicer version are you using? Did the same version worked before? Do you use your own Clara server or the default Slicer server?

---

<div class="post-metadata">

**Author:** ![Xi\_Fang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xi_fang/32/6041_2.png) [@Xi\_Fang](https://discourse.slicer.org/u/Xi_Fang)\
**Post date:** [February 23, 2020, 3:34pm UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280/9 "2020-02-23T15:34:29Z")

</div>

I use 3D slicer 4.11.0-2020-02-12 and the default slicer server.

---

<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:** [February 23, 2020, 6:27pm UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280/10 "2020-02-23T18:27:35Z")

</div>

The server has been working well for months but today there seems to be some network connectivity issues with the server. The service should be restored soon or you can set up your own server.

---

<div class="post-metadata">

**Author:** ![Xi\_Fang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xi_fang/32/6041_2.png) [@Xi\_Fang](https://discourse.slicer.org/u/Xi_Fang)\
**Post date:** [February 25, 2020, 3:57pm UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280/11 "2020-02-25T15:57:18Z")

</div>

Thank you. It seems the environment has been restored. However, there is still one volume that can’t be segmented. It may due to the large size of the volume. By the way, Do you have idea if I want to use the Clara model when using in publication. I didn’t find any citation online.

---

<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:** [February 25, 2020, 6:31pm UTC](https://discourse.slicer.org/t/how-to-segment-multiple-volumes-at-once/10280/12 "2020-02-25T18:31:55Z")

</div>

> [@Xi\_Fang](#):
>
> However, there is still one volume that can’t be segmented.

You need to crop and resample input volume to approximately match inputs used for training.

> [@Xi\_Fang](#):
>
> Do you have idea if I want to use the Clara model when using in publication. I didn’t find any citation online.

I would refer to it as “NVidia Clara AIAA (NVidia, Santa Clara, California, U.S.A.) + the used model’s name” and also cite [papers](https://docs.nvidia.com/clara/aiaa/tlt-mi-ai-an-sdk-getting-started/#aiaa_segmentation_models) that describe how the models were trained, and of course [3D Slicer](https://www.slicer.org/wiki/CitingSlicer).
