Python| ImageOps.autocontrast() 方法
PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 ImageOps 模块包含许多“现成的”图像处理操作。这个模块有点实验性,大多数运算符只处理 L 和 RGB 图像。
ImageOps.autocontrast()
方法最大化(标准化)图像对比度。此函数计算输入图像的直方图,从直方图中移除最亮和最暗像素的截止百分比,并重新映射图像,使最暗像素变为黑色 (0),最亮变为白色 (255)。Syntax: PIL.ImageOps.autocontrast(image, cutoff=0, ignore=None)
Parameters:
image: The image to process.
cutoff: How many percent to cut off from the histogram.
ignore: The background pixel value (use None for no background).
Returns: An image.
使用的图像:
# Importing Image and ImageOps module from PIL package
from PIL import Image, ImageOps
# creating a image1 object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPg")
# applying autocontrast method
im2 = ImageOps.autocontrast(im1, cutoff = 2, ignore = 2)
im2.show()
输出:
# Importing Image and ImageOps module from PIL package
from PIL import Image, ImageOps
# creating a image1 object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPg")
# applying autocontrast method
im2 = ImageOps.autocontrast(im1, cutoff = 5, ignore = 5)
im2.show()
输出: