testing __getitem__ for 5D image
()
| 448 | assert_image_ndarray_equals(img[-1:-4:-1, :, :, :], nda[:, :, :, -1:-4:-1]) |
| 449 | |
| 450 | def test_5d(): |
| 451 | """testing __getitem__ for 5D image""" |
| 452 | |
| 453 | # Check if we have 5D Image support |
| 454 | try: |
| 455 | sitk.Image([2] * 5, sitk.sitkFloat32) |
| 456 | except RuntimeError: |
| 457 | pytest.skip("5D Image not supported") |
| 458 | |
| 459 | nda = np.linspace(0, 719, 720).reshape(2, 3, 4, 5, 6) |
| 460 | |
| 461 | img = sitk.GetImageFromArray(nda, isVector=False) |
| 462 | |
| 463 | # check some exceptions |
| 464 | with pytest.raises(IndexError): |
| 465 | img[0, 1, 0, 0, 0, 0] |
| 466 | with pytest.raises(IndexError): |
| 467 | img[0, 0, 4, 0, 0] |
| 468 | with pytest.raises(IndexError): |
| 469 | img[0, 0, 0, 0, 2] |
| 470 | with pytest.raises(IndexError): |
| 471 | img[-7, 0, 0, 0, 0] |
| 472 | with pytest.raises(IndexError): |
| 473 | img[0, 0, 0, 0, -3] |
| 474 | |
| 475 | assert img[0, 0, 0, 0, 0] == 0.0 |
| 476 | assert img[(1, 0, 0, 0, 0)] == 1.0 |
| 477 | assert img[[2, 0, 0, 0, 0]] == 2.0 |
| 478 | assert img[3, 2, 1, 0, 0] == 45.0 |
| 479 | assert img[-5, -4, -3, -2, -1] == 517.0 |
| 480 | assert img[-5, -4, -3, -2, -1] == nda[-1, -2, -3, -4, -5] |
| 481 | |
| 482 | assert_image_ndarray_equals( |
| 483 | img[::-1, ::-1, ::-1, ::-1, ::-1], nda[::-1, ::-1, ::-1, ::-1, ::-1] |
| 484 | ) |
| 485 | assert_image_ndarray_equals( |
| 486 | img[::-1, ::1, ::-1, ::1, ::-1], nda[::-1, ::1, ::-1, ::1, ::-1] |
| 487 | ) |
| 488 | assert_image_ndarray_equals( |
| 489 | img[::2, ::-1, ::3, ::-2, :], nda[:, ::-2, ::3, ::-1, ::2] |
| 490 | ) |
| 491 | |
| 492 | assert_image_ndarray_equals(img[1:4, 4, 0:2, :, :], nda[:, :, 0:2, 4, 1:4]) |
| 493 | assert_image_ndarray_equals( |
| 494 | img[1:3, 3:0:-1, 0, :, 1], nda[1, :, 0, 3:0:-1, 1:3] |
| 495 | ) |
| 496 | assert_image_ndarray_equals(img[2, ::2, 3, ::-1, 0], nda[0, ::-1, 3, ::2, 2]) |
| 497 | |
| 498 | assert_image_ndarray_equals(img[5, ...], nda[..., 5]) |
| 499 | assert_image_ndarray_equals(img[5, :4, 3, 2, ...], nda[..., 2, 3, :4, 5]) |
| 500 | assert_image_ndarray_equals(img[5, 4, :3, ..., 1], nda[1, ..., :3, 4, 5]) |
| 501 | assert_image_ndarray_equals(img[5, ..., -1, 1], nda[1, -1, ..., 5]) |
| 502 | assert_image_ndarray_equals(img[...], nda[...]) |
| 503 | |
| 504 | def test_compare(): |
| 505 | """Test comparison operators""" |
nothing calls this directly
no test coverage detected