【发布时间】:2020-05-10 00:00:16
【问题描述】:
我有一个 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
并且输出看起来仍然像颜色噪声。
【问题讨论】:
标签: python-imaging-library rgb mean numpy-ndarray tensor