9951 explained code solutions for 126 technologies


python-pillowHow to convert an image to black and white


from PIL import Image, ImageFilter

im = Image.open('/var/www/examples/heroine.png')
im = im.convert('1')

im.show()ctrl + c
PIL

import Pillow package modules

Image.open

open given image with Pillow

.convert('1')

convert image to black and white colors

.show()

displays resulting image