def affine_zoom( img, zoom, spin = 0 ):
'''Returns new image derived from img, after a central-origin affine transform has been applied'''
img_copy = img.copy()
# Shift transforms allow Affine to be applied with centre of image as 0,0
shift_y, shift_x, _ = (np.array(img_copy.shape)-1) / 2.
shift_fwd = transform.SimilarityTransform(translation=[-shift_x, -shift_y])
shift_back = transform.SimilarityTransform(translation=[shift_x, shift_y])
affine = transform.AffineTransform( scale=(zoom, zoom), rotation=(spin * math.pi/180) )
img_copy = transform.warp( img_copy,
( shift_fwd + ( affine + shift_back )).inverse,
order=3,
clip=False, preserve_range=True,
mode='reflect').astype(np.float32)
return img_copy
评论列表
文章目录