def test_copy_crop(): arr = cp.arange(45).reshape(9, 5) out0 = crop(arr, 1, copy=True) assert out0.flags.c_contiguous out0[0, 0] = 100 assert not cp.any(arr == 100) assert not cp.may_share_memory(arr, out0) out1 = crop(arr, 1) out1[0, 0] = 100 assert arr[1, 1] == 100 assert cp.may_share_memory(arr, out1)
def test_2d_cropped_camera_image(): a_black = crop(cp.array(camera()), ((200, 212), (100, 312))) a_white = invert(a_black) zeros = cp.zeros((100, 100)) ones = cp.ones((100, 100)) assert_allclose(meijering(a_black, black_ridges=True), meijering(a_white, black_ridges=False)) assert_allclose(sato(a_black, black_ridges=True, mode='mirror'), sato(a_white, black_ridges=False, mode='mirror')) assert_allclose(frangi(a_black, black_ridges=True), zeros, atol=1e-3) assert_allclose(frangi(a_white, black_ridges=False), zeros, atol=1e-3) assert_allclose(hessian(a_black, black_ridges=True, mode='mirror'), ones, atol=1 - 1e-7) assert_allclose(hessian(a_white, black_ridges=False, mode='mirror'), ones, atol=1 - 1e-7)
def test_3d_cropped_camera_image(): a_black = crop(cp.asarray(camera()), ((200, 212), (100, 312))) a_black = cp.dstack([a_black, a_black, a_black]) a_white = invert(a_black) zeros = cp.zeros((100, 100, 3)) ones = cp.ones((100, 100, 3)) # TODO: determine why the following allclose checks occassionally fail assert_allclose(meijering(a_black, black_ridges=True), meijering(a_white, black_ridges=False)) assert_allclose(sato(a_black, black_ridges=True, mode='mirror'), sato(a_white, black_ridges=False, mode='mirror')) assert_allclose(frangi(a_black, black_ridges=True), zeros, atol=1e-3) assert_allclose(frangi(a_white, black_ridges=False), zeros, atol=1e-3) assert_allclose(hessian(a_black, black_ridges=True, mode='mirror'), ones, atol=1 - 1e-7) assert_allclose(hessian(a_white, black_ridges=False, mode='mirror'), ones, atol=1 - 1e-7)
def test_zero_crop(): arr = cp.arange(45).reshape(9, 5) out = crop(arr, 0) assert out.shape == (9, 5)
def test_multi_crop(): arr = cp.arange(45).reshape(9, 5) out = crop(arr, ((1, 2), (2, 1))) assert_array_equal(out[0], [7, 8]) assert_array_equal(out[-1], [32, 33]) assert out.shape == (6, 2)
def test_int_tuple_crop(): arr = cp.arange(45).reshape(9, 5) out = crop(arr, (1,)) assert_array_equal(out[0], [6, 7, 8]) assert_array_equal(out[-1], [36, 37, 38]) assert out.shape == (7, 3)
def test_pair_tuple_crop(): arr = cp.arange(45).reshape(9, 5) out = crop(arr, ((1, 2),)) assert_array_equal(out[0], [6, 7]) assert_array_equal(out[-1], [31, 32]) assert out.shape == (6, 2)