在python中歪曲或剪切图像 [英] skewing or shearing an image in python

查看:258
本文介绍了在python中歪曲或剪切图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用python剪切和倾斜一些图像。
我遇到了这个影像模块但我似乎无法完全理解我应该如何使用它。

I need to shear and skew some images using python. I've come across this skimage module but I don't seem able to understand exactly how I'm supposed to use this.

我尝试了一些东西,这显然给了我的错误,因为我后来突然意识到,我没有将我的图像传递给函数。然后我注意到该函数首先不将我的图像作为输入参数。那么应该如何应用转型呢?或者这甚至是正确的功能,以便倾斜或剪切图像?

I've tried a few things, which obviously gave me errors, because as I suddenly realized later, I'm not passing in my image to the function. I then noticed that the function doesn't take my image as an input parameter in the first place. So how should the transformation be applied? Or is this even the right function to be looking at in order to skew or shear an image?

推荐答案

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

If you want to use the skimage module the order of operations are:


  • 加载图像或定义要使用的数据

  • 创建所需的转换

  • 应用转换

工作流程可能如下所示:

A work flow might look like the following:

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 类接受转换矩阵作为它的第一个参数(如果您改为使用其他参数,则构造该类)。

The AffineTransform class from the skimage module accepts a transformation matrix as its first parameter (which the class constructs if you instead use the other parameters).

这篇关于在python中歪曲或剪切图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆