Color Swapping techniques in Image Processing

Let’s get into the implementation part. Let’s consider several scenarios of color swapping, we will start with a simple to color swap image (by simple I mean the color distribution doesn’t vary much) and gradually go on to the examples where the image has a varied color distribution where it would be quite tricky to swap a particular color of choice.

Fig: an original image of a pen. Image by Author.
Fig: Increasing the value of “B” component by a fixed amount results in a change in both color and intensity values. Image by Author.
  • Every pixel in an RGB image is a specific combination of these components and we cannot interpret by how much amount a component needs to be changed to get the desired color.
  • Any change in any of the R, G, B components, would bring a change in both the color and the intensity value of a pixel.
Fig: Images obtained by changing the hue component of the image. No disturbance in brightness and saturation values. Images look realistic. Image by Author.
Fig: Image obtained by lowering the brightness component. Image by Author.
Fig: Hue channel for the original pen image. Image by Author.
Fig: histogram of color distribution. Image by Author.
Fig: a color mask for the pen (foreground). Image by Author.
Fig: we changed the foreground color without changing the background. And all illuminations remain intact. Image by Author.