对于从FITS文件中读取的图像,我有一个numpy数组。我用scipy.ndimage.interpolation.rotate把它旋转了N度。然后我想找出原始非旋转帧中的某个点(x,y)在旋转图像中的位置--也就是说,旋转的帧坐标(x',y')是多少?
这应该是一个非常简单的旋转矩阵问题,但是如果我做了通常的基于数学或编程的旋转方程,新的(x',y')就不会在原来的地方结束。我怀疑这与需要一个平移矩阵有关,因为枕叶旋转函数是基于原点(0,0)而不是图像阵列的实际中心。
有人能告诉我如何得到旋转的框架(x',y')吗?举个例子,你可以用
from scipy import misc
from scipy.ndimage import rotate
data_orig = misc.face()
data_rot = rotate(data_orig,66) # data array
x0,y0 = 580,300 # left eye; (xrot,yrot) should point thereP.S.以下两个相关问题的回答对我没有帮助:
发布于 2017-10-10 14:13:01
像通常的旋转,一个人需要转换到原点,然后旋转,然后再转换回来。在这里,我们可以把图像的中心作为起源。
import numpy as np
import matplotlib.pyplot as plt
from scipy import misc
from scipy.ndimage import rotate
data_orig = misc.face()
x0,y0 = 580,300 # left eye; (xrot,yrot) should point there
def 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_center
fig,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()

https://stackoverflow.com/questions/46657423
复制相似问题