# Calculating Luminance From Y'CbCr

I have a video feed generating a stream of of Y'CbCr frames (specifically 8-bit component Y'CbCr 4:2:0, luma range of 16-235, chroma range of 16-240) from which I'd like to calculate relative luminance of specific pixels in each frame with a margin of error at ~2%.

My understanding is that the Y' channel in a Y'CbCr signal is not luminance but luma, and therefore further work is required to reverse that conversion into its linear form.

Of course, to do that I need to know what values were used to compress the signal from its original linear RGB form into its current Y'CbCr state.

I understand there's usually a compression function used to convert linear RGB into R'G'B', so if I know what these are – I should have a fairly good shot at doing it. (That's assuming that not having the camera response curves isn't a problem, as I'm hoping that these are used to transform non-linear raw camera data into a linear form – and so for my purposes there isn't a benefit to reversing the signal transform this far.)

Available to me with the feed are references to a 'transfer function' (usually some ITU standard – BT.601-4 on my test device), a Y'CbCr Matrix (another ITU standard – BT.709-2 on my test device), and some color primaries (P3 D65 on my test device) and white balance gain values.

What steps are required to convert 'luma' to luminance given the available data?

My naive approach is to simply apply the inverse of the transfer function to the luma channel but my concern is that this will be grossly inaccurate. Also, white balance might be a factor too, but perhaps marginally enough to be within the 2% margin of error.

• When you say, convert RGB to R'G'B', by the latter are you meaning sRGB encoded values? Dec 3, 2019 at 16:30
• Good question. It could theoretically be any non-linear color space. I have to rely on the meta data. My test device lists a BT.601 'transfer function' (same as sRGB as I understand) but then a BT.709-2 Y'CbCr matrix, and P3 D65 color primaries. I was hoping someone might shed some light on how these, on the surface conflicting standards, might coexist in the context of the above. Dec 3, 2019 at 16:56
• I (possibly incorrectly) have just assumed the steps are YCbCr => Apply Matrix=> r'g'b' (==sRGB) => apply gamma to decompress to linear RGB. Dec 4, 2019 at 9:24
• I think you're right, although I'm not sure how the color space comes into play. This article from MS goes through the steps: docs.microsoft.com/en-us/windows/win32/medfound/… I'm assuming after step 4 you can calculate luminance using the primaries from the meta data? Dec 4, 2019 at 11:53
• Chapter 3 of "Video Demystified" might be of use to you sites.cs.ucsb.edu/~mturk/Courses/CS281B-2011/Misc/VideoDe.pdf Dec 4, 2019 at 14:49