<p>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%.</p>

<p>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.</p>

<p>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.</p>

<p>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 <em>not</em> 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.)</p>

<p>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.</p>

<p>What steps are required to convert 'luma' to luminance given the available data?</p>

<p>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.</p>

CC BY-SA 4.0
2019-12-03T16:30:48.697Z
When you say, convert RGB to R'G'B', by the latter are you meaning sRGB encoded values?
Simon F
CC BY-SA 4.0
2019-12-03T16:56:26.030Z
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.
Tricky
CC BY-SA 4.0
2019-12-04T09:24:37.420Z
I (possibly incorrectly) have just assumed the steps are  YCbCr => Apply Matrix=> r'g'b' (==sRGB) => apply gamma to decompress to linear RGB.
Simon F
CC BY-SA 4.0
2019-12-04T11:53:37.937Z
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: https://docs.microsoft.com/en-us/windows/win32/medfound/extended-color-information#color-space-conversion I'm assuming after step 4 you can calculate luminance using the primaries from the meta data?
Tricky
CC BY-SA 4.0
2019-12-04T14:49:58.507Z
Chapter 3 of "Video Demystified" might be of use to you https://sites.cs.ucsb.edu/~mturk/Courses/CS281B-2011/Misc/VideoDe.pdf
Simon F
<color><color-science><color-management>
Calculating Luminance From Y'CbCr
Tricky
# Calculating Luminance From Y'CbCr

(Asked by: username_0 on 2019-12-03)

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.

**Tags:** color, color-science, color-management

> **Comments:**
> **username_1**: When you say, convert RGB to R'G'B', by the latter are you meaning sRGB encoded values?  
> **username_0**: 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.  
> **username_1**: I (possibly incorrectly) have just assumed the steps are  YCbCr => Apply Matrix=> r'g'b' (==sRGB) => apply gamma to decompress to linear RGB.  
> **username_0**: 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: https://docs.microsoft.com/en-us/windows/win32/medfound/extended-color-information#color-space-conversion I'm assuming after step 4 you can calculate luminance using the primaries from the meta data?  
> **username_1**: Chapter 3 of "Video Demystified" might be of use to you https://sites.cs.ucsb.edu/~mturk/Courses/CS281B-2011/Misc/VideoDe.pdf  

---

## 0 answers

