图像的可逆旋转
问题描述:
我正在寻找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
结果看起来像
是否有possibilty简单地通过旋转的angle
图像与-angle
旋转结果返回并与原始图像结束了?
答
您的问题的一个可能的解决方案将使用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)
将有原始和图像之间的细微差别旋转两次因旋转功能里面的操作,但对眼睛看起来相同。
这正是我一直在寻找的。谢谢。当然,由于插值,图像会有点不同,但这是如何的。 – Dschoni