OpenCV中LUT函数的说明?

2024-09-30 22:14:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我面临以下HSV增强:

def augment_hsv(img, hgain=0.3, sgain=0.5, vgain=0.4):
   # uniform distribution (low, high, size)
   r = np.random.uniform(-1, 1, 3) * [hgain, sgain, vgain] + 1  # random gains
   hue, sat, val = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))
   dtype = img.dtype  # uint8

   x = np.arange(0, 256, dtype=np.int16)
   lut_hue = ((x * r[0]) % 180).astype(dtype)
   lut_sat = np.clip(x * r[1], 0, 255).astype(dtype)
   lut_val = np.clip(x * r[2], 0, 255).astype(dtype)

   img_hsv = cv2.merge((cv2.LUT(hue, lut_hue), cv2.LUT(sat, lut_sat), cv2.LUT(val, lut_val))).astype(dtype)
   cv2.cvtColor(img_hsv, cv2.COLOR_HSV2BGR, dst=img)  # no return needed

我不明白cv2.LUT是做什么的,我在谷歌上也找不到一个好的解释。有人能给我举个例子解释一下吗?提前谢谢


Tags: imgnpuniformvalcv2hsvhuesat