testing __getitem__ for 3D sub-region
()
| 306 | assert_image_ndarray_equals(img[2, ..., 2:0:-1], nda[2:0:-1, ..., 2]) |
| 307 | |
| 308 | def test_3d(): |
| 309 | """testing __getitem__ for 3D sub-region""" |
| 310 | |
| 311 | nda = np.linspace(0, 59, 60).reshape(3, 4, 5) |
| 312 | |
| 313 | img = sitk.GetImageFromArray(nda) |
| 314 | |
| 315 | # check some exceptions |
| 316 | with pytest.raises(IndexError): |
| 317 | img[0, 3, 0, 0] |
| 318 | with pytest.raises(IndexError): |
| 319 | img[0, 4, 0] |
| 320 | with pytest.raises(IndexError): |
| 321 | img[0, 0, 3] |
| 322 | with pytest.raises(IndexError): |
| 323 | img[-6, 0, 0] |
| 324 | with pytest.raises(IndexError): |
| 325 | img[0, 0, -4] |
| 326 | |
| 327 | # check basic indexing |
| 328 | assert img[0, 0, 0] == 0.0 |
| 329 | assert img[(1, 0, 0)] == 1.0 |
| 330 | assert img[[2, 0, 0]] == 2.0 |
| 331 | assert img[3, 2, 1] == 33.0 |
| 332 | assert img[-3, -2, -1] == 52.0 |
| 333 | |
| 334 | assert_image_ndarray_equals(img[1:-1, 1:-1, 1:-1], nda[1:-1, 1:-1, 1:-1]) |
| 335 | assert_image_ndarray_equals(img[:, :, 1:2], nda[1:2, :, :]) |
| 336 | assert_image_ndarray_equals(img[1:5, 2:4, 0:2], nda[0:2, 2:4, 1:5]) |
| 337 | assert_image_ndarray_equals(img[1:, 2:, :2], nda[:2, 2:, 1:]) |
| 338 | |
| 339 | # some negative cases |
| 340 | assert_image_ndarray_equals(img[::-1, ::-1, ::-1], nda[::-1, ::-1, ::-1]) |
| 341 | assert_image_ndarray_equals(img[:, ::-2, ::-1], nda[::-1, ::-2, :]) |
| 342 | assert_image_ndarray_equals(img[-1:-4:-1, :, :], nda[:, :, -1:-4:-1]) |
| 343 | |
| 344 | assert_image_ndarray_equals(img[1, ...], nda[..., 1]) |
| 345 | assert_image_ndarray_equals(img[2, 1:3, ...], nda[..., 1:3, 2]) |
| 346 | assert_image_ndarray_equals(img[...], nda[...]) |
| 347 | assert_image_ndarray_equals(img[..., -2], nda[-2, ...]) |
| 348 | |
| 349 | def test_4d_extract(): |
| 350 | """testing __getitem__ for extracting slices from 4D image""" |
nothing calls this directly
no test coverage detected