如何使用PIL(Python-Imaging)反转图像的颜色? [英] How to invert colors of image with PIL (Python-Imaging)?
本文介绍了如何使用PIL(Python-Imaging)反转图像的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将在黑色背景字母上绘制为白色的一系列图像转换为白色和黑色反转(为负)的图像.如何使用PIL实现此目标?
I need to convert series of images drawn as white on black background letters to images where white and black are inverted (as negative). How can I achieve this using PIL?
推荐答案
尝试从文档中进行以下操作: http ://effbot.org/imagingbook/imageops.htm
Try the following from the docs: http://effbot.org/imagingbook/imageops.htm
from PIL import Image
import PIL.ImageOps
image = Image.open('your_image.png')
inverted_image = PIL.ImageOps.invert(image)
inverted_image.save('new_name.png')
注意:"ImageOps模块包含许多现成的"图像处理操作.该模块在某种程度上是实验性的,大多数操作员只能处理L和RGB图像."
Note: "The ImageOps module contains a number of 'ready-made' image processing operations. This module is somewhat experimental, and most operators only work on L and RGB images."
这篇关于如何使用PIL(Python-Imaging)反转图像的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文