matplotlib.pyplot 透视变换 Image.PERSPECTIVE

编程入门 行业动态 更新时间:2024-10-27 10:26:43

matplotlib.pyplot 透视变换

import math
import matplotlib.pyplot as plt
from PIL import Image


if __name__ == '__main__':
    img = Image.open('./example.png').resize((128, 128))
    params = [
        [0.5, 0.0, -64, 0.0,  1.0, -64, 0.0, 0.0],
        [1.5, 0.0, -64, 0.0,  1.0, -64, 0.0, 0.0],

        [1.0, 0.0, -64, 0.0,  0.5, -64, 0.0, 0.0],
        [1.0, 0.0, -64, 0.0,  1.5, -64, 0.0, 0.0],

        [1.0, 0.5, -64, 0.0,  1.0, -64, 0.0, 0.0],
        [1.0, -.5, -64, 0.0,  1.0, -64, 0.0, 0.0],

        [1.0, 0.0, -64, 0.5,  1.0, -64, 0.0, 0.0],
        [1.0, 0.0, -64, -.5,  1.0, -64, 0.0, 0.0],

        [1.0, 0.0, -32, 0.0,  1.0, -64, 0.0, 0.0],
        [1.0, 0.0, -64, 0.0,  1.0, -32, 0.0, 0.0],

        [1.0, 0.0, -64, 0.0,  1.0, -64, 0.001, 0.0],
        [1.0, 0.0, -64, 0.0,  1.0, -64, -0.001, 0.0],

        [1.0, 0.0, -64, 0.0,  1.0, -64, 0.0, 0.001],
        [1.0, 0.0, -64, 0.0,  1.0, -64, 0.0, -0.001],

        [1.0, 0.0, -64, 0.0,  1.0, -64, 0.0, 0.0],
    ]
    plt.rcParams['figure.figsize'] = (16.0, 8.0)
    row, col = math.ceil(len(params)/5), 5
    plt.subplots(row, col, constrained_layout=True)
    for i in range(len(params)):
        plt.subplot(row, col, i+1)
        plt.imshow(img.transform((256, 256), Image.PERSPECTIVE, params[i]))
        plt.title(
            '['+(', '.join(['%.3f' % e for e in params[i]]))+']',
            fontsize=7
        )
    plt.show()

输出

更多推荐

matplotlib.pyplot 透视变换 Image.PERSPECTIVE

本文发布于:2023-06-13 15:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1383128.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:透视   pyplot   matplotlib   Image   PERSPECTIVE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!