meridius
meridius

Reputation: 161

TensorFlow: 'tf.image.rgb_to_yuv' not working

Currently I'm working on an image encoder implementation with tensorflow, and in order to transform from RGB- to YUV-colorspace, I wanted to use the tensorflow function tf.image.rgb_to_yuv, which appears not to exist (although it's documented here: https://www.tensorflow.org/api_docs/python/tf/image/rgb_to_yuv), since I get the error message:

AttributeError: module 'tensorflow.python.ops.image_ops' has no attribute 'rgb_to_yuv'

I'm using Tensorflow 1.8. For example, the analogue HSV-transformation tf.image.rgb_to_hsv works properly, so it appears to be a special issue related only to the rgb_to_yuv transform. Maybe it has something to do with the transition to the 1.x versions of Tensorflow, in which certain functions got new names, but I could not find anything about it. Does someone know, what's going on here?

Thanks in advance

Upvotes: 0

Views: 962

Answers (2)

Yaoshiang
Yaoshiang

Reputation: 1941

I believe the documentation is incorrect. The range of U and V are supposed to be [-0.436, 0.436] and [-0.615, 0.615].

https://en.wikipedia.org/wiki/YUV#Conversion_to/from_RGB

The kernel used in the TF source allows the U to go beyond that range, all the way to [-0.43601035, 0.43601035].

https://github.com/tensorflow/tensorflow/blob/v2.2.0/tensorflow/python/ops/image_ops_impl.py

Finally, The YUV-RGB matrix used in the TF source is for linear RGB, not the gamma corrected sRGB we are used to using online.

Based on my initial research, my hypothesis is that the best approach is probably to implement your own sRGB to YCbCR conversion. YCbCr was designed for gamma corrected sRGB. I'm working on it and I'll repost here once I've tested it.

Upvotes: 0

benjaminplanche
benjaminplanche

Reputation: 15119

tf.image.rgb_to_yuv() is present in Tensorflow 1.8 c.f. the version's source (image_ops_impl.py#L1852).

Maybe double-check if the TF version you're running is indeed 1.8...? (print(tf.__version__))

Upvotes: 1

Related Questions