From e89102f7793c3bbc089f2629d27b894e0de04610 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Sat, 29 Oct 2022 09:57:07 +0100 Subject: [PATCH 1/2] fixes #5432 Signed-off-by: Wenqi Li --- monai/data/image_reader.py | 7 ++++++- tests/test_load_image.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) 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 From df0195477544293106bdb83646fa360fbfc93c62 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Sat, 29 Oct 2022 10:09:40 +0100 Subject: [PATCH 2/2] add tests Signed-off-by: Wenqi Li --- .github/workflows/pythonapp.yml | 4 ++++ 1 file changed, 4 insertions(+) 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