PIL是用于图像处理的第三方库,它支持图像存储、处理和显示等操作。
安装命令
pip install pillow
示例:图像的颜色交换
原图:
from PIL import Image
im=Image.open('Google.jpg')
# print(type(im),im) #<class 'PIL.PngImagePlugin.PngImageFile'> <PIL.PngImagePlugin.PngImageFile image mode=RGB size=1172x514 at 0x1258C8C20>
#提供RGB图像的颜色通道,返回结果是图像的副本
r,g,b=im.split()
print(r) #<PIL.Image.Image image mode=L size=1172x514 at 0x12E9A0D70>
print(g) #<PIL.Image.Image image mode=L size=1172x514 at 0x12E93EFD0>
print(b) #<PIL.Image.Image image mode=L size=1172x514 at 0x12E93F110>
#合并通道
om=Image.merge('RGB',(r,b,g))
om.save('changleColor_Google.jpg')
颜色更新后的图:
想更深入学习,可参考博客Python 图像处理 PIL 第三方库详细使用教程(更新中)-CSDN博客