可反转的图像旋转

时间:2017-09-08 12:23:20

标签: python rotation image-rotation scikit-image

我正在寻找python中的旋转变换,可以反转以产生原始图像。到目前为止我正在使用

import skimage.transform as tf
import scipy
im = scipy.misc.ascent()

Original, unrotated image

r1 = tf.rotate(im, 10, mode='wrap')

Image rotated 10 degrees

r2 = tf.rotate(r1, -10, mode='wrap')

Rotated Image inversely rotated

如果我使用reflect执行相同的操作,结果会显示为

Result using 'reflect'

是否有可能简单地按angle旋转图像并将结果旋转回-angle并最终得到原始图像?

1 个答案:

答案 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)

由于旋转功能内部的操作,原稿和旋转图像之间会有微小的差异,但眼睛看起来是一样的。