码迷,mamicode.com
首页 > 编程语言 > 详细

利用python拼接图片

时间:2018-03-07 21:43:50      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:images   post   http   path   pil   技术分享   pre   class   []   

问题描述: 将16张图片拼接成4x4的图片, 且不改变每单张图片的像素值.

代码如下:

 1 import os
 2 from PIL import Image
 3 path = /share1/home/cong/Datasets/resized_Polyvore/pair1/pair1
 4 imglist = os.listdir(path)
 5 imglist.sort()
 6 imglist = imglist[:16]
 7 images = []
 8 for item in imglist:
 9     images.append(Image.open(path + / + item))
10 
11 h, w = 128, 128
12 target = Image.new(RGBA, (w * 4, h * 4))
13 for idx, img in enumerate(images):
14     i = idx % 4
15     j = idx // 4
16     target.paste(img, (i * w, j * h, i * w + w, j * h + h))
17 
18 target.save(. + / + real.png)

效果如下:

技术分享图片

利用python拼接图片

标签:images   post   http   path   pil   技术分享   pre   class   []   

原文地址:https://www.cnblogs.com/congyucn/p/8524994.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!