Python Pillow Image Invert
本文主要是利用Python的第三方库Pillow,实现单通道灰度图像的颜色翻转功能。
# -*- encoding:utf-8 -*- import os import sys from PIL import Image from PIL import ImageOps def img_gray_invert(img_path): """ invert input image. """ if not os.path.isfile(img_path): print "Error for input file path." return image = Image.open(img_path) image = image.convert("L") inverted_image = ImageOps.invert(image) return inverted_image if __name__ == '__main__': argv = sys.argv if len(argv) != 3: print """Example: python gray_invert.py test/htc.png test/htc_inv.png """ else: img_file_path = argv[1] invert_image = img_gray_invert(img_file_path) img_file_out = argv[2] invert_image.save(img_file_out)
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16