# Reorient the displacement field according to its grid-to-space # transform dcopy = np.copy(d) vfu.reorient_vector_field_3d(dcopy, field_grid2world) extended_dcopy = np.zeros((ns + 2, nr + 2, nc + 2, 3), dtype=floating) extended_dcopy[1:ns + 1, 1:nr + 1, 1:nc + 1, :] = dcopy # Compute the warping coordinates (see warp_2d documentation) Y = np.apply_along_axis(A.dot, 0, X)[0:3, ...] Z = np.zeros_like(X) Z[0, ...] = map_coordinates(extended_dcopy[..., 0], Y + 1, order=1) Z[1, ...] = map_coordinates(extended_dcopy[..., 1], Y + 1, order=1) Z[2, ...] = map_coordinates(extended_dcopy[..., 2], Y + 1, order=1) Z[3, ...] = 0 Z = np.apply_along_axis(C.dot, 0, Z)[0:3, ...] T = np.apply_along_axis(B.dot, 0, X)[0:3, ...] W = T + Z # Test bilinear interpolation # expected = map_coordinates(sphere, W, order=1) # warped = vfu.warp_3d(sphere, dcopy, A, B, C, # np.array(sh, dtype=np.int32)) # np.save('sl_syn_warp_3d.npy', warped) # Test nearest neighbor interpolation expected = map_coordinates(sphere, W, order=0) warped = vfu.warp_3d_nn(sphere, dcopy, A, B, C, np.array(sh, dtype=np.int32)) # assert_array_almost_equal(warped, expected, decimal=5) np.save('sl_syn_warp_3d_nn.npy', warped)