其他分享
首页 > 其他分享> > matplotlib.pyplot 透视变换 Image.PERSPECTIVE

matplotlib.pyplot 透视变换 Image.PERSPECTIVE

作者:互联网

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()

在这里插入图片描述

标签:__,plt,1.0,0.0,pyplot,matplotlib,64,PERSPECTIVE,params
来源: https://blog.csdn.net/weixin_44763595/article/details/120616860