# How to generate a .seg.nrrd file out of multiple STL files using Python?

**URL:** <https://discourse.itk.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stl-files-using-python/6484>\
**Category:** Engineering\
**Created:** [March 1, 2024, 5:15am UTC](https://discourse.itk.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stl-files-using-python/6484 "2024-03-01T05:15:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dzemal](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/e95f7d/32.png) [@Dzemal](https://discourse.itk.org/u/Dzemal)\
**Post date:** [March 1, 2024, 5:15am UTC](https://discourse.itk.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stl-files-using-python/6484/1 "2024-03-01T05:15:13Z")

</div>

Hi together,  
I’ve asked this question also in the Slicer forum and got some help but nevertheless I also want to ask here, maybe there is a another way to implement this issue.

I’m trying to write a code snippet in Python for a pipeline that should generate a .seg.nrrd file by using the actual DICOM and the segmented STLs. In Slicer, I have performed this by using the module ‘Segmentations’ → Import models (one by one) → Right-click on the created segmentation node and export it as a .seg.nrrd file. Are there any existing python modules or functions, which can perform exactly this operation?

Thanks for any clue!

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [March 1, 2024, 2:57pm UTC](https://discourse.itk.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stl-files-using-python/6484/2 "2024-03-01T14:57:53Z")

</div>

To create .seg.nrrd (a Slicer format), no. But a binary mask can be created from a mesh, see this example:  
[https://examples.itk.org/src/core/mesh/converttrianglemeshtobinaryimage/documentation](https://examples.itk.org/src/core/mesh/converttrianglemeshtobinaryimage/documentation)

---

<div class="post-metadata">

**Author:** ![Dzemal](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/e95f7d/32.png) [@Dzemal](https://discourse.itk.org/u/Dzemal)\
**Post date:** [March 2, 2024, 7:18am UTC](https://discourse.itk.org/t/how-to-generate-a-seg-nrrd-file-out-of-multiple-stl-files-using-python/6484/3 "2024-03-02T07:18:45Z")

</div>

Thanks a lot @dzenanz ! I think this can solve my problem.
