如何将图片中的白色变为红色?

-3 python opencv

我想使用opencv将白色更改为红色,保留黑色部分的颜色,该怎么做? 在此处输入图片说明

小智 6

GPPK 的答案是错误的,原因有两个:

  1. 第 1 行正在创建一个新图像,但在问题中被问及如何更改现有图像的颜色。
  2. 第 2 行正在改变黑色,而不是白色。
image = cv2.imread("Your image path here")
image[np.where((image==[255, 255, 255]).all(axis=2))] = [0, 0, 255]
Run Code Online (Sandbox Code Playgroud)


GPP*_*PPK 5

你可以 numpy 来做到这一点。

image = np.zeros((400,400,3), dtype="uint8")
image[np.where((image==[0,0,0]).all(axis=2))] = [0,0,255]
Run Code Online (Sandbox Code Playgroud)

这会将图像中所有值为 [0,0,0] 的像素更改为 [0,0,255](红色)