python
import cv2
import numpy as np
def adjust_gamma(image, gamma=1.0):
invGamma = 1.0 / gamma
table = np.array(
[((i / 255.0) ** invGamma) * 255 for i in np.arange(0, 256)]
).astype("uint8")
return cv2.LUT(image, table)
# 读取图像
original = cv2.imread("test.png", 1)
# gamma矫正
gamma = 1.8 # 矫正系数:越大越亮、越小越暗
adjusted = adjust_gamma(original, gamma=gamma)
cv2.imwrite("result.jpg", adjusted)
矫正前后效果如下: