Python中的魔杖affline_projection失真方法
仿射投影与 scale_rotate_translate 失真类型非常相似。唯一的区别是失真参数需要六个实数。
Scalex, Rotatex, Rotatey, Scaley, Translatex, Translatey
源图像:
示例 #1:
from collections import namedtuple
# Import Color from wand.color module
from wand.color import Color
# Import Image from wand.image module
from wand.image import Image
Point = namedtuple('Point', ['x', 'y'])
with Image(filename ='gog.png') as img:
img.background_color = Color('skyblue')
img.virtual_pixel = 'background'
rotate = Point(0.1, 0)
scale = Point(0.7, 0.6)
translate = Point(5, 5)
args = (
scale.x, rotate.x, rotate.y,
scale.y, translate.x, translate.y
)
img.distort('affine_projection', args)
img.save(filename ="afflinegfg.png")
输出 :
示例 #2:
改变参数值。
# Import Color from wand.color module
from wand.color import Color
# Import Image from wand.image module
from wand.image import Image
with Image(filename ='gog.png') as img:
img.background_color = Color('skyblue')
img.virtual_pixel = 'background'
rotate = Point(0.1, 0.3)
scale = Point(0.9, 0.2)
translate = Point(7, 5)
args = (
scale.x, rotate.x, rotate.y,
scale.y, translate.x, translate.y
)
img.distort('affine_projection', args)
img.save(filename ="afflinegfg2.png")
输出 :
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。