Skip to content
4 changes: 3 additions & 1 deletion monai/data/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,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:
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_load_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -144,7 +145,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")
Expand All @@ -154,7 +154,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):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_load_imaged.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)


Expand Down