(image, saturation_factor, name=None)
Adjust saturation of an RGB image.

  This is a convenience method that converts an RGB image to float
  representation, converts it to HSV, add an offset to the saturation channel,
  converts back to RGB and then back to the original data type. If several
  adjustments are chained it is advisable to minimize the number of redundant
  conversions.

  `image` is an RGB image.  The image saturation is adjusted by converting the
  image to HSV and multiplying the saturation (S) channel by
  `saturation_factor` and clipping. The image is then converted back to RGB.

  Args:
    image: RGB image or images. Size of the last dimension must be 3.
    saturation_factor: float. Factor to multiply the saturation by.
    name: A name for this operation (optional).

  Returns:
    Adjusted image(s), same shape and DType as `image`.
Adjust saturation of an RGB image.
Adjust saturation of an RGB image .
def adjust_saturation(image, saturation_factor, name=None):
  """Adjust saturation of an RGB image.

  This is a convenience method that converts an RGB image to float
  representation, converts it to HSV, add an offset to the saturation channel,
  converts back to RGB and then back to the original data type. If several
  adjustments are chained it is advisable to minimize the number of redundant
  conversions.

  `image` is an RGB image.  The image saturation is adjusted by converting the
  image to HSV and multiplying the saturation (S) channel by
  `saturation_factor` and clipping. The image is then converted back to RGB.

  Args:
    image: RGB image or images. Size of the last dimension must be 3.
    saturation_factor: float. Factor to multiply the saturation by.
    name: A name for this operation (optional).

  Returns:
    Adjusted image(s), same shape and DType as `image`.
  """
  with ops.name_scope(name, 'adjust_saturation', [image]) as name:
    image = ops.convert_to_tensor(image, name='image')
    # Remember original dtype to so we can convert back if needed
    orig_dtype = image.dtype
    flt_image = convert_image_dtype(image, dtypes.float32)

    # TODO(zhengxq): we will switch to the fused version after we add a GPU
    # kernel for that.
    fused = os.environ.get('TF_ADJUST_SATURATION_FUSED', '')
    fused = fused.lower() in ('true', 't', '1')

    if fused:
      return convert_image_dtype(
          gen_image_ops.adjust_saturation(flt_image, saturation_factor),
          orig_dtype)

    hsv = gen_image_ops.rgb_to_hsv(flt_image)

    hue = array_ops.slice(hsv, [0, 0, 0], [-1, -1, 1])
    saturation = array_ops.slice(hsv, [0, 0, 1], [-1, -1, 1])
    value = array_ops.slice(hsv, [0, 0, 2], [-1, -1, 1])

    saturation *= saturation_factor
    saturation = clip_ops.clip_by_value(saturation, 0.0, 1.0)

    hsv_altered = array_ops.concat([hue, saturation, value], 2)
    rgb_altered = gen_image_ops.hsv_to_rgb(hsv_altered)

    return convert_image_dtype(rgb_altered, orig_dtype)
def adjust_saturation ( image , saturation_factor , name = None ) : with ops . name_scope ( name , 'adjust_saturation' , [ image ] ) as name : image = ops . convert_to_tensor ( image , name = 'image' ) # Remember original dtype to so we can convert back if needed orig_dtype = image . dtype flt_image = convert_image_dtype ( image , dtypes . float32 ) # TODO(zhengxq): we will switch to the fused version after we add a GPU # kernel for that. fused = os . environ . get ( 'TF_ADJUST_SATURATION_FUSED' , '' ) fused = fused . lower ( ) in ( 'true' , 't' , '1' ) if fused : return convert_image_dtype ( gen_image_ops . adjust_saturation ( flt_image , saturation_factor ) , orig_dtype ) hsv = gen_image_ops . rgb_to_hsv ( flt_image ) hue = array_ops . slice ( hsv , [ 0 , 0 , 0 ] , [ - 1 , - 1 , 1 ] ) saturation = array_ops . slice ( hsv , [ 0 , 0 , 1 ] , [ - 1 , - 1 , 1 ] ) value = array_ops . slice ( hsv , [ 0 , 0 , 2 ] , [ - 1 , - 1 , 1 ] ) saturation *= saturation_factor saturation = clip_ops . clip_by_value ( saturation , 0.0 , 1.0 ) hsv_altered = array_ops . concat ( [ hue , saturation , value ] , 2 ) rgb_altered = gen_image_ops . hsv_to_rgb ( hsv_altered ) return convert_image_dtype ( rgb_altered , orig_dtype )