import cv2
import numpy as np
import os
def gamma_trans(img, gamma):
'''
首先归一化到0-1范围,然后gamma作为指数值求出新的像素值再还原
'''
gamma_table = [np.power(x / 255.0, gamma) * 255.0 for x in range(256)]
gamma_table = np.round(np.array(gamma_table)).astype(np.uint8)
return cv2.LUT(img, gamma_table) # 作为一个查表的映射
orig_path=r'E:\\89_result\\carData\\background\\background'
save_path=r'E:\\89_result\\carData\\background\\background2'
os.makedirs(save_path,exist_ok=True)
for root,dir,files in os.walk(orig_path):
for file in files:
if os.path.splitext(file)[-1] in [".jpg", ".png", ".JPEG", ".PNG",".jpeg"]:
img = cv2.imread(os.path.join(root,file))
img3 = gamma_trans(img,0.5)
cv2.imwrite(os.path.join(save_path,file),img3)
print(os.path.join(save_path,file))
图像亮度对比度增强
于 2023-07-11 09:54:45 首次发布