def _shift_interp(array, shift_value, mode='constant', cval=0):
# Manual alternative to built-in function: slightly slower
Ndim = array.ndim
dims = array.shape
dtype = array.dtype.kind
if (Ndim == 1):
pass
elif (Ndim == 2):
x, y = np.meshgrid(np.arange(dims[1], dtype=dtype), np.arange(dims[0], dtype=dtype))
x -= shift_value[0]
y -= shift_value[1]
shifted = ndimage.map_coordinates(img, [y, x], mode=mode, cval=cval)
return shifted
评论列表
文章目录