How to split image to RGB colors and why doesn't split() function work?
from PIL import Image
pil_image = Image.fromarray(some_image)
red, green, blue = pil_image.split()
red.show()
Why does red.show() shows image in greyscale instead of red scale?
PS. The same situation using green.show() and blue.show().
解决方案
I've created a script that takes an RGB image, and creates the pixel data for each band by suppressing the bands we don't want.
RGB to R__ -> red.png
RGB to _G_ -> green.png
RGB to __B -> blue.png
from PIL import Image
img = Image.open('ra.jpg')
data = img.getdata()
# Suppress specific bands (e.g. (255, 120, 65) -> (0, 120, 0) for g)
r = [(d[0], 0, 0) for d in data]
g = [(0, d[1], 0) for d in data]
b = [(0, 0, d[2]) for d in data]
img.putdata(r)
img.save('r.png')
img.putdata(g)
img.save('g.png')
img.putdata(b)
img.save('b.png')