From 08da9df5d0e897f14a730f4cf0e25fa04b1a710d Mon Sep 17 00:00:00 2001 From: Nic Ma Date: Thu, 17 Sep 2020 07:13:29 +0800 Subject: [PATCH 1/3] [DLMED] update itk spatial shape Signed-off-by: Nic Ma --- monai/data/image_reader.py | 4 +++- tests/test_load_image.py | 3 +-- tests/test_load_imaged.py | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/monai/data/image_reader.py b/monai/data/image_reader.py index b3599bb785..b4fcaa0b49 100644 --- a/monai/data/image_reader.py +++ b/monai/data/image_reader.py @@ -210,7 +210,9 @@ def _get_spatial_shape(self, img) -> Sequence: img: a ITK image object loaded from a image file. """ - return list(itk.size(img)) + shape = list(itk.size(img)) + shape.reverse() + return shape def _get_array_data(self, img) -> np.ndarray: """ diff --git a/tests/test_load_image.py b/tests/test_load_image.py index 596ad5e581..6e51a21049 100644 --- a/tests/test_load_image.py +++ b/tests/test_load_image.py @@ -120,7 +120,6 @@ def test_load_png(self): def test_register(self): spatial_size = (32, 64, 128) - expected_shape = (128, 64, 32) test_image = np.random.rand(*spatial_size) with tempfile.TemporaryDirectory() as tempdir: filename = os.path.join(tempdir, "test_image.nii.gz") @@ -130,7 +129,7 @@ def test_register(self): loader = LoadImage(image_only=False) loader.register(ITKReader()) result, header = loader(filename) - self.assertTupleEqual(tuple(header["spatial_shape"]), expected_shape) + self.assertTupleEqual(tuple(header["spatial_shape"]), spatial_size) self.assertTupleEqual(result.shape, spatial_size) def test_kwargs(self): diff --git a/tests/test_load_imaged.py b/tests/test_load_imaged.py index d85c6cfab4..396167046b 100644 --- a/tests/test_load_imaged.py +++ b/tests/test_load_imaged.py @@ -42,7 +42,6 @@ def test_shape(self, input_param, expected_shape): def test_register(self): spatial_size = (32, 64, 128) - expected_shape = (128, 64, 32) test_image = np.random.rand(*spatial_size) with tempfile.TemporaryDirectory() as tempdir: filename = os.path.join(tempdir, "test_image.nii.gz") @@ -52,7 +51,7 @@ def test_register(self): loader = LoadImaged(keys="img") loader.register(ITKReader()) result = loader({"img": filename}) - self.assertTupleEqual(tuple(result["img_meta_dict"]["spatial_shape"]), expected_shape) + self.assertTupleEqual(tuple(result["img_meta_dict"]["spatial_shape"]), spatial_size) self.assertTupleEqual(result["img"].shape, spatial_size) From f3a5c2358d5770e34a13eed088e59e2a251fbbae Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Thu, 17 Sep 2020 11:01:13 +0100 Subject: [PATCH 2/3] update test case Signed-off-by: Wenqi Li --- tests/test_load_image.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_load_image.py b/tests/test_load_image.py index d4213483f4..f520a47d62 100644 --- a/tests/test_load_image.py +++ b/tests/test_load_image.py @@ -128,6 +128,7 @@ def test_itk_dicom_series_reader(self, input_param, filenames, expected_shape): ), ), self.assertTupleEqual(result.shape, expected_shape) + self.assertTupleEqual(tuple(header['spatial_shape']), expected_shape) def test_load_png(self): spatial_size = (256, 256) From 3808b226efbda0c79e23b563a6cd4ebcad4b8d0b Mon Sep 17 00:00:00 2001 From: monai-bot Date: Thu, 17 Sep 2020 10:07:37 +0000 Subject: [PATCH 3/3] [MONAI] python code formatting Signed-off-by: monai-bot --- tests/test_load_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_load_image.py b/tests/test_load_image.py index f520a47d62..9399afaf50 100644 --- a/tests/test_load_image.py +++ b/tests/test_load_image.py @@ -128,7 +128,7 @@ def test_itk_dicom_series_reader(self, input_param, filenames, expected_shape): ), ), self.assertTupleEqual(result.shape, expected_shape) - self.assertTupleEqual(tuple(header['spatial_shape']), expected_shape) + self.assertTupleEqual(tuple(header["spatial_shape"]), expected_shape) def test_load_png(self): spatial_size = (256, 256)