# Create labelmap nrrd file from numpy array

**URL:** <https://discourse.slicer.org/t/create-labelmap-nrrd-file-from-numpy-array/34285>\
**Category:** Development\
**Tags:** segmentation, python\
**Created:** [February 13, 2024, 12:40pm UTC](https://discourse.slicer.org/t/create-labelmap-nrrd-file-from-numpy-array/34285 "2024-02-13T12:40:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elias\_Kim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/elias_kim/32/69328_2.png) [@Elias\_Kim](https://discourse.slicer.org/u/Elias_Kim)\
**Post date:** [February 13, 2024, 12:40pm UTC](https://discourse.slicer.org/t/create-labelmap-nrrd-file-from-numpy-array/34285/1 "2024-02-13T12:40:39Z")

</div>

Hi,

I’m interested in converting a numpy array into a .nrrd file that functions as a label map in 3D slicer.

This numpy array represents the output of a custom semantic segmentation model, containing 33 distinct classes by integer values.

I wonder if I could transform this prediction mask into a label map file format that is compatible with 3D slicer.

I would really appreciate some help. Thank you.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [February 13, 2024, 5:00pm UTC](https://discourse.slicer.org/t/create-labelmap-nrrd-file-from-numpy-array/34285/2 "2024-02-13T17:00:20Z")

</div>

See this:

[slicer.util.addVolumeFromArray](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.addVolumeFromArray)
