导入 7 张 .jpeg 图片(大小相同)的列表并将它们堆叠到 NxMx7 numpy 数组中

Importing list of 7 .jpeg pictures (all the same size) and stacking them into a NxMx7 numpy array

我正在尝试导入图像以堆叠到一个 numpy 数组中。我有这样的东西,但没有给我我需要的东西,而且似乎无法在网上找到答案。

import easygui as eg
import cv2
openfiles1 = eg.fileopenbox("Select the files to stack",  multiple=True)
stack = np.array([])
for item in openfiles1:
    pic = cv2.imread(item)
    stack =np.dstack(pic)

根据 np.dstack 文档,dstack 将 numpy 数组的元组作为参数。现在,在每个循环中,您都将堆栈变量重置为一个具有长度为 1 的元组的堆栈(您当前在循环中的一个图像)。相反,您可能想要这样的东西:

import easygui as eg
import cv2
openfiles1 = eg.fileopenbox("Select the files to stack",  multiple=True)
pics = []
for item in openfiles1:
    pics.append(cv2.imread(item))
stack = np.dstack(tuple(pics))

这将创建一个您要加入的数组列表(稍后您将其转换为不可变元组)。