# Export segmentation results (3d labels) to multiple 2d images (for deep learning training)?

**URL:** <https://discourse.slicer.org/t/export-segmentation-results-3d-labels-to-multiple-2d-images-for-deep-learning-training/3197>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [June 15, 2018, 4:12pm UTC](https://discourse.slicer.org/t/export-segmentation-results-3d-labels-to-multiple-2d-images-for-deep-learning-training/3197 "2018-06-15T16:12:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaowei](https://avatars.discourse-cdn.com/v4/letter/x/76d3ee/32.png) [@xiaowei](https://discourse.slicer.org/u/xiaowei)\
**Post date:** [June 15, 2018, 4:12pm UTC](https://discourse.slicer.org/t/export-segmentation-results-3d-labels-to-multiple-2d-images-for-deep-learning-training/3197/1 "2018-06-15T16:12:59Z")

</div>

I use Slicer to segment CT/MRI images. Currently I would like to try deep learning on medical image segmentation.

For deep learning, we need to prepare the training data first. Particularly, if we have 200 images for one CT (then the input is 200_height_width), then we need a labeled image set for this CT and it also has 200 images (200_height_width).

The problem is I can manually segment the CT now. However, do anyone know how to export the segmented results (e.g., the input is 200_height_width) to a 2d image set (e.g., 200 images and their dimension is height\*width)?  
(exporting it to stl and than performing slicing is a choice but is inconvenient and time-consuming)

I have just used Slicer for 3 months, and thank you for your help.

---

<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:** [June 15, 2018, 4:27pm UTC](https://discourse.slicer.org/t/export-segmentation-results-3d-labels-to-multiple-2d-images-for-deep-learning-training/3197/2 "2018-06-15T16:27:34Z")

</div>

I’m not sure that dumping image slices into series of 2D files would be the best approach. Consumer file formats (jpeg, png, etc.) are not well suited for storing metadata that is very common for medical image computing (axis directions, origin, pixel and slice spacing), they may not support 16-bit grayscale images, etc.

I would recommend to have a look at existing approaches for file storage, data normalization, and augmentation for deep learning in medical images.

@raul’s group using HDF file format for deep learning, which allows structure storage of 3D medical images (including all metadata, arbitrary pixel type, etc).

You may check out [DeepInfer](http://www.deepinfer.org/pages/about/) and [DeepInfer Slicer extension](https://www.slicer.org/wiki/Documentation/Nightly/Modules/DeepInfer), see how models are created, etc.

You can get some ideas from [NiftyNet](https://arxiv.org/pdf/1709.03485.pdf), too.

---

<div class="post-metadata">

**Author:** ![xiaowei](https://avatars.discourse-cdn.com/v4/letter/x/76d3ee/32.png) [@xiaowei](https://discourse.slicer.org/u/xiaowei)\
**Post date:** [June 15, 2018, 7:11pm UTC](https://discourse.slicer.org/t/export-segmentation-results-3d-labels-to-multiple-2d-images-for-deep-learning-training/3197/3 "2018-06-15T19:11:07Z")

</div>

Thanks, Lassoan!

Do you know how to export the segmentation results to HDF format?

---

<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:** [June 17, 2018, 1:36am UTC](https://discourse.slicer.org/t/export-segmentation-results-3d-labels-to-multiple-2d-images-for-deep-learning-training/3197/4 "2018-06-17T01:36:48Z")

</div>

I’ll participate in a project to explore this, but we’ll get there in a few months. Maybe @raul can comment on how they create them now.

What you can do easily now is to export segmentation as 4D NRRD file (each segment is a 3D subvolume). If segments don’t overlap then you can also export segmentation to labelmap node and save it as 3D NRRD file.

---

<div class="post-metadata">

**Author:** ![Shannon\_Chow](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shannon_chow/32/66067_2.png) [@Shannon\_Chow](https://discourse.slicer.org/u/Shannon_Chow)\
**Post date:** [December 14, 2018, 5:45am UTC](https://discourse.slicer.org/t/export-segmentation-results-3d-labels-to-multiple-2d-images-for-deep-learning-training/3197/5 "2018-12-14T05:45:32Z")

</div>

How do you solve this problem？
