Pycharm_python_opencv批量调节图片亮度至相近亮度值`
import numpy as np
import cv2
import os
# 调整最大值+
MAX_VALUE = 100
def update(input_img_path, output_img_path, brightness,saturation):
"""
用于修改图片的亮度和饱和度
:param input_img_path: 图片路径
:param output_img_path: 输出图片路径
:param lightness: 亮度
:param saturation: 饱和度
"""
# 加载图片
img = cv2.imread(input_img_path, cv2.IMREAD_COLOR)
Imax = np.max(img)
Imin = np.min(img)
MAX = 255
MIN = 0
ime = (img - Imin) / (Imax - Imin) * (MAX - MIN) + MIN
ime = img.astype('uint8')
max_percentile_pixel, min_percentile_pixel = compute(ime, 1, 99)
# 去掉分位值区间之外的值
ime[ime >= max_percentile_pixel] = max_percentile_pixel
ime[ime <= min_percentile_pixel] = min_percentile_pixel
# 将分位值区间拉伸到0到255,这里取了255*0.1与255*0.9是因为可能会出现像素值溢出的情况,所以最好不要设置为0到255。
im