图像的可逆旋转

Invertable rotation of an image

我正在 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 并最终得到原始图像?

您的问题的一个潜在解决方案是使用 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)

由于旋转函数内部的操作,原图和旋转了两次的图片会有细微的差别,但是肉眼看起来是一样的。