import numpy as np
import cv2
hist, bins = np.histogram(img, bins=256, range=(0, 256))
# 计算累积分布函数(CDF)
cdf = np.cumsum(hist)
# 归一化CDF: 归一化CDF以确保其范围在0到255之间
cdf_norm = 255 * (cdf - cdf.min()) / (cdf.max() - cdf.min())
cdf_norm = np.uint8(np.round(cdf_norm))
# 使用映射表查表将像素值重新映射
rlt = cdf_norm[img]