Python Pillow 简明教程

Python Pillow - Enhancing Color

Enhancing color 是一种图像处理技术,侧重于通过微调其颜色的平衡和饱和度来提高数字图像的视觉吸引力和质量。图像颜色增强的目标是在突出有用信息的同时获得更精细的图像细节。当图像的照明条件较差,导致出现较暗且对比度较低的画面,需要进行细化时,此技术特别有用。此技术广泛用于平面设计、摄影和数字艺术等各个领域,以增强图像的视觉效果。

Python Pillow 库 (PIL) 在其 ImageEnhance 模块中提供了 Color() 类,它使您可以对图像应用颜色增强。

Enhancing Color of an Image

要使用 Python Pillow 库增强图像颜色,您可以使用 ImageEnhance.Color() 类,它允许您调整图像的色彩平衡,就像通过彩色电视机上的控制一样。

以下是 ImageEnhance.Color() 类的语法:

class PIL.ImageEnhance.Color(image)

将表示为浮点数的增强因子作为参数传递给常见的单接口方法 enhance(factor)。此因子在调整色彩平衡中起着重要作用。因子为 0.0 将生成一幅黑白图像。因子为 1.0 保留原图像。

以下步骤可实现图像的色彩增强:

  1. 使用 ImageEnhance.Color() 类创建色彩增强器对象。

  2. 然后使用 enhance() 方法将增强因子应用到增强器对象。

Example

这里有一个示例,它使用因子 3.0 增强图像颜色。

from PIL import Image, ImageEnhance

# Open an image file
image = Image.open('Images/Tajmahal_2.jpg')

# Create a Color object
color_enhancer = ImageEnhance.Color(image)

# Display the original image
image.show()

# Enhance the color with a factor of 3.0
colorful_image = color_enhancer.enhance(3.0)

# Display the enhanced color image
colorful_image.show()

输入图像 −

tajmahal

输出颜色增强过的图像:

highly color enhanced

Example

这里有一个示例,它使用更低的增强因子 (0.0) 增强图像颜色。

from PIL import Image, ImageEnhance

# Open an image file
image = Image.open('Images/Tajmahal_2.jpg')

# Create a Color object
color_enhancer = ImageEnhance.Color(image)

# Display the original image
image.show()

# Enhance the color with a factor of 0.0
colorful_image = color_enhancer.enhance(0.0)

# Display the enhanced color image
colorful_image.show()

输入图像 −

tajmahal

输出增强因子为 0.0 的颜色增强图像:

imageenhance zero