我正在寻找python中的旋转变换,可以反转以产生原始图像。到目前为止我正在使用
import skimage.transform as tf
import scipy
im = scipy.misc.ascent()
r1 = tf.rotate(im, 10, mode='wrap')
r2 = tf.rotate(r1, -10, mode='wrap')
如果我使用reflect
执行相同的操作,结果会显示为
是否有可能简单地按angle
旋转图像并将结果旋转回-angle
并最终得到原始图像?
答案 0 :(得分:1)
问题的一个潜在解决方案是使用rotate
并将可选参数resize
设置为True
,然后裁剪最终结果。
import skimage.transform as tf
import scipy
import matplotlib.pyplot as plt
im = scipy.misc.ascent()
r1 = tf.rotate(im, 10, mode='wrap', resize=True)
plt.imshow(r1)
r2 = tf.rotate(r1, -10, mode='wrap', resize=True)
plt.imshow(r2)
# Get final image by cropping
imf = r2[int(np.floor((r2.shape[0] - im.shape[0])/2)):int(np.floor((r2.shape[0] + im.shape[0])/2)),int(np.floor((r2.shape[1] - im.shape[1])/2)):int(np.floor((r2.shape[1] + im.shape[1])/2))]
plt.imshow(imf)
由于旋转功能内部的操作,原稿和旋转图像之间会有微小的差异,但眼睛看起来是一样的。