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

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

Have your u tried the outputPixelType option?

about to try it now…

@blowekamp This is what I got when I tried:

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

(Notice that the outp pixel type is not a keyword argument)

  File "/Users/odin/anaconda/lib/python2.7/site-packages/SimpleITK/", 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!

This is the respective NRRD header dump

__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'

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.

Hi Dženan thanks! I will try that!

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?)


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


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!

It’s already available in the nightly version.


Hey Diego,

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