📜  Python中的魔杖仿射扭曲()函数

📅  最后修改于: 2022-05-13 01:55:45.011000             🧑  作者: Mango

Python中的魔杖仿射扭曲()函数

仿射失真方法对图像进行剪切操作。参数与透视变形方法类似,但只需要一对 3 点和 12 个实数,方式如下所示:

src1x, src1y, dst1x, dst1y,
src2x, src2y, dst2x, dst2y,
src3x, src3y, dst3x, dst3y

输入图像:

示例 #1:

Python3
# 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.resize(140, 92)
    img.background_color = Color('skyblue')
    img.virtual_pixel = 'background'
    args = (
        10, 10, 15, 15,  # Point 1: (10, 10) => (15,  15)
        139, 0, 100, 20, # Point 2: (139, 0) => (100, 20)
        0, 92, 50, 80    # Point 3: (0,  92) => (50,  80)
    )
    # affline distortion using distort function
    img.distort('affine', args)
    img.save(filename ="afflinegfg.png")


Python3
# 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.resize(140, 92)
    img.background_color = Color('skyblue')
    img.virtual_pixel = 'background'
    args = (
        20, 21, 12, 11,  # Point 1: (10, 10) => (15,  15)
        38, 1, 17, 0, # Point 2: (139, 0) => (100, 20)
        7, 92, 50, 80    # Point 3: (0,  92) => (50,  80)
    )
    # affline distortion using distort function
    img.distort('affine', args)
    img.save(filename ="afflinegfg2.png")


输出:

示例 #2:
改变参数值。

Python3

# 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.resize(140, 92)
    img.background_color = Color('skyblue')
    img.virtual_pixel = 'background'
    args = (
        20, 21, 12, 11,  # Point 1: (10, 10) => (15,  15)
        38, 1, 17, 0, # Point 2: (139, 0) => (100, 20)
        7, 92, 50, 80    # Point 3: (0,  92) => (50,  80)
    )
    # affline distortion using distort function
    img.distort('affine', args)
    img.save(filename ="afflinegfg2.png")

输出: