ITK
ITK copied to clipboard
xarray from ITK image fails with downcast error
Description
Steps to Reproduce
filepath = 'atlas_fc_nii.gz'
img1 = itk.imread(filepath, itk.F)
x_img = itk.xarray_from_image(img1)
Expected behavior
Actual behavior
85 metadata = dict(l_image)
86 ignore_keys = {"direction", "origin", "spacing"}
87 for key in metadata:
File ~/anaconda3/envs/ethicon/lib/python3.8/site-packages/itk/itkImagePython.py:7271, in itkImageBase3.__getitem__(self, key)
7269 return np.flip(itk.array_from_matrix(self.GetDirection()), axis=None)
7270 else:
-> 7271 return self.GetMetaDataDictionary()[key]
7272 else:
7273 return itk.array_view_from_image(self).__getitem__(key)
File ~/anaconda3/envs/ethicon/lib/python3.8/site-packages/itk/ITKCommonBasePython.py:851, in itkMetaDataDictionary.__getitem__(self, key)
849 import itk
850 obj = self.Get(key)
--> 851 return itk.down_cast(obj).GetMetaDataObjectValue()
File ~/anaconda3/envs/ethicon/lib/python3.8/site-packages/itk/support/extras.py:1844, in down_cast(obj)
1841 except Exception:
1842 # fail silently for now
1843 pass
-> 1844 raise RuntimeError(f"Can't downcast to a specialization of {class_name}")
1845 else:
1846 return t.cast(obj)
RuntimeError: Can't downcast to a specialization of MetaDataObject
Reproducibility
Sample file: atlas_fc.nii.gz
Versions
5.3rc4.post2
If the commit number is required, run $ git rev-parse --short HEAD
. -->
Environment
Additional Information
@PranjalSahu this is a Matrix
object for the Nifti transformation? Could support be added similar to https://github.com/InsightSoftwareConsortium/ITK/pull/2270 ?
@thewtex yes that's what I discovered. It is failing for the key qto_xyz which is 4x4 Matrix. After adding wrapping for Matrix it could proceed but failed at another step. I will check and update here.
Matrix with 4x4 is failing currently. Looking to resolve this issue https://github.com/InsightSoftwareConsortium/ITK/issues/3540 .
Will re-open if some new keys are discovered that are failing.