本文摘自php中文网,作者不言,侵删。
这篇文章主要介绍了关于Python 使用PIL numpy 实现拼接图片,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下python纵向合并任意多个图片,files是要拼接的文件list
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # -*- 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 进行数组拼接,分别在行和列上合并的实例
numpy实现合并多维矩阵、list的扩展方法
以上就是Python 使用PIL numpy 实现拼接图片的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python使用join的两个实例分享
Python 限制函数调用次数
Python自学文件操作
Python Pythonpath是什么意思?
Python爬虫看哪本书
Python单行注释用什么符号
学Python需要什么软件
Python介绍 list.sort方法和内置函数sorted
Python中header是什么意思
Python如何缩进
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python 使用PIL numpy 实现拼接图片