2017-09-08 19 views
1

私は、元の画像を生成するために反転することができる、Pythonの回転変換を探しています。私はreflectを使用して同じ操作を行う場合はこれまでのところ、私は画像の反転可能な回転

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

を使用していた結果は

のように見えます

Result using 'reflect'

単にangleて画像を回転させると-angleバック結果を回転させると、元の画像で終わるためにpossibiltyはありますか?

答えて

1

rotateを使用して、オプションの引数resizeTrueに設定してから、最終結果をトリミングします。

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) 

元と画像の間に若干の違いがあります回転機能の内部が、それは同じように見える目に起因する操作に2回転。

+0

これはまさに私が探していたものです。ありがとうございました。もちろん、画像は補間のために少し異なりますが、これはその方法です。 – Dschoni

関連する問題