# Create a segmentation from a contour file using python

**URL:** <https://discourse.slicer.org/t/create-a-segmentation-from-a-contour-file-using-python/29167>\
**Category:** Support\
**Created:** [April 27, 2023, 6:34am UTC](https://discourse.slicer.org/t/create-a-segmentation-from-a-contour-file-using-python/29167 "2023-04-27T06:34:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RonJones](https://avatars.discourse-cdn.com/v4/letter/r/6bbea6/32.png) [@RonJones](https://discourse.slicer.org/u/RonJones)\
**Post date:** [April 27, 2023, 6:34am UTC](https://discourse.slicer.org/t/create-a-segmentation-from-a-contour-file-using-python/29167/1 "2023-04-27T06:34:07Z")

</div>

We have a standard workflow that uses a LabelMap file which is then converted to a Segment node.

Is it possible to convert a LabelMapVolume to a Segmentation using the python API?

---

<div class="post-metadata">

**Author:** ![RonJones](https://avatars.discourse-cdn.com/v4/letter/r/6bbea6/32.png) [@RonJones](https://discourse.slicer.org/u/RonJones)\
**Post date:** [May 1, 2023, 6:43am UTC](https://discourse.slicer.org/t/create-a-segmentation-from-a-contour-file-using-python/29167/2 "2023-05-01T06:43:23Z")

</div>

For reference this is the solution I worked out.

```auto
    labelMapNode = slicer.util.getNodesByClass('vtkMRMLLabelMapVolumeNode')[0]
    segNode = slicer.util.getNodesByClass('vtkMRMLSegmentationNode')[0]
    logic = slicer.util.getModuleLogic('Segmentations')
    logic.ImportLabelmapToSegmentationNodeWithTerminology(contourImageNode, segNode, "")

```
