赞
踩
Stefan答案中的图像中心似乎不正确,下面是他的代码的正确版本from skimage import transform
import numpy as np
import matplotlib.pyplot as plt
image = np.zeros([21, 21])
image[10,:] = 1
image[10,10] = 5
image[7, 10] = 1
shift_y, shift_x = (np.array(image.shape)-1) / 2.
tf_rotate = transform.SimilarityTransform(rotation=np.deg2rad(60))
tf_shift = transform.SimilarityTransform(translation=[-shift_x, -shift_y])
tf_shift_inv = transform.SimilarityTransform(translation=[shift_x, shift_y])
image_rotated = transform.warp(image, (tf_shift + (tf_rotate + tf_shift_inv)).inverse, order = 3)
plt.subplot(121)
plt.imshow(image)
plt.subplot(122)
plt.imshow(image_rotated)
plt.show()
print "original image maximum at: ", np.unravel_index(np.argmax(image), image.shape)
print "rotated image maximum at : ", np.unravel_index(np.argmax(image_rotated), image_rotated.shape)
原始图像最大值为:(10,10)
旋转图像的最大值为:(10,10)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。