(images, name=None)
Converts one or more images from RGB to Grayscale.

  Outputs a tensor of the same `DType` and rank as `images`.  The size of the
  last dimension of the output is 1, containing the Grayscale value of the
  pixels.

  Args:
    images: The RGB tensor to convert. Last dimension must have size 3 and
      should contain RGB values.
    name: A name for the operation (optional).

  Returns:
    The converted grayscale image(s).
Converts one or more images from RGB to Grayscale.
Converts one or more images from RGB to Grayscale .
def rgb_to_grayscale(images, name=None):
  """Converts one or more images from RGB to Grayscale.

  Outputs a tensor of the same `DType` and rank as `images`.  The size of the
  last dimension of the output is 1, containing the Grayscale value of the
  pixels.

  Args:
    images: The RGB tensor to convert. Last dimension must have size 3 and
      should contain RGB values.
    name: A name for the operation (optional).

  Returns:
    The converted grayscale image(s).
  """
  with ops.name_scope(name, 'rgb_to_grayscale', [images]) as name:
    images = ops.convert_to_tensor(images, name='images')
    # Remember original dtype to so we can convert back if needed
    orig_dtype = images.dtype
    flt_image = convert_image_dtype(images, dtypes.float32)

    # Reference for converting between RGB and grayscale.
    # https://en.wikipedia.org/wiki/Luma_%28video%29
    rgb_weights = [0.2989, 0.5870, 0.1140]
    rank_1 = array_ops.expand_dims(array_ops.rank(images) - 1, 0)
    gray_float = math_ops.reduce_sum(flt_image * rgb_weights,
                                     rank_1,
                                     keep_dims=True)
    gray_float.set_shape(images.get_shape()[:-1].concatenate([1]))
    return convert_image_dtype(gray_float, orig_dtype, name=name)
def rgb_to_grayscale ( images , name = None ) : with ops . name_scope ( name , 'rgb_to_grayscale' , [ images ] ) as name : images = ops . convert_to_tensor ( images , name = 'images' ) # Remember original dtype to so we can convert back if needed orig_dtype = images . dtype flt_image = convert_image_dtype ( images , dtypes . float32 ) # Reference for converting between RGB and grayscale. # https://en.wikipedia.org/wiki/Luma_%28video%29 rgb_weights = [ 0.2989 , 0.5870 , 0.1140 ] rank_1 = array_ops . expand_dims ( array_ops . rank ( images ) - 1 , 0 ) gray_float = math_ops . reduce_sum ( flt_image * rgb_weights , rank_1 , keep_dims = True ) gray_float . set_shape ( images . get_shape ( ) [ : - 1 ] . concatenate ( [ 1 ] ) ) return convert_image_dtype ( gray_float , orig_dtype , name = name )