Consider an image like array as below :
>>> red
array([[[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255]],
[[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255]]])
Its all elements are [0,0,255]. Its shape is 2x5x3. Just think there are other values also in it. (I can't create all those).
Now you find where [0,0,255] are present and change them to [0,255,255]. You can do it as follows :
>>> red[np.where((red == [0,0,255]).all(axis = 2))] = [0,255,255]
Now check the red.
>>> red
array([[[ 0, 255, 255],
[ 0, 255, 255],
[ 0, 255, 255],
[ 0, 255, 255],
[ 0, 255, 255]],
[[ 0, 255, 255],
[ 0, 255, 255],
[ 0, 255, 255],
[ 0, 255, 255],
[ 0, 255, 255]]])
Hope this is what you want.
Test Results:
Check out the code from this link : https://stackoverflow.com/a/11072667/1134940
I want to change all red pixels to yellow as asked in question.
So i added this below piece of code at the end :
im2[np.where((im2 == [0,0,255]).all(axis = 2))] = [0,255,255]
Below is the result I got :
What if i want to change green ground to yellow ground :
im2[np.where((im2 == [0,255,0]).all(axis = 2))] = [0,255,255]
Result :