# slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode() Not workign with given SegmentIDs

**URL:** <https://discourse.slicer.org/t/slicer-modules-segmentations-logic-importlabelmaptosegmentationnode-not-workign-with-given-segmentids/27998>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [February 23, 2023, 5:42am UTC](https://discourse.slicer.org/t/slicer-modules-segmentations-logic-importlabelmaptosegmentationnode-not-workign-with-given-segmentids/27998 "2023-02-23T05:42:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Shen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_shen/32/14411_2.png) [@Alex\_Shen](https://discourse.slicer.org/u/Alex_Shen)\
**Post date:** [February 23, 2023, 5:42am UTC](https://discourse.slicer.org/t/slicer-modules-segmentations-logic-importlabelmaptosegmentationnode-not-workign-with-given-segmentids/27998/1 "2023-02-23T05:42:28Z")

</div>

Hi, having this issue trying to convert labelmap volume to a segmentation node.  
My labelmap volume here has only 0s and 1s, so theoretically, only one segment will be created running this function.

If I run the following code without specifying segmentIDs, everything works fine:

```auto
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(volumeNode, segmentationNode)

```

The function returns true and expected segment is created with the default name (“jake”)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/7/17e5cbf0c5ffa93a3ee292f788eb6fa990b65f3c.png)

I want to give the segment a specific ID, so I can call it afterwards by running:

```auto
id = 'Fem_P'
ids = vtk.vtkStringArray()
ids.InsertNextValue(id)
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(volumeNode, segmentationNode, ids)

```

The function returns True and does NOT create segments.

Anyone knows why? Did I do something wrong when creating the `vtkStringArray`?

Thanks ahead

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [February 23, 2023, 7:07pm UTC](https://discourse.slicer.org/t/slicer-modules-segmentations-logic-importlabelmaptosegmentationnode-not-workign-with-given-segmentids/27998/2 "2023-02-23T19:07:15Z")

</div>

I’ve created a PR that should fix the issue here: [BUG: Create non-existing segments in ImportLabelmapToSegmentationNode by Sunderlandkyl · Pull Request #6835 · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/pull/6835)

---

<div class="post-metadata">

**Author:** ![Alex\_Shen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_shen/32/14411_2.png) [@Alex\_Shen](https://discourse.slicer.org/u/Alex_Shen)\
**Post date:** [February 23, 2023, 11:09pm UTC](https://discourse.slicer.org/t/slicer-modules-segmentations-logic-importlabelmaptosegmentationnode-not-workign-with-given-segmentids/27998/3 "2023-02-23T23:09:41Z")

</div>

Thanks for the quick PR on fixing this. Now I understand that to work around this problem, I can create an empty segment with the ID that I want to name it.

The following code works now:

id = ‘Fem\_P’  
segmentationNode.GetSegmentation().AddEmptySegment(id)  
ids = vtk.vtkStringArray()  
ids.InsertNextValue(id)  
slicer.modules.segmentations.logic().ImportLabelmapToSegmentationNode(volumeNode, segmentationNode, ids)
