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

Method test_inverse

tests/transforms/test_orientation.py:306–321  ·  view source on GitHub ↗
(self, lps_convention: bool, device)

Source from the content-addressed store, hash-verified

304
305 @parameterized.expand(TESTS_INVERSE)
306 def test_inverse(self, lps_convention: bool, device):
307 img_t = torch.rand((1, 10, 9, 8), dtype=torch.float32, device=device)
308 affine = torch.tensor(
309 [[0, 0, -1, 0], [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1]], dtype=torch.float32, device="cpu"
310 )
311 meta = {"fname": "somewhere", "space": SpaceKeys.LPS if lps_convention else SpaceKeys.RAS}
312 img = MetaTensor(img_t, affine=affine, meta=meta)
313 tr = Orientation("LPS")
314 # check that image and affine have changed
315 img = cast(MetaTensor, tr(img))
316 self.assertNotEqual(img.shape, img_t.shape)
317 self.assertGreater(float((affine - img.affine).max()), 0.5)
318 # check that with inverse, image affine are back to how they were
319 img = cast(MetaTensor, tr.inverse(img))
320 self.assertEqual(img.shape, img_t.shape)
321 self.assertLess(float((affine - img.affine).max()), 1e-2)
322
323
324if __name__ == "__main__":

Callers

nothing calls this directly

Calls 3

inverseMethod · 0.95
MetaTensorClass · 0.90
OrientationClass · 0.90

Tested by

no test coverage detected