问问题
8273 次
2 回答
3
这目前可以通过组合以下转换来实现:
- 移动图像,使中心围绕原点
- 旋转 N 度
- 将图像向后移动
但是,单个参数会使这更容易!您能否在 GitHub 上提出问题,以便我们实施?
与此同时,代码:
from skimage import data
from skimage import transform
import numpy as np
import matplotlib.pyplot as plt
image = data.chelsea()
shift_y, shift_x = np.array(image.shape[:2]) / 2.
tf_rotate = transform.SimilarityTransform(rotation=np.deg2rad(30))
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)
plt.imshow(image_rotated)
plt.show()
于 2014-09-22T12:23:49.497 回答
2
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)
于 2016-03-16T19:23:55.753 回答