# Disapearing segment information after using importlabelmaptosegmentation

**URL:** https://discourse.slicer.org/t/disapearing-segment-information-after-using-importlabelmaptosegmentation/9291
**Category:** Support
**Created:** [November 25, 2019, 1:08pm UTC](https://discourse.slicer.org/t/disapearing-segment-information-after-using-importlabelmaptosegmentation/9291 "2019-11-25T13:08:12Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![dominicrushforth](https://avatars.discourse-cdn.com/v4/letter/d/97f17d/32.png) [@dominicrushforth](https://discourse.slicer.org/u/dominicrushforth)
#### Post date: [November 25, 2019, 1:08pm UTC](https://discourse.slicer.org/t/disapearing-segment-information-after-using-importlabelmaptosegmentation/9291/1 "2019-11-25T13:08:12Z")

</div>

Hi,

I am really loving 4.11 as I can now use scipy and pdflatex with ease. However ever since I started using 4.11 I have been having problems with my GUI for performing localised thresholing using simpleitk…

The first segment loses all it’s segment information as soon as another is created. The segment still exists in the list of segments and the segmentation node (when printed in the interactor) but it cannot be visualised - as if it were a newly created ‘blank’ segment.

I have tracked the issue down to this command:

slicer.vtkSlicerSegmentationsModuleLogic.ImportLabelmapToSegmentationNode(labelmap, segmentationNode, segmentVtkString)

Whenever this is run for a different segment, the first segment in the segmentation node is ‘cleared’ as described above. When creating multiple segments none of the subsequent segments are affected in the same way and it is possible to work around this problem by redefining the first segment after having completed all the others.

I am currently using the nightly from the 21st.

---

<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: [November 25, 2019, 1:53pm UTC](https://discourse.slicer.org/t/disapearing-segment-information-after-using-importlabelmaptosegmentation/9291/2 "2019-11-25T13:53:51Z")

</div>

@sunderlandkyl could you please check if you can reproduce this issue?

---

<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: [November 25, 2019, 1:56pm UTC](https://discourse.slicer.org/t/disapearing-segment-information-after-using-importlabelmaptosegmentation/9291/3 "2019-11-25T13:56:18Z")

</div>

Sure, I’ll take a look.

---

<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: [November 25, 2019, 2:58pm UTC](https://discourse.slicer.org/t/disapearing-segment-information-after-using-importlabelmaptosegmentation/9291/4 "2019-11-25T14:58:42Z")

</div>

@dominicrushforth I’ve tried importing lablemaps one after the other into the same segmentation, but I haven’t been able to reproduce this issue so far.

Could you provide mode information on when this occurs?  
How many segments are in the labelmaps that you import?

---

<div class="post-metadata">

### Author: ![dominicrushforth](https://avatars.discourse-cdn.com/v4/letter/d/97f17d/32.png) [@dominicrushforth](https://discourse.slicer.org/u/dominicrushforth)
#### Post date: [November 25, 2019, 4:30pm UTC](https://discourse.slicer.org/t/disapearing-segment-information-after-using-importlabelmaptosegmentation/9291/5 "2019-11-25T16:30:29Z")

</div>

I’m not entirely sure what is relevant,

I get a vtkMRMLSegmentEditorNode…

```python
try:
  self.segmentEditorNode = slicer.util.getNode('Dose Segment Editor')
except:
  self.segmentEditorNode = slicer.vtkMRMLSegmentEditorNode()
self.segmentEditorNode.SetName('Dose Segment Editor')
# create a vtkMRMLSegmentationNode…
try:
  self.segmentationNode = slicer.util.getNode('Dose Segmentation')
except:
  self.segmentationNode = slicer.vtkMRMLSegmentationNode()
self.segmentationNode.SetName('Dose Segmentation')

```

I run the simple itk ConnectedThresholdImageFilter then use this function to put the resulting labelmap into a segment

```python
# names of relevant nodes are looked up
currentSegmentText = self.segmentationSelector.currentText
# looks for segment
segmentID = self.segmentationNode.GetSegmentation().GetSegmentIdBySegmentName(currentSegmentText)
segment = self.segmentationNode.GetSegmentation().GetSegment(segmentID)
# if the mask segment has not already been created, this is done (it should have been but just in case!)
if segment is None:
  segmentID = self.segmentationNode.GetSegmentation().AddEmptySegment(currentSegmentText)
# convert resulting label map into a segment
segmentVtkString = vtk.vtkStringArray()
segmentVtkString.SetNumberOfValues(1)
segmentVtkString.SetValue(0,currentSegmentText)
slicer.vtkSlicerSegmentationsModuleLogic.ImportLabelmapToSegmentationNode(labelmap, self.segmentationNode, segmentVtkString)

```

The problem occurs when creating the second segment. The original segment can still be seen if the function is ended before the last  
line is run. Running the last line in the interactor then makes the first segment vanish (even if all the eyes are open). Creating a third segment has no effect on the second segment and so on… However if the first segment is removed the segment that is  
now at the top of the list is affected in the same way if any new segments are created using this method. The problem doesn’t occur with other of creating or defining segments.

I am using  
r28644 on windows. I can install the latest nightly if that might help?

Dom

---

<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: [November 25, 2019, 8:42pm UTC](https://discourse.slicer.org/t/disapearing-segment-information-after-using-importlabelmaptosegmentation/9291/6 "2019-11-25T20:42:09Z")

</div>

Thanks for your help, I think I’ve found the cause of the issue.  
I’ll let you know when it’s fixed.

---

<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: [November 25, 2019, 10:06pm UTC](https://discourse.slicer.org/t/disapearing-segment-information-after-using-importlabelmaptosegmentation/9291/7 "2019-11-25T22:06:06Z")

</div>

Found the problem and made a fix (can be found here: [https://github.com/Slicer/Slicer/pull/1268](https://github.com/Slicer/Slicer/pull/1268)).

---

<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: [November 26, 2019, 2:24pm UTC](https://discourse.slicer.org/t/disapearing-segment-information-after-using-importlabelmaptosegmentation/9291/8 "2019-11-26T14:24:05Z")

</div>

The fix should be found in the latest 4.11 nightly.

---

<div class="post-metadata">

### Author: ![dominicrushforth](https://avatars.discourse-cdn.com/v4/letter/d/97f17d/32.png) [@dominicrushforth](https://discourse.slicer.org/u/dominicrushforth)
#### Post date: [November 26, 2019, 3:16pm UTC](https://discourse.slicer.org/t/disapearing-segment-information-after-using-importlabelmaptosegmentation/9291/9 "2019-11-26T15:16:06Z")

</div>

I’ve installed the latest nightly and it’s working great. Thanks so much 🙂
