- 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 - 增强对比度
增强对比度是指提高图像可见性和质量的过程。这是一种图像处理技术,通过调整强度值或颜色的分布,来增加图像中各种元素(如物体、形状、边缘和纹理)之间的差异。此技术广泛应用于医学影像、计算机视觉、遥感和摄影等领域,以提高图像质量并获得更详细的视觉信息。
Python Pillow (PIL) 库在其 ImageEnhance 模块中提供了Contrast() 类,用于对图像应用对比度增强。
增强图像对比度
要调整图像的对比度,您可以将ImageEnhance.Contrast() 类与增强因子一起应用于图像对象。它可以控制图像的对比度,就像调整电视机的对比度一样。
以下是 ImageEnhance.Contrast() 类的语法:
class PIL.ImageEnhance.Contrast(image)
以下是实现图像对比度增强的步骤:
使用ImageEnhance.Contrast() 类创建一个对比度对象。
然后使用contrast_object.enhance() 方法应用增强因子。
增强因子是一个传递给通用单接口方法 enhance(factor) 的浮点值,它在调整图像对比度方面起着重要作用。当使用 0.0 的因子时,它将产生一个纯灰色的图像。1.0 的因子将给出原始图像,而当使用更大的值时,图像的对比度会增加,使其在视觉上更清晰。
示例
以下示例演示了如何使用 PIL.ImageEnhance 模块实现高对比度图像。
from PIL import Image, ImageEnhance
# Open the input image
image = Image.open('Images/flowers.jpg')
# Create an ImageEnhance object for adjusting contrast
enhancer = ImageEnhance.Contrast(image)
# Display the original image
image.show()
# Enhance the contrast by a factor of 2 and display the result
enhancer.enhance(2).show()
输入图像
输出图像
输出输入图像的高对比度版本:
示例
要降低图像的对比度,可以使用小于 1 的对比度增强因子。以下是一个示例,说明了如何使用 PIL.ImageEnhance.Contrast 类创建输入图像的低对比度版本。
from PIL import Image, ImageEnhance
# Open the input image
image = Image.open('Images/flowers.jpg')
# Create an ImageEnhance object for adjusting contrast
enhancer = ImageEnhance.Contrast(image)
# Display the original image
image.show()
# Reduce the contrast by a factor of 0.5 and display the result
enhancer.enhance(0.5).show()
输入图像
输出图像
输出输入图像的低对比度版本:
广告