使用skimag旋转图像而不剪切它

2024-06-26 14:40:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我用一个缩放的图像来翻译。返回的图像使用原始图像形状,从而裁剪原始图像。如何返回包含整个原始图像的图像?在

from skimage import data
from skimage import transform as tf
import numpy as np
import matplotlib.pyplot as plt
import math

image = data.chelsea()

tform = tf.SimilarityTransform(scale=1, rotation=math.pi / 4,
                               translation=(image.shape[0] / 2, -100))    

rotated = tf.warp(image, tform)

plt.imshow(rotated)

enter image description here


Tags: from图像imageimportnumpydatatfas
2条回答
import skimage

#Set the argument **resize = True** to get the uncropped 
skimage.transform.rotate(image,angle=45,resize=False, mode='constant')

如果允许使用scikit-image以外的库(正如您在评论中提到的那样),那么scipy只有the tool用于此:

import matplotlib.pyplot as plt
from scipy.ndimage.interpolation import rotate
import scipy.misc
lena = scipy.misc.lena()
rotated_lena = rotate(lena, 30, reshape=True)
f, (ax0,ax1) = plt.subplots(1,2)
ax0.imshow(lena, cmap='gray')
ax1.imshow(rotated_lena, cmap='gray')
plt.show()  # shows a normal version of Lena and a version that is rotated by 30° CCW, uncropped

相关问题 更多 >