def add_hsv_noise(rgb, hue_offset, saturation_offset, value_offset, proba=0.5):
mask = np.all(rgb != 0, axis=2)
hsv = rgb2hsv(rgb)
if random.uniform(0, 1) > proba:
hsv[:, :, 0] = (hsv[:, :, 0] + random.uniform(-hue_offset, hue_offset)) % 1
if random.uniform(0, 1) > proba-0.1:
hsv[:, :, 1] = (hsv[:, :, 1] + random.uniform(-saturation_offset, saturation_offset)) % 1
if random.uniform(0, 1) > proba-0.1:
hsv[:, :, 2] = (hsv[:, :, 2] + random.uniform(-value_offset, value_offset)) % 1
rgb = hsv2rgb(hsv) * 255
return rgb.astype(np.uint8) * mask[:, :, np.newaxis]
评论列表
文章目录