opencv的LUT函数使用
LUT即look-up table, 进行查表转换,LUT函数对输入图像,根据提供的转换表,将像素值进行转换,其参数含义如下:
dst = cv2.LUT(src, lut, dst=None)
src:输入数据array,类型为8位整型(np.uin8)
lut:查找表,如果输入src是多通道的,例如是BGR三通到的图像,而查表是单通道的,则此时B、G、R三个通道使用的是同一个查找表
dst=None:输出数组,大小和通道数与src相同,而深度depth与lut相同
对于src中的每个元素(像素点),通过LUT表查找到对应值,并填充输出数组中对应位置元素,LUT函数对src中的每个元素的处理如下:

图像增强
def augment_hsv(img, hgain=0.5, sgain=0.5, vgain=0.5): 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
参考:https://blog.csdn.net/weixin_41010198/article/details/111634487

浙公网安备 33010602011771号