# Segmentation to labelmap via commandline

**URL:** <https://discourse.slicer.org/t/segmentation-to-labelmap-via-commandline/16209>\
**Category:** Support\
**Created:** [February 25, 2021, 10:56am UTC](https://discourse.slicer.org/t/segmentation-to-labelmap-via-commandline/16209 "2021-02-25T10:56:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaoloZaffino](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/paolozaffino/32/81052_2.png) [@PaoloZaffino](https://discourse.slicer.org/u/PaoloZaffino)\
**Post date:** [February 25, 2021, 10:56am UTC](https://discourse.slicer.org/t/segmentation-to-labelmap-via-commandline/16209/1 "2021-02-25T10:56:17Z")

</div>

Hi all,  
is there a way for converting a segmentation into a labelmap via command line?  
The labelmap should fit the shape of an anatomical image, so this would be another parameter to specify.

In addition: can I apply (via command line, again) a transformation to a segmentation?

Basically, I would first apply one (or more) transformation to the segmentation, then convert the contours to fit the final image shape.

Thanks a lot.

Paolo

---

<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, 2021, 6:42pm UTC](https://discourse.slicer.org/t/segmentation-to-labelmap-via-commandline/16209/2 "2021-02-25T18:42:18Z")

</div>

See examples here: [Documentation/Nightly/ScriptRepository - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Export_labelmap_node_from_segmentation_node)

---

<div class="post-metadata">

**Author:** ![PaoloZaffino](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/paolozaffino/32/81052_2.png) [@PaoloZaffino](https://discourse.slicer.org/u/PaoloZaffino)\
**Post date:** [March 1, 2021, 12:11pm UTC](https://discourse.slicer.org/t/segmentation-to-labelmap-via-commandline/16209/3 "2021-03-01T12:11:23Z")

</div>

Thanks @lassoan .

Since I need to do all this via command line, I have to run slicer specifying the reference volume, the segmentation, and the python script with the code for conversion.

Am I right?

Paolo

---

<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:** [March 1, 2021, 12:32pm UTC](https://discourse.slicer.org/t/segmentation-to-labelmap-via-commandline/16209/4 "2021-03-01T12:32:51Z")

</div>

Yes. You can pass all the code that loads inputs, runs processing, and exports output to files. Or, you can create a small script and just specify the script and input/output file paths as command-line arguments.
