Python – Wand 中的 distort() 方法
ImageMagick 通过对用户提供的参数应用各种转换,提供了几种扭曲图像的方法。在 Wand 中,使用了distort()方法,并遵循一个基本函数。
句法 :
wand.image.distort(method, arguments, best_fit)
参数 :Parameter Input Type Description method basestring Black point, as a percentage of the system’s quantum range. Defaults to 0.. arguments collections.abc.Sequence Distortion method name from DISTORTION_METHODS. best_fit bool Attempt to resize resulting image fit distortion. Defaults False.
以下是失真方法:Distortion Method Description ‘undefined’ default Distortion Method ‘affine’ parallel type of distortion. ‘affine_projection’ kind of 3 parallelogram projection. ‘scale_rotate_translate’ transformation distortion ‘perspective’ 3 dimensional outwards projection distortion. ‘perspective_projection’ creates a away perspective. ‘bilinear_forward’ based on bilinear equation. ‘bilinear_reverse’ based on reverse bilinear equation. ‘polynomial’ based on polynomial. ‘arc’ creates a circular curve of image. ‘polar’ creates a polar distortion effect. ‘depolar’ creates a depolar distortion effect. ‘cylinder_2_plane’ creates a cylinder to plane distortion effect. ‘plane_2_cylinder’ creates a plane to cylinder distortion effect. ‘barrel’ creates outwards bump on 2d image. ‘barrel_inverse’ creates inwards bump on 2d image. ‘resize’ resize distortion image. ‘sentinel’ creates sentinel image distortion.
源图像:
代码示例 1:
Python3
# Import Image from wand.image module
from wand.image import Image
# Read image using Image function
with Image(filename ="gog.png") as img:
img.distort('arc', (45, ))
img.save(filename ='gogdistort1.png')
Python3
# Import Image from wand.image module
from wand.image import Image
# Read image using Image function
with Image(filename ="gog.png") as img:
arguments = (0, 0, 20, 60,
90, 0, 70, 63,
0, 90, 5, 83,
90, 90, 85, 88)
img.distort('perspective', arguments)
img.save(filename ='gogdistort.png')
输出图像:
代码示例 2:
将 DISTORTION_METHOD 更改为“透视”。
Python3
# Import Image from wand.image module
from wand.image import Image
# Read image using Image function
with Image(filename ="gog.png") as img:
arguments = (0, 0, 20, 60,
90, 0, 70, 63,
0, 90, 5, 83,
90, 90, 85, 88)
img.distort('perspective', arguments)
img.save(filename ='gogdistort.png')
输出图像: