我正在使用OpenCV和Python.我有一个图像,我想要做的是将BGR值[0,0,255]的所有像素设置为[0,255,255].
我问了一个关于如何对图像进行分色的前一个问题,并从我学到的关于使用索引数组进行索引的答案,例如:image [image> 128] = 255
我理解这是如何工作的,因为image> 128将返回一个满足条件的多维索引数组,然后我将这个数组应用于图像并将它们设置为255.但是,我对如何混淆将此扩展为为数组执行值.
我尝试过以下操作:
red = np.array([0, 0, 255])
redIndex = np.where(np.equal(image, red))
image[redIndex] = np.array([0, 255, 255])
Run Code Online (Sandbox Code Playgroud)
但它不起作用,错误:
ValueError: array is not broadcastable to correct shape
Run Code Online (Sandbox Code Playgroud)
有没有一种有效的方法来处理这个问题?