Professional Documents
Culture Documents
Whatislife
Whatislife
import sys
import numpy as np
filePath = ''
if len(sys.argv) is 1:
filePath = input('Image file path: ')
elif len(sys.argv) is 2:
filePath = sys.argv[1]
image = Image.open(filePath)
pixels = image.load()
r = np.zeros((image.size[1], image.size[0], 3), dtype=np.uint8)
g = np.zeros((image.size[1], image.size[0], 3), dtype=np.uint8)
b = np.zeros((image.size[1], image.size[0], 3), dtype=np.uint8)
for itX in range(image.size[0]):
for itY in range(image.size[1]):
r[itY, itX] = pixels[itX, itY][0], pixels[itX, itY][0], pixels[itX,
itY][0]
g[itY, itX] = pixels[itX, itY][1], pixels[itX, itY][1], pixels[itX,
itY][1]
b[itY, itX] = pixels[itX, itY][2], pixels[itX, itY][2], pixels[itX,
itY][2]
rImage = Image.fromarray(r, 'RGB')
gImage = Image.fromarray(g, 'RGB')
bImage = Image.fromarray(b, 'RGB')
rImage.save("r.png")
gImage.save("g.png")
bImage.save("b.png")