# 3D slicer's segmented output for convolutional neural network training 

**URL:** <https://discourse.slicer.org/t/3d-slicers-segmented-output-for-convolutional-neural-network-training/14000>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [October 12, 2020, 2:28pm UTC](https://discourse.slicer.org/t/3d-slicers-segmented-output-for-convolutional-neural-network-training/14000 "2020-10-12T14:28:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abdulrahman](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Abdulrahman](https://discourse.slicer.org/u/Abdulrahman)\
**Post date:** [October 12, 2020, 2:28pm UTC](https://discourse.slicer.org/t/3d-slicers-segmented-output-for-convolutional-neural-network-training/14000/1 "2020-10-12T14:28:45Z")

</div>

Hi all,  
I’m working on the field of brain segmentation using convolutional neural network CNN. I have already segmented the brain regions on Slicer, so now I want to export the input images(DICOM) and its corresponding outputs as 3D for CNN training.  
How I can perform that ?

Any idea will be appreciated

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:** [October 12, 2020, 2:33pm UTC](https://discourse.slicer.org/t/3d-slicers-segmented-output-for-convolutional-neural-network-training/14000/2 "2020-10-12T14:33:17Z")

</div>

I would recommend saving both the CT and segmentation into nrrd or nifti format that you can easily read into numpy array and use in your network.

---

<div class="post-metadata">

**Author:** ![Abdulrahman](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Abdulrahman](https://discourse.slicer.org/u/Abdulrahman)\
**Post date:** [October 12, 2020, 11:17pm UTC](https://discourse.slicer.org/t/3d-slicers-segmented-output-for-convolutional-neural-network-training/14000/3 "2020-10-12T23:17:33Z")

</div>

Thanks Mr Lassoan,  
Is there any tool or module can export/save the files into nifti format in Slicer. By the way, I’m using Matlab.

Secondly, Should I perform registration for the MRI and its corresponding segmentation ?

Kind regards

---

<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:** [October 12, 2020, 11:33pm UTC](https://discourse.slicer.org/t/3d-slicers-segmented-output-for-convolutional-neural-network-training/14000/4 "2020-10-12T23:33:44Z")

</div>

> [@Abdulrahman](#):
>
> Is there any tool or module can export/save the files into nifti format in Slicer

No need for a module, you can run `slicer.util.saveNode` to save an image in nifti format.

> [@Abdulrahman](#):
>
> By the way, I’m using Matlab.

I’m not sure this is the best idea: you cannot implement complete applications in Matlab, it is only affordable for academic use, and in general you just make your life harder by not using the same toolsets that most machine learning experts . For example, if you use tensorflow, pytorch, etc. then you can run training or inference directly within Slicer’s Python environment. You can interface Slicer with Matlab, too, but there are several additional layers and inconveniences.

> [@Abdulrahman](#):
>
> Should I perform registration for the MRI and its corresponding segmentation ?

If you segment an image then the resulting segmentation will be spatially aligned with it in physical space (and in most cases, you choose the segmentation to have the exact same geometry as the input image). Therefore, there should be no need for any additional registration step.

---

<div class="post-metadata">

**Author:** ![Abdulrahman](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Abdulrahman](https://discourse.slicer.org/u/Abdulrahman)\
**Post date:** [October 12, 2020, 11:57pm UTC](https://discourse.slicer.org/t/3d-slicers-segmented-output-for-convolutional-neural-network-training/14000/5 "2020-10-12T23:57:08Z")

</div>

Thanks you so much for your perfect explanation.

---

<div class="post-metadata">

**Author:** ![Abdulrahman](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Abdulrahman](https://discourse.slicer.org/u/Abdulrahman)\
**Post date:** [October 14, 2020, 5:22am UTC](https://discourse.slicer.org/t/3d-slicers-segmented-output-for-convolutional-neural-network-training/14000/6 "2020-10-14T05:22:32Z")

</div>

[No need for a module, you can run `slicer.util.saveNode` to save an image in nifti format.]

Sorry Mr Lassoan for keep asking, Can I save only the visible segments into nifti file?.  
If yes, Is it like what I’ve attached.

Thanks again ![Picture1](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/2/622a5e82683da71fd8ad34aabd958402a9612aba.jpeg)

---

<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:** [October 15, 2020, 5:25am UTC](https://discourse.slicer.org/t/3d-slicers-segmented-output-for-convolutional-neural-network-training/14000/7 "2020-10-15T05:25:44Z")

</div>

You can use “Export to files…” feature in Segment Editor module (“Segmentations…” button’s dropdown menu). Use latest Slicer Stable Release.
