I tried this script for replacing the single color of the image. I need to recolor similar colors in image. For example, I have a blue, slate blue. I want to recolor both of these colors with red. But as I mentioned below, I cannot do that. It can be in PIL or OpenCV library in python.
Source of this code: Change specific RGB color pixels to another color, in image file
import numpy as np
from PIL import Image
image = Image.open('wall.jpg')
data = np.array(im)
r1, g1, b1 = 81, 90, 103 # Original value
r2, g2, b2 = 255, 0, 0 # Value that we want to replace it with
red, green, blue = data[:,:,0], data[:,:,1], data[:,:,2]
mask = (red == r1) & (green == g1) & (blue == b1)
data[:,:,:3][mask] = [r2, g2, b2]
im = Image.fromarray(data)
im.show()
