-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
Describe the bug
ITKReader throws an error when reading NRRD05 images with the "measurement frame" field. Here's part of the traceback:
~/workspace/envs/sono-env/lib/python3.6/site-packages/monai/data/image_reader.py in _get_meta_dict(self, img)
220 if key.startswith("ITK_original_"):
221 continue
--> 222 meta_dict[key] = img_meta_dict[key]
223 meta_dict["origin"] = np.asarray(img.GetOrigin())
224 meta_dict["spacing"] = np.asarray(img.GetSpacing())
~/workspace/envs/sono-env/lib/python3.6/site-packages/itk/ITKCommonBasePython.py in __getitem__(self, key)
887 import itk
888 obj = self.Get(key)
--> 889 return itk.down_cast(obj).GetMetaDataObjectValue()
890 def __len__(self):
891 return self.GetKeys().size()
~/workspace/envs/sono-env/lib/python3.6/site-packages/itkExtras.py in down_cast(obj)
1198 raise RuntimeError(
1199 "Can't downcast to a specialization of %s" %
-> 1200 className)
1201 else:
1202 return t.cast(obj)
RuntimeError: Can't downcast to a specialization of MetaDataObject
To Reproduce
Run
import numpy as np
import SimpleITK as sitk
from monai.data import ITKReader
from monai.transforms import LoadImage
fn = "tmp.seg.nrrd"
data = np.zeros((3,3,3))
im = sitk.GetImageFromArray(data)
im.SetMetaData("NRRD_measurement frame", "(1,0,0) (0,1,0) (0,0,1)")
sitk.WriteImage(im, fn)
LoadImage(reader=ITKReader())(fn)
Commenting out the SetMetaData line runs fine.
Expected behavior
ITKReader reads NRRD005 files.
Environment
================================
Printing MONAI config...
================================
MONAI version: 0.4.0
Numpy version: 1.17.4
Pytorch version: 1.6.0.dev20200528+cu101
MONAI flags: HAS_EXT = False, USE_COMPILED = False
MONAI rev id: 0563a4467fa602feca92d91c7f47261868d171a1
Optional dependencies:
Pytorch Ignite version: 0.4.2
Nibabel version: 3.2.1
scikit-image version: 0.17.2
Pillow version: 6.2.1
Tensorboard version: 2.4.0
gdown version: 3.12.2
TorchVision version: 0.7.0.dev20200528+cu101
ITK version: 5.1.2
tqdm version: 4.54.1
lmdb version: NOT INSTALLED or UNKNOWN VERSION.
psutil version: NOT INSTALLED or UNKNOWN VERSION.
Additional context
Is ignoring the measurement frame field like this here an acceptable fix? adamaji@13cbe07 If so, I can issue the PR.
Jingnan-Jia
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested