import cv2 import numpy as np from PIL import Image import matplotlib.pyplot as plt #使用cv2读取图片 img = cv2.imread('1.png',0) print(img.shape) img1 = cv2.imread('2.png',0) print(img1.shape) img2 = cv2.imread('3.png',0) print(img2.shape) #将所有图片转换为相同的大小 img = np.resize(img,(255,64)) print(img.shape) img1 = np.resize(img1,(255,64)) print(img1.shape) img2 = np.resize(img2,(255,64)) print(img2.shape) com = np.array([img, img1, img2]) print(合并矩阵:\n', com) print维数: com.shape) com=np.swapaxes(com,2.0)#转换三维矩阵X,Z轴的位置,将3放在Z轴上,直接转换为RGB三色图 com=np.swapaxes(com,0,1)#将X,Y轴交换位置,输出图片垂直 print维数: com.shape) com = Image.fromarray(com).convert('RGB') # 将数组转换回图片s com.save("out.png") # 将数组保存为图片