TensorFlow

API

 tf.image / resize_with_crop_or_pad


Converts one or more images from RGB to Grayscale.

Used in the notebooks

Used in the tutorials

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.

original = tf.constant([[[1.0, 2.0, 3.0]]])
converted = tf.image.rgb_to_grayscale(original)
print(converted.numpy())
[[[1.81...]]]

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

The converted grayscale image(s).

此页内容是否对您有帮助