Home  >  Article  >  Backend Development  >  Python uses PIL numpy to stitch pictures

Python uses PIL numpy to stitch pictures

不言
不言Original
2018-05-08 16:48:372735browse

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

Related recommendations:


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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn