栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/653125.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号