Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code for preprocessing of YUV images before feeding yuv_to_rgb #37565

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions tensorflow/python/ops/image_ops_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3293,6 +3293,31 @@ def yuv_to_rgb(images):
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 `yub_to_rgb`.

```python
yub_images = tf.random.uniform(shape=[100, 64, 64, 3], maxval=255)
last_dimension_axis = len(yub_images.shape) - 1
yub_tensor_images = tf.truediv(
tf.subtract(
yub_images,
tf.reduce_min(yub_images)
),
tf.subtract(
tf.reduce_max(yub_images),
tf.reduce_min(yub_images)
)
)
y, u, v = tf.split(yub_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_yub_images = tf.concat([y, u, v], axis=last_dimension_axis)
rgb_tensor_images = tf.image.yuv_to_rgb(preprocessed_yub_images)
```

Args:
images: 2-D or higher rank. Image data to convert. Last dimension must be
size 3.
Expand Down