MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / _cmp

Method _cmp

tests/transforms/test_load_imaged.py:97–124  ·  view source on GitHub ↗
(self, filename, ch_shape, reader_1, reader_2, outname, ext)

Source from the content-addressed store, hash-verified

95@unittest.skipUnless(has_itk, "itk not installed")
96class TestConsistency(unittest.TestCase):
97 def _cmp(self, filename, ch_shape, reader_1, reader_2, outname, ext):
98 data_dict = {"img": filename}
99 keys = data_dict.keys()
100 xforms = Compose([LoadImaged(keys, reader=reader_1, ensure_channel_first=True, image_only=True)])
101 img_dict = xforms(data_dict) # load dicom with itk
102 self.assertTupleEqual(img_dict["img"].shape, ch_shape)
103
104 with tempfile.TemporaryDirectory() as tempdir:
105 save_xform = SaveImageD(keys, output_dir=tempdir, squeeze_end_dims=False, output_ext=ext)
106 save_xform(img_dict) # save to nifti
107
108 new_xforms = Compose(
109 [
110 LoadImaged(keys, reader=reader_2, image_only=True),
111 EnsureChannelFirstD(keys),
112 FromMetaTensord(keys),
113 ToMetaTensord(keys),
114 ]
115 )
116 out = new_xforms({"img": os.path.join(tempdir, outname)}) # load nifti with itk
117 self.assertTupleEqual(out["img"].shape, ch_shape)
118
119 def is_identity(x):
120 return (x == torch.eye(x.shape[0])).all()
121
122 if not is_identity(img_dict["img"].affine) and not is_identity(out["img"].affine):
123 assert_allclose(img_dict["img"].affine, out["img"].affine, rtol=1e-3)
124 assert_allclose(out["img"], img_dict["img"], rtol=1e-3)
125
126 def test_dicom(self):
127 img_dir = "tests/testing_data/CT_DICOM"

Callers 3

test_dicomMethod · 0.95
test_multi_dicomMethod · 0.95
test_pngMethod · 0.95

Calls 5

ComposeClass · 0.90
LoadImagedClass · 0.90
FromMetaTensordClass · 0.90
ToMetaTensordClass · 0.90
assert_allcloseFunction · 0.90

Tested by

no test coverage detected