- Python Pillow 教程
- Python Pillow - 首页
- Python Pillow - 概述
- Python Pillow - 环境设置
- 基本图像操作
- Python Pillow - 图像处理
- Python Pillow - 调整图像大小
- Python Pillow - 翻转和旋转图像
- Python Pillow - 裁剪图像
- Python Pillow - 为图像添加边框
- Python Pillow - 识别图像文件
- Python Pillow - 合并图像
- Python Pillow - 剪切和粘贴图像
- Python Pillow - 滚动图像
- Python Pillow - 在图像上写入文本
- Python Pillow - ImageDraw 模块
- Python Pillow - 连接两张图像
- Python Pillow - 创建缩略图
- Python Pillow - 创建水印
- Python Pillow - 图像序列
- Python Pillow 颜色转换
- Python Pillow - 图像颜色
- Python Pillow - 创建彩色图像
- Python Pillow - 将颜色字符串转换为 RGB 颜色值
- Python Pillow - 将颜色字符串转换为灰度值
- Python Pillow - 通过更改像素值来更改颜色
- 图像处理
- Python Pillow - 降噪
- Python Pillow - 更改图像模式
- Python Pillow - 图像合成
- Python Pillow - 使用 Alpha 通道
- Python Pillow - 应用透视变换
- 图像滤镜
- Python Pillow - 为图像添加滤镜
- Python Pillow - 卷积滤镜
- Python Pillow - 模糊图像
- Python Pillow - 边缘检测
- Python Pillow - 浮雕图像
- Python Pillow - 增强边缘
- Python Pillow - 锐化蒙版滤镜
- 图像增强和校正
- Python Pillow - 增强对比度
- Python Pillow - 增强锐度
- Python Pillow - 增强色彩
- Python Pillow - 校正色彩平衡
- Python Pillow - 去噪
- 图像分析
- Python Pillow - 提取图像元数据
- Python Pillow - 识别颜色
- 高级主题
- Python Pillow - 创建动画 GIF
- Python Pillow - 批量处理图像
- Python Pillow - 转换图像文件格式
- Python Pillow - 为图像添加填充
- Python Pillow - 颜色反转
- Python Pillow - 使用 NumPy 进行机器学习
- Python Pillow 与 Tkinter BitmapImage 和 PhotoImage 对象
- Image 模块
- Python Pillow - 图像混合
- Python Pillow 有用资源
- Python Pillow - 快速指南
- Python Pillow - 函数参考
- Python Pillow - 有用资源
- Python Pillow - 讨论
Python Pillow - ImageChops.invert() 函数
在 Python 图像处理库 Pillow (PIL) 中,位于 ImageOps 模块中的 invert 函数提供了一种方便的方法来执行图像中像素值的负正反转。
此 PIL.ImageChops.invert 函数用于反转图像或通道的像素值。它通过从最大可能的像素值中减去每个像素值来计算反转值。该操作实现如下:
$$\mathrm{out\:=\:MAX\:−\:image}$$
语法
以下是函数的语法:
PIL.ImageChops.invert(image)
参数
以下是此函数参数的详细信息:
image - 将反转其像素值的输入图像。
返回值
此函数的返回类型为 Image。
示例
示例 1
这是一个使用 ImageChops.invert() 函数对 JPEG 图像文件执行像素值负正反转的示例。
from PIL import Image, ImageChops
# Open a PNG image file
original_image = Image.open('Images/Car_2.jpg')
# Invert the pixel values of the image
inverted_image = ImageChops.invert(original_image)
# Display the input and resulting images
original_image.show()
inverted_image.show()
输出
输入图像
输出图像
示例 2
此示例演示了在将 ImageChops.invert() 应用于 BMP 类型输入图像之前和之后像素值。
from PIL import Image, ImageChops
# Open an image file
original_image = Image.open('Images/lena.bmp')
# Display the pixel values before inversion
print("Pixel values in the original image at (0, 0) before inversion:", original_image.getpixel((0, 0)))
# Apply the ImageChops.invert() function to invert pixel values
inverted_image = ImageChops.invert(original_image)
# Display the pixel values after inversion
print("Pixel values in the inverted image at (0, 0) after inversion:", inverted_image.getpixel((0, 0)))
# Display the input and resulting images
original_image.show()
inverted_image.show()
输出
输入图像
输出图像
示例 3
以下示例演示如何使用 ImageChops.invert() 函数对 RGB 图像的单个通道应用反转操作。
from PIL import Image, ImageChops
# Open an image file
original_image = Image.open('Images/flowers.jpg')
# Split the channels of the image
red, green, blue = original_image.split()
# Invert the green channel
inverted_green_channel = ImageChops.invert(green)
# Merge the channels back into an RGB image
image_with_inverted_green = Image.merge('RGB', (red, inverted_green_channel, blue))
# Display the input and resulting images
original_image.show()
image_with_inverted_green.show()
输出
输入图像
输出图像
python_pillow_function_reference.htm
广告