8. Image getchannel
8.1. Getchannel
Use the
Image.getchannel(channel)
returns an image, in “L” mode (greyscale), containing a single channel of the source image.channel - Could be index (0 for “R” channel of “RGB”) or channel name (“A” for alpha channel of “RGBA”).
from PIL import Image
with Image.open("test_images/alph_blocks.png") as im:
im1 = im.getchannel("R")
# im1.show()
im1.save("Image/Image_channel_R.png")
im1 = im.getchannel("G")
# im1.show()
im1.save("Image/Image_channel_G.png")
im1 = im.getchannel("B")
# im1.show()
im1.save("Image/Image_channel_B.png")