import os
from PIL import Image
def image_Splicing(img_1, img_2, img_3, flag='x'):
img1 = Image.open(img_1)
img2 = Image.open(img_2)
img3 = Image.open(img_3)
dir_save = "/media/algo/show_20221017/joint/"
name = img_1.split("/")[-1][3:]
path_save = dir_save + name
size1, size2, size3 = img1.size, img2.size, img3.size
if flag == 'x':
joint = Image.new("RGB", (size1[0] + size2[0] + size3[0], size1[1]))
loc1, loc2, loc3 = (0, 0), (size1[0], 0), (size1[0] + size2[0], 0)
else:
joint = Image.new("RGB", (size1[0], size2[1]+size1[1]))
loc1, loc2 = (0, 0), (0, size1[1])
joint.paste(img1, loc1)
joint.paste(img2, loc2)
joint.paste(img3, loc3)
joint.save(path_save)
def get_img_path(path):
list_img = os.listdir(path)
out = []
for name in list_img:
path_img = path + name
out.append(path_img)
return out
# path_img1 = "/media/algo/show_20221017/L2/L2_conv2_1.png"
# path_img2 = "/media/algo/20221017/L1/L1_conv2_1.png"
# image_Splicing(path_img1, path_img2, flag='x')
#
path_dir_L2 = "/media/algo/show_20221017/L2/"
path_dir_L1 = "/media/algo/20221017/L1/"
path_dir_L1_sparse = "/media/algo/20221017/L1_sparse/"
list_img_L2 = get_img_path(path_dir_L2)
list_img_L1 = get_img_path(path_dir_L1)
list_img_L1_sparse = get_img_path(path_dir_L1_sparse)
for cnt, name in enumerate(list_img_L2):
print(cnt, name)
path_L2 = list_img_L2[cnt]
path_L1 = list_img_L1[cnt]
path_L1_sparse = list_img_L1_sparse[cnt]
image_Splicing(path_L2, path_L1, path_L1_sparse)
标签:size1,img,图像,list,拼接,L2,L1,path
From: https://www.cnblogs.com/yanghailin/p/16799196.html