# reading segmentation file from Slicer (NRRD) with multiple segments with SimpleITK shows Exception

**URL:** <https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808>\
**Category:** Engineering\
**Tags:** simpleitk, python\
**Created:** [March 29, 2018, 7:03pm UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808 "2018-03-29T19:03:58Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![Diego\_C](https://discourse.itk.org/user_avatar/discourse.itk.org/diego_c/32/279_2.png) [@Diego\_C](https://discourse.itk.org/u/Diego_C)\
**Post date:** [March 31, 2018, 2:57am UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808/22 "2018-03-31T02:57:14Z")

</div>

> [@dzenanz](#):
>
> Segmentations module should always write vector or list for the first dimension.

If I change the NRRD kinds header in my files so the first dimension becomes of the type _list_ (instead of _complex_) would that make that file readable by SimpleITK? @blowekamp @dzenanz

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [March 31, 2018, 2:57am UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808/23 "2018-03-31T02:57:14Z")

</div>

Have your u tried the outputPixelType option?

---

<div class="post-metadata">

**Author:** ![Diego\_C](https://discourse.itk.org/user_avatar/discourse.itk.org/diego_c/32/279_2.png) [@Diego\_C](https://discourse.itk.org/u/Diego_C)\
**Post date:** [March 31, 2018, 2:58am UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808/24 "2018-03-31T02:58:20Z")

</div>

about to try it now…

---

<div class="post-metadata">

**Author:** ![Diego\_C](https://discourse.itk.org/user_avatar/discourse.itk.org/diego_c/32/279_2.png) [@Diego\_C](https://discourse.itk.org/u/Diego_C)\
**Post date:** [March 31, 2018, 3:06am UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808/25 "2018-03-31T03:06:48Z")

</div>

@blowekamp This is what I got when I tried:

```auto
image = sitk.ReadImage(filename, sitk.sitkVectorUInt16)
```

(Notice that the outp pixel type is not a _keyword argument_)

```auto
  File "/Users/odin/anaconda/lib/python2.7/site-packages/SimpleITK/SimpleITK.py", line 8332, in ReadImage
    return _SimpleITK.ReadImage(*args)
RuntimeError: Exception thrown in SimpleITK ReadImage: /scratch/dashboards/SimpleITK-OSX10.6-intel-pkg/SimpleITK/Code/IO/src/sitkImageReaderBase.cxx:285:
sitk::ERROR: Only Complex image with float and double are supported!
```

---

<div class="post-metadata">

**Author:** ![Diego\_C](https://discourse.itk.org/user_avatar/discourse.itk.org/diego_c/32/279_2.png) [@Diego\_C](https://discourse.itk.org/u/Diego_C)\
**Post date:** [March 31, 2018, 3:14am UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808/26 "2018-03-31T03:14:28Z")

</div>

This is the respective NRRD header dump

```auto
__len__ = {int} 10
u'dimension' (4867413600) = {int} 4
u'encoding' (4867413792) = {str} 'gzip'
u'keyvaluepairs' (4628472432) = {dict} # Slicer metadata about segments goes here
u'kinds' (4596423152) = {list} <type 'list'>: ['complex', 'domain', 'domain', 'domain']
u'measurement frame' (4867413984) = {list} <type 'list'>: [['1', '0', '0'], ['0', '1', '0'], ['0', '0', '1']]
u'sizes' (4867413696) = {list} <type 'list'>: [2, 41, 80, 9]
u'space' (4867413360) = {str} 'right-anterior-superior'
u'space directions' (4867413456) = {list} <type 'list'>: [u'none', ['-0.5', '1.01115573674059e-10', '1.7102395547300398e-11'], ['-1.0255169999999903e-10', '-0.492998018603237', '-0.08338437295609949'], ['-1.9387071799358836e-26', '-0.50030691366964397', '2.9579921079755898']]
u'space origin' (4867413888) = {list} <type 'list'>: ['-18.165176407702127', '-1.8838383685304463', '-70.585192304157161']
u'type' (4867413504) = {str} 'unsigned char'
```

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [March 31, 2018, 2:13pm UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808/27 "2018-03-31T14:13:50Z")

</div>

> [@Diego\_C](#):
>
> If I change the NRRD kinds header in my files so the first dimension becomes of the type list…

That should make the file readable. I think that all the other metadata is OK, but you should try to be sure. You can also change it using a text editor (e.g. Notepad++) just to see if it works, you don’t have to do it programmatically.

---

<div class="post-metadata">

**Author:** ![Diego\_C](https://discourse.itk.org/user_avatar/discourse.itk.org/diego_c/32/279_2.png) [@Diego\_C](https://discourse.itk.org/u/Diego_C)\
**Post date:** [March 31, 2018, 2:24pm UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808/28 "2018-03-31T14:24:41Z")

</div>

Hi Dženan thanks! I will try that!

---

<div class="post-metadata">

**Author:** ![glk](https://discourse.itk.org/user_avatar/discourse.itk.org/glk/32/69_2.png) [@glk](https://discourse.itk.org/u/glk)\
**Post date:** [April 2, 2018, 10:45am UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808/29 "2018-04-02T10:45:45Z")

</div>

I agree with @lassoan that “list” is the right axis “kind” here: you know its a list when two things are true: it doesn’t make any sense to resample along this axis (as it would if this were a spatial or temporal axis), and, these values would not change in a predictable way with a change in the basis vectors used to span space (as they would if this were the coefficients of a vector or tensor).

But obviously a file format can’t teach software about how to handle meta-data. @lassoan is there ever a case where vtkTeemNRRDWriter might be used to save an actual vector field (like a displacement field from a non-rigid registration?)

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.itk.org/user_avatar/discourse.itk.org/lassoan/32/27_2.png) [@lassoan](https://discourse.itk.org/u/lassoan)\
**Post date:** [April 2, 2018, 12:33pm UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808/30 "2018-04-02T12:33:54Z")

</div>

vtkTeemNRRDWriter still uses different axis kinds for vector fields, tenors, etc. I’ve just changed it to use list kind for Segmentations.

---

<div class="post-metadata">

**Author:** ![Diego\_C](https://discourse.itk.org/user_avatar/discourse.itk.org/diego_c/32/279_2.png) [@Diego\_C](https://discourse.itk.org/u/Diego_C)\
**Post date:** [April 3, 2018, 8:43pm UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808/31 "2018-04-03T20:43:11Z")

</div>

Thank you @lassoan When do you think this change will be available in Slicer? I have another 900 images to go through with my radiologists… thanks!

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.itk.org/user_avatar/discourse.itk.org/lassoan/32/27_2.png) [@lassoan](https://discourse.itk.org/u/lassoan)\
**Post date:** [April 4, 2018, 12:25am UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808/32 "2018-04-04T00:25:21Z")

</div>

It’s already available in the nightly version.

---

<div class="post-metadata">

**Author:** ![asere](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/ebca7d/32.png) [@asere](https://discourse.itk.org/u/asere)\
**Post date:** [November 3, 2020, 1:29am UTC](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808/33 "2020-11-03T01:29:03Z")

</div>

Hey Diego,

Would it be possible for you to share that code? Thank you in advance

[Previous page](https://discourse.itk.org/t/reading-segmentation-file-from-slicer-nrrd-with-multiple-segments-with-simpleitk-shows-exception/808.md?page=1)
