Python 3.x 如何使用python连接多个图像(平铺)以形成单个图像?

Python 3.x 如何使用python连接多个图像(平铺)以形成单个图像?,python-3.x,image,python-imaging-library,Python 3.x,Image,Python Imaging Library,我已经从OpenStreetMaps下载了多个互动程序,我需要加入所有互动程序以形成一个图像,事实上,我对这个主题非常陌生,我知道的不多 到目前为止,我制作了一个小脚本来连接瓷砖,目的是连接瓷砖,使它们彼此吻合,从而形成地图区域的图像。。。使用脚本,我成功地加入了tile,但问题不是它们不匹配 我和大家分享我的剧本,如果你能给我任何帮助,我将不胜感激 这是我的纸条: import numpy as np from PIL import Image import glob def join_im

我已经从OpenStreetMaps下载了多个互动程序,我需要加入所有互动程序以形成一个图像,事实上,我对这个主题非常陌生,我知道的不多

到目前为止,我制作了一个小脚本来连接瓷砖,目的是连接瓷砖,使它们彼此吻合,从而形成地图区域的图像。。。使用脚本,我成功地加入了tile,但问题不是它们不匹配

我和大家分享我的剧本,如果你能给我任何帮助,我将不胜感激

这是我的纸条:

import numpy as np
from PIL import Image
import glob

def join_images_horizontally(imgs):
    '''
    Esta función une imagenes horizontalmente.
    '''
    #crea dos listas: una para alturas y otra para anchuras
    widths, heights = zip(*(i.size for i in imgs))
    width_of_new_image = sum(widths)
    height_of_new_image = min(heights) #toma la altura minima
    # crear nueva imagen
    new_im = Image.new('RGB', (width_of_new_image, height_of_new_image))
    new_pos = 0
    for im in imgs:
        new_im.paste(im, (new_pos,0))
        new_pos += im.size[0] #position for the next image
    new_im.save('/home/orlando/git/orlando3dmaps/src/imghorizontal.png')


def join_images_vertically(imgs):
    '''
    Esta función une imagenes verticalmente.
    '''
    #crea dos listas: una para alturas y otra para anchuras
    widths, heights = zip(*(i.size for i in imgs))
    width_of_new_image = min(widths)  #toma la altura minima
    height_of_new_image = sum(heights)
    # ccrear nueva imagen
    new_im = Image.new('RGB',(width_of_new_image, height_of_new_image))
    new_pos = 0
    for im in imgs:
        new_im.paste(im, (0, new_pos))
        new_pos += im.size[1] #posicion para la siguiente imagen
    new_im.save('/home/orlando/git/orlando3dmaps/src/imgvertical.png')


def main():
    '''
    Inicializa el código.
    '''
    # Abrir archivos de imagen
    imgs = [Image.open(im) for im in list_im]
    
    ###fusionar imagenes horizontalmente
    #join_images_horizontally(imgs)
    
    ###fusionar imagenes verticalmente
    join_images_vertically(imgs)

#lista de imagenes
list_im = glob.glob("/home/orlando/git/orlando3dmaps/src/tiles/11/494/*.png") #change it to use your images

if __name__ == '__main__':
    '''
    Este programa fusiona imagenes vertical y horizontalmente.
    '''
    main()
这将生成类似下图的输出:

加入的方式很好,但正如我所说的,问题是它们的顺序不正确,它们与地图不匹配

它应该是这样的:

提前感谢您的帮助