不裁剪图像的情况下旋转图像,使用skimage

3
我正在使用skimage来旋转、缩放和平移图像。返回的图像使用原始图像的形状,因此裁剪了原始图像。如何返回一个包含整个原始图像的图像?
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


不确定这是否能解决您的问题,但您可以根据边界矩形计算比例参数,从而将图像缩小。 - Linuxios
真的必须使用skimage吗?这个功能在scipy中也存在,而且不需要裁剪。 - Oliver W.
任何工具都可以。 你有使用Scipy的代码示例吗? - ADJ
1
如果您不需要同时进行多个转换,请只使用transform.rotate(img, angle, resize=True) - Ciprian Tomoiagă
2个回答

3

如果允许使用除了scikit-image之外的库(正如您在评论中提到的),那么scipy就有这个工具

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

2
import skimage

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接