I am looking for a rotational transform in python, that can be inverted to yield the original image. So far I am using
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')
If I do the same using reflect
the result looks like
Is there a possibilty to simply rotate an image by angle
and rotate the result back by -angle
and end up with the original image?
A potential solution to your problem would be to use rotate
with the optional argument resize
set to True
, and then to crop the final result.
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)
There will be minor differences between the original and the image rotated twice due to the operations inside the rotation function, but to the eye it looks the same.