RGB tensor to YDbDr

Is there a way to convert a RGB tensor to YDbDr? I’m assuming maybe not. This seems like a basic question but I never verified that indexes representing the channels in in the tensor correspond to a color like: 0, 1, 2 = R, G, B, because if so then I should be able to take a tensor of Batch x RGB x Height x Width and use the equation in the wikipedia article.

Kornia might help you to achieve this.
https://kornia.readthedocs.io/en/latest/color.html#ycbcr

is YCbCr the same as YDbDr? Pretty sure this is different.

Yes, they seem to be different.
You could look at the source code of YCbCr and adapt it to YDbDr.

https://kornia.readthedocs.io/en/latest/_modules/kornia/color/ycbcr.html#rgb_to_ycbcr

Either way, to answer your question, Yes. You can take the RGB tensor and use the mapping equation in Wikipedia/elsewhere to convert RGB to YDbDr.

Also, RGB indices depend on the library that’s used to load the images. As I know, Numpy/Scipy libraries load RGB channels in indices 0,1,2 respectively, and OpenCV loads RGB channels in indices 2,1,0 by default.

1 Like