在图像列表上执行平均减法?

时间:2018-06-03 23:52:45

标签: numpy machine-learning computer-vision

我有一个形状(100,320,320)的numpy数组,100个图像,每个图像是320 * 320。

我尝试过:

mean = np.mean(train_x)
train_x -= mean

我得到Cannot cast ufunc subtract output from dtype('float64') to dtype('uint8') with casting rule 'same_kind'

有人可以指导我如何实现这个目标吗?

1 个答案:

答案 0 :(得分:0)

允许结果为浮点数:

mean = np.mean(train_x)
train_x = train_x - mean

或者将平均值计算为np.uint8(失去精度):

mean = np.mean(train_x, dtype=train_x.dtype)
train_x -= mean