当前位置: 首页 > 工具软件 > tf.Transform > 使用案例 >

python transformat_python:skimage.transform.AffineTransform旋转中心

曹高轩
2023-12-01

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)

 类似资料: