scipy.ndimage.interpolation.rotate之后旋转的图像坐标?

scipy.ndimage.interpolation.rotate之后旋转的图像坐标?,第1张

scipy.ndimage.interpolation.rotate之后旋转的图像坐标?

与平常一样,旋转时,需要平移原点,然后旋转,然后平移回原点。在这里,我们可以将图像的中心作为原点。

import numpy as npimport matplotlib.pyplot as pltfrom scipy import miscfrom scipy.ndimage import rotatedata_orig = misc.face()x0,y0 = 580,300 # left eye; (xrot,yrot) should point theredef rot(image, xy, angle):    im_rot = rotate(image,angle)     org_center = (np.array(image.shape[:2][::-1])-1)/2.    rot_center = (np.array(im_rot.shape[:2][::-1])-1)/2.    org = xy-org_center    a = np.deg2rad(angle)    new = np.array([org[0]*np.cos(a) + org[1]*np.sin(a), -org[0]*np.sin(a) + org[1]*np.cos(a) ])    return im_rot, new+rot_centerfig,axes = plt.subplots(2,2)axes[0,0].imshow(data_orig)axes[0,0].scatter(x0,y0,c="r" )axes[0,0].set_title("original")for i, angle in enumerate([66,-32,90]):    data_rot, (x1,y1) = rot(data_orig, np.array([x0,y0]), angle)    axes.flatten()[i+1].imshow(data_rot)    axes.flatten()[i+1].scatter(x1,y1,c="r" )    axes.flatten()[i+1].set_title("Rotation: {}deg".format(angle))plt.show()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5655240.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存