# Error when trying SimpleITK with Segmentations / conversion

**URL:** https://discourse.slicer.org/t/error-when-trying-simpleitk-with-segmentations-conversion/16586
**Category:** Development
**Created:** [March 16, 2021, 10:28pm UTC](https://discourse.slicer.org/t/error-when-trying-simpleitk-with-segmentations-conversion/16586 "2021-03-16T22:28:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![yannick\_s](https://avatars.discourse-cdn.com/v4/letter/y/f14d63/32.png) [@yannick\_s](https://discourse.slicer.org/u/yannick_s)
#### Post date: [March 16, 2021, 10:28pm UTC](https://discourse.slicer.org/t/error-when-trying-simpleitk-with-segmentations-conversion/16586/1 "2021-03-16T22:28:42Z")

</div>

Dear all,

I would like to use SimpleITK with Segmentations. For this, I tried the approaches described by @lassoan here: [Segmentation Using SimpleITK - #2 by lassoan](https://discourse.slicer.org/t/segmentation-using-simpleitk/13232/2)

My `inputSeg` stems from a `vtkMRMLSegmentationNode` I get from a `qMRMLNodeComboBox`.

I first tried:

```
    labelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLabelMapVolumeNode')

    segs = vtk.vtkStringArray()
    inputSeg.GetDisplayNode().GetVisibleSegmentIDs(segs)

    slicer.modules.segmentations.logic().ExportSegmentsToLabelmapNode(inputSeg, segs, labelmapVolumeNode)

    segimg = sitkUtils.PullVolumeFromSlicer(labelmapVolumeNode)

```

This gives the error:  
RuntimeError: Exception thrown in SimpleITK ReadImage: /tmp/SimpleITK/Code/IO/src/sitkImageReaderBase.cxx:318:  
sitk::ERROR: Logic error!

Trying `sitk.ReadImage(sitkUtils.GetSlicerITKReadWriteAddress(labelmapVolumeNode.GetName()))` gives the same error.

I then tried to get to the label map representation from the segmentation:

```
img = vtkSegmentationCore.vtkOrientedImageData()
segimg2 = inputSeg.GetBinaryLabelmapRepresentation(segs.GetValue(3), img)

```

But this results in a `segimimg2` with `NoneType` that I cannot further process.

I do not need the label maps to be accessible through e.g. the Data module and use it only internally. That’s why I would prefer something like getting the label map without adding a node.

I am new to handling segmentations and need to use SimpleITK functions. Any help to get there highly appreciated!

---

<div class="post-metadata">

### Author: ![yannick\_s](https://avatars.discourse-cdn.com/v4/letter/y/f14d63/32.png) [@yannick\_s](https://discourse.slicer.org/u/yannick_s)
#### Post date: [March 18, 2021, 3:51pm UTC](https://discourse.slicer.org/t/error-when-trying-simpleitk-with-segmentations-conversion/16586/2 "2021-03-18T15:51:39Z")

</div>

I am switching to a scripted CLI, looks more straightforward to use my existing code based on SimpleITK
