Magic of White Color — Python

Sudhakar Chelliah
CodeX
Published in
4 min readJun 5, 2024

All the colors of this universe have been locked inside WHITE Color.

Let's see how it works. Any color will be identified by the combination of RGB(Red,Green,Blue) matrix.

0 is the lowest and 255 is the highest range.

Black will have all the RGB value as 0 so it will not have any color within it but WHITE is filled with the Full values (255) of RGB.Hence we can remove certain color and get a new color from white. It is like White is a full bag of all the colors.

RGB - Color Mapping:

The RGB mapping presented below will have basic color combination.

If we remove Red from White color, then Cyan will be displayed as the result of full value of green and blue combination.

If we remove blue color from white color, then the result will be yellow color (Combination of Red and Green).

We can test this with Python code.

Basic Color Mapping of RGB- Image created by Self.

Original White color Rose :

In the below code, we are displaying original white rose image without changing anything.

First line, we are importing numpy library (import numpy as np)

Second line, we are importing image class from PIL module (from PIL import image)

Third line, we are importing matplotlib library and calling the pyplot to plot the image (import matplotlib.pyplot as plt).

Fourth line, we are assigning the rose.jpg image to the variable(img).

Fifth line, we are assigning the image to the numpy array to calculate the pixel.

Sixth line, we are opening the image in the pyplot to open with a plot.

import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('rose.jpg')
img_arr= np.array(img)
plt.imshow(img_arr)

Displaying Cyan color rose from White Rose:

In the below code, we are removing the red color from the White rose and the result is displaying the Cyan color.

img_arr[0: , 0: , 0] = 0 , This line will retrieve the complete x axis(0:) and y axis(0:) and remove the red color(0).

import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('rose.jpg')
img_arr= np.array(img)
img_arr[0:, 0:,0] = 0
plt.imshow(img_arr)

Displaying Magenta color rose from White Rose:

In the below code, we are removing the green color from the White rose and the result is displaying the magenta color.

img_arr[0: , 0: , 1] = 0, This line will retrieve the complete x axis (0:) and y axis (0:) and remove the green color (1).

import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('rose.jpg')
img_arr= np.array(img)
img_arr[0:, 0:,1] = 0
plt.imshow(img_arr)

Displaying Yellow color rose from White Rose:

In the below code, we are removing the red color from the White rose and the result is displaying the yellow color.

img_arr[0: , 0: , 2] = 0 , This line will retrieve the complete x axis(0:) and y axis(0:) and remove the Red color(2).

import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('rose.jpg')
img_arr= np.array(img)
img_arr[0:, 0:,2] = 0
plt.imshow(img_arr)

Displaying Red color rose from White Rose:

In the below code, we are removing the Green and Blue color from the White rose and the result is displaying the Red color.

img_arr[0: , 0: , 1] = 0 # Removing green color

img_arr[0: , 0: , 2] = 0 # Removing blue color

import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('rose.jpg')
img_arr= np.array(img)
img_arr[0:, 0:,1] = 0
img_arr[0:, 0:,2] = 0
plt.imshow(img_arr)

Displaying Blue color rose from White Rose:

In the below code, we are removing the Red and Green color from the White rose and the result is displaying the Blue color.

img_arr[0: , 0: , 0] = 0 # Removing redcolor

img_arr[0: , 0: , 1] = 0 # Removing green color

import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('rose.jpg')
img_arr= np.array(img)
img_arr[0:, 0:,0] = 0
img_arr[0:, 0:,1] = 0
plt.imshow(img_arr)

Displaying Green color rose from White Rose:

In the below code, we are removing the red and blue color from the White rose and the result is displaying the green color.

img_arr[0: , 0: , 0] = 0 # Removing red color

img_arr[0: , 0: , 2] = 0 # Removing blue color

import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('rose.jpg')
img_arr= np.array(img)
img_arr[0:, 0:,0] = 0
img_arr[0:, 0:,2] = 0
plt.imshow(img_arr)

Thanks for reading the blog. Please share your thoughts :)

--

--