Color Paradise — Python

Sudhakar Chelliah
CodeX
Published in
3 min readJun 9, 2024

Pixels of Color variation using python.

We are going to take a black and white image and convert into colorful pixels using python.

Displaying the Original Black and White picture :

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

Displaying multiple color by slicing small columns vertically.

We are adding different color to the image by slicing the array vertically . Please find the below details.

# This line will remove RED from WHITE color and the result will display CYAN/AQUA color. Array slicer( Y axis full range, X axis =1250 to 1500,0). So the red color will display between 1250 and 1500 in the plot.
img_arr[0:,1250:1500,0] = 0

# This line will remove GREEN from WHITE color and the result will display MAGNETA color. Array slicer( Y axis full range, X axis =1500 to 1750). So the red color will display between 1500 and 1750 in the plot.
img_arr[0:,1500:1750,1] = 0

# This line will remove BLUE from WHITE color and the result will display YELLOW color. Array slicer( Y axis full range, X axis =1750 to 2000,2). So the red color will display between 1750and 2000 in the plot.
img_arr[0:,1750:2000,2] = 0

# This line will remove GREEN AND BLUE from WHITE color and the result will display RED color.
img_arr[0:,2000:2250,1] = 0
img_arr[0:,2000:2250,2] = 0

# This line will remove RED AND BLUE from WHITE color and the result will display GREEN color.
img_arr[0:,2250:2500,0] = 0
img_arr[0:,2250:2500,2] = 0

# This line will remove RED AND GREEN from WHITE color and the result will display BLUE color.
img_arr[0:,2500:2750,0] = 0
img_arr[0:,2500:2750,1] = 0

# This line will remove all three colors (RED,GREEN,BLUE) from White color and the result will display BLACK color.
img_arr[0:,2750:,0] = 0
img_arr[0:,2750:,1] = 0
img_arr[0:,2750:,2] = 0

import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('Color.jpg')
img_arr= np.array(img)
img_arr[0:,1250:1500,0] = 0
img_arr[0:,1500:1750,1] = 0
img_arr[0:,1750:2000,2] = 0
img_arr[0:,2000:2250,1] = 0
img_arr[0:,2000:2250,2] = 0
img_arr[0:,2250:2500,0] = 0
img_arr[0:,2250:2500,2] = 0
img_arr[0:,2500:2750,0] = 0
img_arr[0:,2500:2750,1] = 0
img_arr[0:,2750:,0] = 0
img_arr[0:,2750:,1] = 0
img_arr[0:,2750:,2] = 0
plt.imshow(img_arr)
Result of Multiple color by slicing the plot .

Displaying multiple color by slicing small columns horizontally hence creating a box of colors.

We are slicing the image horizontally and vertically with different color combo to create different box shaped colorful image.

import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('Color.jpg')
img_arr= np.array(img)
img_arr[0:, 1250:1500,0] = 0
img_arr[0:,1500:1750,1] = 0
img_arr[0:,1750:2000,2] = 0
img_arr[0:,2250:2500,0] = 0
img_arr[0:,2500:2750,1] = 0
img_arr[0:,2750:3000,2] = 0
img_arr[250:500,0:,0] = 0
img_arr[500:750,0:,1] = 0
img_arr[750:1050,0:,2] = 0
img_arr[1050:1300,0:,0] = 0
img_arr[1300:1550,0:,1] = 0
img_arr[1550:1850,0:,2] = 0
img_arr[1850:2100,0:,0] = 0
img_arr[2100:2350,0:,1] = 0
img_arr[2350:2700,0:,2] = 0
plt.imshow(img_arr)

Thanks for allocating your valuable time for reading my blog.

--

--