def _rotate_interp(array, alpha, center, mode='constant', cval=0):
'''
Rotation around a provided center
This is the only way to be sure where exactly is the center of rotation.
'''
dtype = array.dtype
dims = array.shape
alpha_rad = -np.deg2rad(alpha)
x, y = np.meshgrid(np.arange(dims[1], dtype=dtype), np.arange(dims[0], dtype=dtype))
xp = (x-center[0])*np.cos(alpha_rad) + (y-center[1])*np.sin(alpha_rad) + center[0]
yp = -(x-center[0])*np.sin(alpha_rad) + (y-center[1])*np.cos(alpha_rad) + center[1]
rotated = ndimage.map_coordinates(img, [yp, xp], mode=mode, cval=cval, order=3)
return rotated
评论列表
文章目录