(self, lps_convention: bool, device)
| 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 | |
| 324 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected