图像的可逆旋转

问题描述:

我正在寻找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'

是否有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) 

将有原始和图像之间的细微差别旋转两次因旋转功能里面的操作,但对眼睛看起来相同。

+0

这正是我一直在寻找的。谢谢。当然,由于插值,图像会有点不同,但这是如何的。 – Dschoni