I have an image as a np.array which has shape (320, 240, 4). I want to replace all the individual pixels that have array value (1, 0, 0, 1) which is red to green which has array value (0, 1, 0, 1). I've tried using np.all()
but it's not working though I don't get any errors. Below is my code:
mario = mpimg.imread("mario_big.png")
print(mario.shape) # (320, 240, 4)
mario[np.all(mario == (1, 0, 0, 1), axis=-1)] = (0, 1, 0, 1)
luigi = mario
plt.imshow(luigi)
plt.show()
mario looks like this:
[[[0. 0. 0. 0. ]
[0. 0. 0. 0. ]
[0. 0. 0. 0. ]
...
[0. 0. 0. 0. ]
[0. 0. 0. 0. ]
[0. 0. 0. 0. ]]
[[0. 0. 0. 0. ]
[0. 0. 0. 0. ]
[0. 0. 0. 0. ]
...
[0. 0. 0. 0. ]
[0. 0. 0. 0. ]
[0. 0. 0. 0. ]]
[[0. 0. 0. 0. ]
[0. 0. 0. 0. ]
[0. 0. 0. 0. ]
...
[0. 0. 0. 0. ]
[0. 0. 0. 0. ]
[0. 0. 0. 0. ]]
...
Please advise.