def adjust_saturation(image, saturation_factor, name=None):
with ops.op_scope([image], name, 'adjust_saturation') as name:
# Remember original dtype to so we can convert back if needed
orig_dtype = image.dtype
flt_image = tf.image.convert_image_dtype(image, tf.float32)
hsv = gen_image_ops.rgb_to_hsv(flt_image)
hue = tf.slice(hsv, [0, 0, 0, 0], [-1, -1, -1, 1])
saturation = tf.slice(hsv, [0, 0, 0, 1], [-1, -1, -1, 1])
value = tf.slice(hsv, [0, 0, 0, 2], [-1, -1, -1, 1])
saturation *= saturation_factor
saturation = clip_ops.clip_by_value(saturation, 0.0, 1.0)
hsv_altered = tf.concat(3, [hue, saturation, value])
rgb_altered = gen_image_ops.hsv_to_rgb(hsv_altered)
return tf.image.convert_image_dtype(rgb_altered, orig_dtype)
评论列表
文章目录