我有一个 4D 数据 np.array,由 150 个图像 50X70 组成,分解为 3 个通道。
数据的形状为 (150, 50, 70, 3)。我需要按通道计算这 150 张图像的平均值,形状为 (50, 70, 3)(其中 R 通道的平均值将是 150 个 R 通道的平均值等)我试过了:
average = data.mean(axis=0)
averageimage = Image.fromarray(average, 'RGB')
averageimage.show()
但即使它给出了正确的形状,图像看起来也像是随机的颜色噪声。
编辑:我试过
def average_image(a_lot_of_images):
avg = np.zeros((a_lot_of_images.shape[1], a_lot_of_images.shape[2], a_lot_of_images.shape[3]))
for i in range(a_lot_of_images.shape[0]):
avg[:,:,0] += a_lot_of_images[i,:,:,0]
avg[:,:,1] += a_lot_of_images[i,:,:,1]
avg[:,:,2] += a_lot_of_images[i,:,:,2]
for i in [0,1,2]:
avg[:,:,i] = avg[:,:,i]/a_lot_of_images.shape[0]
return avg
并且输出看起来仍然像彩色噪声。