gpt4 book ai didi

python - 使用 skimage 旋转图像而不裁剪它

转载 作者:行者123 更新时间:2023-11-28 16:34:39 26 4
gpt4 key购买 nike

我正在使用 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

最佳答案

如果图书馆不是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

关于python - 使用 skimage 旋转图像而不裁剪它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28050544/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com