Skip to content

Commit

Permalink
[DLMED] fix typo
Browse files Browse the repository at this point in the history
Signed-off-by: Nic Ma <nma@nvidia.com>
  • Loading branch information
Nic-Ma committed Jan 14, 2021
1 parent af7a2bf commit db31dbd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
5 changes: 4 additions & 1 deletion monai/data/nifti_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def __getitem__(self, index: int):
self.randomize()
meta_data = None
img_loader = LoadImage(
image_only=self.image_only, dtype=self.dtype, as_closest_canonical=self.as_closest_canonical
reader="NibabelReader",
image_only=self.image_only,
dtype=self.dtype,
as_closest_canonical=self.as_closest_canonical,
)
if self.image_only:
img = img_loader(self.image_files[index])
Expand Down
4 changes: 0 additions & 4 deletions tests/min_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ def run_testsuit():
"test_lmdbdataset",
"test_load_image",
"test_load_imaged",
"test_load_nifti",
"test_load_niftid",
"test_load_png",
"test_load_pngd",
"test_load_spacing_orientation",
"test_mednistdataset",
"test_nifti_dataset",
Expand Down
33 changes: 26 additions & 7 deletions tests/test_nifti_rw.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,41 @@
)

TEST_CASES = [
[TEST_IMAGE, TEST_AFFINE, dict(image_only=False, as_closest_canonical=True), np.arange(24).reshape((2, 4, 3))],
[
TEST_IMAGE,
TEST_AFFINE,
dict(image_only=False, as_closest_canonical=True),
dict(reader="NibabelReader", image_only=False, as_closest_canonical=True),
np.arange(24).reshape((2, 4, 3)),
],
[
TEST_IMAGE,
TEST_AFFINE,
dict(reader="NibabelReader", image_only=True, as_closest_canonical=True),
np.array(
[
[[12.0, 15.0, 18.0, 21.0], [13.0, 16.0, 19.0, 22.0], [14.0, 17.0, 20.0, 23.0]],
[[0.0, 3.0, 6.0, 9.0], [1.0, 4.0, 7.0, 10.0], [2.0, 5.0, 8.0, 11.0]],
]
),
],
[TEST_IMAGE, TEST_AFFINE, dict(image_only=True, as_closest_canonical=False), np.arange(24).reshape((2, 4, 3))],
[TEST_IMAGE, TEST_AFFINE, dict(image_only=False, as_closest_canonical=False), np.arange(24).reshape((2, 4, 3))],
[TEST_IMAGE, None, dict(image_only=False, as_closest_canonical=False), np.arange(24).reshape((2, 4, 3))],
[
TEST_IMAGE,
TEST_AFFINE,
dict(reader="NibabelReader", image_only=True, as_closest_canonical=False),
np.arange(24).reshape((2, 4, 3)),
],
[
TEST_IMAGE,
TEST_AFFINE,
dict(reader="NibabelReader", image_only=False, as_closest_canonical=False),
np.arange(24).reshape((2, 4, 3)),
],
[
TEST_IMAGE,
None,
dict(reader="NibabelReader", image_only=False, as_closest_canonical=False),
np.arange(24).reshape((2, 4, 3)),
],
]


Expand Down Expand Up @@ -74,13 +94,12 @@ def test_orientation(self, array, affine, reader_param, expected):

if affine is not None:
np.testing.assert_allclose(saved_affine, affine)
print("!!!!!!!!!!", saved_data.shape, expected.shape)
np.testing.assert_allclose(saved_data, expected)

def test_consistency(self):
np.set_printoptions(suppress=True, precision=3)
test_image = make_nifti_image(np.arange(64).reshape(1, 8, 8), np.diag([1.5, 1.5, 1.5, 1]))
data, header = LoadImage(as_closest_canonical=False)(test_image)
data, header = LoadImage(reader="NibabelReader", as_closest_canonical=False)(test_image)
data, original_affine, new_affine = Spacing([0.8, 0.8, 0.8])(data[None], header["affine"], mode="nearest")
data, _, new_affine = Orientation("ILP")(data, new_affine)
if os.path.exists(test_image):
Expand Down

0 comments on commit db31dbd

Please sign in to comment.