Change a particular color in an Image Python

asked 2020-07-14 05:57:00 -0500

dlrnae gravatar image

Hi there,

I have an image and I would like to change a particular colour on that. Particularly, the image contains a set of colours I have used a means algorithm in order to obtain the whole set of colours contained in the image and selecting just one colour I would completely change it. For instance, in the image I have (as already said) the set of different colors I would like that this RGB source

RGB_source=(5, 114, 121)

change in:

RGB_dest=(166, 109, 82)

How may I manage this color change?

thank you

edit retag flag offensive close merge delete


Attention: in a "normal" image (like a photo) the values of the pixels change a lot: there is noise, difference in probably 2 pixels of the same color will have different RGB values. Of course this is not the case for syntetic images (i.e. drawn using Paint).

To change only a single color (as in question), you just compare the value of each pixel with RGB_source, and if they match, replace the value with RGB_dest.

kbarni gravatar imagekbarni ( 2020-07-15 10:49:38 -0500 )edit

please show how you get the means, since using KMeans() would already give you the resp. cluster indices

berak gravatar imageberak ( 2020-07-16 03:44:04 -0500 )edit