在 python 中倾斜或剪切图像

问题描述 投票:0回答:1

我需要使用 Python 剪切和倾斜一些图像。我遇到过this skimage module但我真的不明白我应该如何使用它。

我尝试了一些以错误告终的事情,因为后来我意识到我没有将图像传递给函数。然后我注意到该函数首先没有将我的图像作为输入参数。那么,应该如何应用转换呢?或者,这不是为了倾斜或剪切图像而需要查看的正确函数吗?

python image-processing numpy transformation scikit-image
1个回答
23
投票

如果你想使用 skimage 模块,操作顺序是:

  • 加载图像或定义要使用的数据
  • 创造你想要的转变
  • 应用转换

工作流程可能如下所示:

from skimage import io
from skimage import transform as tf

# Load the image as a matrix
image = io.imread("/path/to/your/image.jpg")

# Create Afine transform
afine_tf = tf.AffineTransform(shear=0.2)

# Apply transform to image data
modified = tf.warp(image, inverse_map=afine_tf)

# Display the result
io.imshow(modified)
io.show()

skimage 模块中的

AffineTransform
类接受一个 transformation matrix 作为它的第一个参数(如果您使用其他参数,该类将构造该矩阵)。

© www.soinside.com 2019 - 2024. All rights reserved.