This article mainly introduces the use of PIL numpy to realize splicing pictures in Python. It has a certain reference value. Now I share it with you. Friends in need can refer to it
##python vertical Merge any multiple pictures, files is a list of files to be spliced
# -*- coding:utf-8 -*- def mergeReport(files): from PIL import Image import numpy as np baseimg=Image.open(files[0]) sz = baseimg.size basemat=np.atleast_2d(baseimg) for file in files[1:]: im=Image.open(file) #resize to same width sz2 = im.size if sz2!=sz: im=im.resize((sz[0],round(sz2[0] / sz[0] * sz2[1])),Image.ANTIALIAS) mat=np.atleast_2d(im) basemat=np.append(basemat,mat,axis=0) report_img=Image.fromarray(basemat) report_img.save('merge.png')
numpy performs array splicing and merges examples on rows and columns respectively
numpy implements the extension method of merging multi-dimensional matrices and lists
The above is the detailed content of Python uses PIL numpy to stitch pictures. For more information, please follow other related articles on the PHP Chinese website!