def test_center_image(): # BASEX sample image, Gaussians at 10, 15, 20, 70,85, 100, 145, 150, 155 # image width, height n = 361, origin = (180, 180) IM = abel.tools.analytical.SampleImage(n=361, name="dribinski").image # artificially displace origin, now at (179, 182) IMx = shift(IM, (-1, 2)) true_origin = (179, 182) # find_origin using 'slice' method origin = find_origin(IMx, method="slice") assert_allclose(origin, true_origin, atol=1) # find_origin using 'com' method origin = find_origin(IMx, method="com") assert_allclose(origin, true_origin, atol=1) # check single axis - vertical # center shifted image IMx in the vertical direction only IMc = center_image(IMx, method="com", axes=1) # determine the origin origin = find_origin(IMc, method="com") assert_allclose(origin, (179, 180), atol=1) # check single axis - horizontal # center shifted image IMx in the horizontal direction only IMc = center_image(IMx, method="com", axes=0) origin = find_origin(IMc, method="com") assert_allclose(origin, (180, 182), atol=1) # check even image size returns odd # drop off one column, to make an even column image IM = IM[:, :-1] m, n = IM.shape IMy = center_image(IM, method="slice", odd_size=True) assert_allclose(IMy.shape, (m, n - 1))
def test_centering_function_shape(): # ni -> original shape # n -> result of the centering function for (y, x) in [(20, 11), # crop image (21, 11), (5, 11), # pad image (4, 11)]: data = np.zeros((y, x)) res = center_image(data, (y//2, x//2)) assert_equal( res.shape, (y, x), 'Centering preserves shapes for ni={}, n={}'.format(y, x))
def test_centering_function_shape(): # ni -> original shape # n -> result of the centering function for (y, x) in [ (20, 11), # crop image (21, 11), (5, 11), # pad image (4, 11) ]: data = np.zeros((y, x)) res = center_image(data, (y // 2, x // 2)) assert_equal(res.shape, (y, x), 'Centering preserves shapes for ni={}, n={}'.format(y, x))
def test_centering_function(): # ni -> original shape of the data is (ni, ni) # n_c -> the image center is (n_c, n_c) for (ni, n_c) in [(10, 5), (10, 5), ]: arr = np.zeros((ni, ni)) # arr[n_c-1:n_c+2,n_c-1:n_c+2] = 1 # # else: arr[n_c-1:n_c+1,n_c-1:n_c+1] = 1.0 res = center_image(arr, (n_c, n_c), odd_size=False) # The print statements below can be commented after we fix the centering issue # print('Original array') # print(arr) # print('Centered array') # print(res) assert_equal( is_symmetric(res), True,\ 'Validating the centering function for ni={}, n_c={}'.format(ni, n_c))
def test_centering_function(): # ni -> original shape of the data is (ni, ni) # n_c -> the image center is (n_c, n_c) for (ni, n_c) in [ (10, 5), (10, 5), ]: arr = np.zeros((ni, ni)) # arr[n_c-1:n_c+2,n_c-1:n_c+2] = 1 # # else: arr[n_c - 1:n_c + 1, n_c - 1:n_c + 1] = 1.0 res = center_image(arr, (n_c, n_c), odd_size=False) # The print statements below can be commented after we fix the centering issue # print('Original array') # print(arr) # print('Centered array') # print(res) assert_equal( is_symmetric(res), True,\ 'Validating the centering function for ni={}, n_c={}'.format(ni, n_c))