def random_saturation(img, label, lower=0.5, upper=1.5):
"""
Multiplies saturation with a constant and clips the value between [0,1.0]
Args:
img: input image in float32
label: returns label unchanged
lower: lower val for sampling
upper: upper val for sampling
"""
alpha = lower + (upper - lower) * rand.rand()
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# saturation should always be within [0,1.0]
hsv[:, :, 1] = np.clip(alpha * hsv[:, :, 1], 0.0, 1.0)
return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR), label
评论列表
文章目录