#!python # -*- mode: python; Encoding: utf-8; coding: utf-8 -*- # Last updated: <2022/06/19 21:49:33 +0900> """ Pillow .split() .merge() sample Windows10 x64 21H2 + Python 3.9.13 64bit + Pillow 9.1.1 """ from PIL import Image def main(): im = Image.open("mandrill.png") width, height = im.size print("%d x %d" % (width, height)) rc, gc, bc = im.split() rc1 = rc.convert("1").convert("L") gc1 = gc.convert("1").convert("L") bc1 = bc.convert("1").convert("L") oim = Image.merge("RGB", (rc1, gc1, bc1)) oim.show() oim.save("output_01split.png") if __name__ == '__main__': main()