zoukankan      html  css  js  c++  java
  • 利用python拼接图片

    问题描述: 将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')

    效果如下:

  • 相关阅读:
    Celery
    windows笔记目录
    Linux笔记目录
    python笔记目录
    rsa
    c#目录
    webpack3.x配置
    RabbitMQ服务安装(Linux)
    JavaScript验证用户输入
    IP地址检测工具
  • 原文地址:https://www.cnblogs.com/congyucn/p/8524994.html
Copyright © 2011-2022 走看看