diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index 484026626f..a710e8e46e 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -88,6 +88,10 @@ jobs: name: Install torch cpu from pytorch.org (Windows only) run: | python -m pip install torch==1.12.1+cpu torchvision==0.13.1+cpu -f https://download.pytorch.org/whl/torch_stable.html + - if: runner.os == 'Linux' + name: Install itk pre-release (Linux only) + run: | + python -m pip install --pre -U itk - name: Install the dependencies run: | python -m pip install torch==1.12.1 torchvision==0.13.1 diff --git a/monai/data/image_reader.py b/monai/data/image_reader.py index 087d4d1950..34e1368fe2 100644 --- a/monai/data/image_reader.py +++ b/monai/data/image_reader.py @@ -318,7 +318,12 @@ def _get_meta_dict(self, img) -> Dict: """ img_meta_dict = img.GetMetaDataDictionary() - meta_dict = {key: img_meta_dict[key] for key in img_meta_dict.GetKeys() if not key.startswith("ITK_")} + meta_dict = {} + for key in img_meta_dict.GetKeys(): + if key.startswith("ITK_"): + continue + val = img_meta_dict[key] + meta_dict[key] = np.asarray(val) if type(val).__name__.startswith("itk") else val meta_dict["spacing"] = np.asarray(img.GetSpacing()) return meta_dict diff --git a/tests/test_load_image.py b/tests/test_load_image.py index 834c9f9d59..1db39a310b 100644 --- a/tests/test_load_image.py +++ b/tests/test_load_image.py @@ -315,7 +315,7 @@ def test_channel_dim(self, input_param, filename, expected_shape): with tempfile.TemporaryDirectory() as tempdir: filename = os.path.join(tempdir, filename) nib.save(nib.Nifti1Image(test_image, np.eye(4)), filename) - result = LoadImage(image_only=True, **input_param)(filename) + result = LoadImage(image_only=True, **input_param)(filename) # with itk, meta has 'qto_xyz': itkMatrixF44 self.assertTupleEqual( result.shape, (3, 128, 128, 128) if input_param.get("ensure_channel_first", False) else expected_shape