替换2d numpy数组中的向量

时间:2012-10-17 21:35:47

标签: python numpy

我从图片中加载numpy array形状(height, width, 3)。我想用特定颜色[0, 0, 0]替换所有黑色像素[r, g, b]。有numpy方法吗?

1 个答案:

答案 0 :(得分:1)

import numpy as np
orig_color = (0, 0, 0)
replacement_color = (r, g, b)

data[(data == orig_color).all(axis = -1)] = replacement_color