tf.image.yuv_to_rgb
Stay organized with collections
Save and categorize content based on your preferences.
Converts one or more images from YUV to RGB.
tf.image.yuv_to_rgb(
images
)
Outputs a tensor of the same shape as the images
tensor, containing the RGB
value of the pixels.
The output is only well defined if the Y value in images are in [0,1],
U and V value are in [-0.5,0.5].
As per the above description, you need to scale your YUV images if their
pixel values are not in the required range. Below given example illustrates
preprocessing of each channel of images before feeding them to yuv_to_rgb
.
yuv_images = tf.random.uniform(shape=[100, 64, 64, 3], maxval=255)
last_dimension_axis = len(yuv_images.shape) - 1
yuv_tensor_images = tf.truediv(
tf.subtract(
yuv_images,
tf.reduce_min(yuv_images)
),
tf.subtract(
tf.reduce_max(yuv_images),
tf.reduce_min(yuv_images)
)
)
y, u, v = tf.split(yuv_tensor_images, 3, axis=last_dimension_axis)
target_uv_min, target_uv_max = -0.5, 0.5
u = u * (target_uv_max - target_uv_min) + target_uv_min
v = v * (target_uv_max - target_uv_min) + target_uv_min
preprocessed_yuv_images = tf.concat([y, u, v], axis=last_dimension_axis)
rgb_tensor_images = tf.image.yuv_to_rgb(preprocessed_yuv_images)
Args |
images
|
2-D or higher rank. Image data to convert. Last dimension must be
size 3.
|
Returns |
images
|
tensor with the same shape as images .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.image.yuv_to_rgb\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/image_ops_impl.py#L4073-L4119) |\n\nConverts one or more images from YUV to RGB.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.image.yuv_to_rgb`](https://www.tensorflow.org/api_docs/python/tf/image/yuv_to_rgb)\n\n\u003cbr /\u003e\n\n tf.image.yuv_to_rgb(\n images\n )\n\nOutputs a tensor of the same shape as the `images` tensor, containing the RGB\nvalue of the pixels.\nThe output is only well defined if the Y value in images are in \\[0,1\\],\nU and V value are in \\[-0.5,0.5\\].\n\nAs per the above description, you need to scale your YUV images if their\npixel values are not in the required range. Below given example illustrates\npreprocessing of each channel of images before feeding them to `yuv_to_rgb`. \n\n yuv_images = tf.random.uniform(shape=[100, 64, 64, 3], maxval=255)\n last_dimension_axis = len(yuv_images.shape) - 1\n yuv_tensor_images = tf.truediv(\n tf.subtract(\n yuv_images,\n tf.reduce_min(yuv_images)\n ),\n tf.subtract(\n tf.reduce_max(yuv_images),\n tf.reduce_min(yuv_images)\n )\n )\n y, u, v = tf.split(yuv_tensor_images, 3, axis=last_dimension_axis)\n target_uv_min, target_uv_max = -0.5, 0.5\n u = u * (target_uv_max - target_uv_min) + target_uv_min\n v = v * (target_uv_max - target_uv_min) + target_uv_min\n preprocessed_yuv_images = tf.concat([y, u, v], axis=last_dimension_axis)\n rgb_tensor_images = tf.image.yuv_to_rgb(preprocessed_yuv_images)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------|---------------------------------------------------------------------------|\n| `images` | 2-D or higher rank. Image data to convert. Last dimension must be size 3. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|----------|-----------------------------------------|\n| `images` | tensor with the same shape as `images`. |\n\n\u003cbr /\u003e"]]