import numpy as np
from PIL import Image
# 此处为路径,将三张图像的路径对应自己的改一下
paths = ['tab101_11_16.png', 'tab10102_11_16.png', 'tab1010103_11_16.png']
img_array = ''
img = ''
# 行,列数
img = Image.open(paths[0])
shape = (img.height,img.width)
# 缩的比例 这里是2倍
r = 2
shape=int( shape[0]/r),int(shape[1]/r)
# 去除边缘空白的比例
height_ratio = 0.08
width_ratio = 0.08
def getImage(file,shape, height_ratio,width_ratio):
img = Image.open(v) # 打开图片
# 此处将单张图像进行缩放为统一大小,改为自己单张图像的平均尺寸即可
img = img.resize(shape, Image.ANTIALIAS)
img_array = np.array(img) # 转化为np array对象
h = int( shape[0] * height_ratio)
w = int(shape[1] * width_ratio)
s = img_array.shape
# 去除边缘空白的比例
return img_array[h:s[0]-h,w:s[1]-w,:]
for i, v in enumerate(paths):
if i == 0:
img_array = getImage(v,shape,height_ratio,width_ratio)
if i == 1:
img_array2 = getImage(v,shape,height_ratio,width_ratio)
img_array = np.concatenate((img_array, img_array2), axis=1) # 横向拼接
if i == 2:
img_array2 = getImage(v,shape,height_ratio,width_ratio)
s = img_array2.shape
img3 = img_array.copy()
img3.fill(255)
mid = int(s[1]/2)
# 将图复制到中间
img3[:,mid:-mid,:] = img_array2[:,:,:]
img_array = np.concatenate((img_array, img3), axis=0)# 纵向拼接
# 转化为图片
img = Image.fromarray(img_array)
# 保存图片
img.save('./img-1.png')