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