It appears that in the digital world, nothing confounds people more than the concept of Middle Gray – second only to actually finding Carmen Sandiego. Where exactly is Middle Gray? Why are there so many different quoted values for Middle Gray and which value is actually correct? In this write-up, we will explore Middle Gray in a little more detail.
Firstly, let’s start with a disclaimer and a qualifier – there are numerous discussions around a “calibration constant” being set close to 12% or just below 18% or a Middle Gray at 18.4% based on CIELAB derived values. We won’t be going down that rabbit hole. To keep things simple, the most commonly used reference for Middle Gray is 18%, as presented on a typical Gray Card, and we will be referencing that value from here onwards.
So Middle Gray is 18% of what one may ask? Let’s look at this in the context of a Camera sensor. When a sensor captures raw data from a scene, it is captured in linear light. If we look at these values in terms of a 0 – 1 scale for an SDR signal, where zero results in no light being reflected and one results in all the light being reflected back (peak white), a properly configured Middle Gray card will result in a reading of 0.18, or 18% of the light being reflected back. Where the real confusion begins is when this linear signal is then encoded into a separate Gamma such as Rec.709 or sRGB.
Throughout Internet and social media platforms such as Facebook and YouTube, one can find oh so many ill-informed statements that set arbitrary Middle Gray values at 50%, 42.5%, 38%, 43% or any other random IRE. These random values have no meaning without providing the Gamma context under which they have been defined.
Let’s take a look at sRGB for example. It is defined by the following transfer function which encodes linear light (V) into the sRGB Gamma (VsRGB):
If we plug the linear light value of 0.18 for Middle Gray into the equation, we can then obtain the result:
To the average person, this may equate to 46.1% IRE for Middle Gray, but that’s not quite right. To get the IRE value, we must then perform a further calculation (assuming 10-bit values):
The Middle Gray for sRGB is therefore defined as 46.6% IRE and not 50% or whatever value quoted by some random YouTuber or forum user on the internet.
Following similar methods from above, we can also calculate the Rec.709 Gamma Middle Gray value from the ITU-R BT.709 transfer function:
But there is a catch – these are data values, which are defined in the full range (0 – 1023 for a 10-bit signal). In the video world, many encoding curves are often defined in the context of Video Legal ranges (64 – 940 for a 10-bit signal). The ITU-R BT.709 and the ITU-R BT.2100 HLG curves are prime examples of this as they are defined using legal ranges. Conversely, many Log curves are often defined in the context of full data ranges – Panasonic’s V-Log is one example that uses the full data range for encoding. It’s important to confirm whether the relevant Log curve uses full data levels or video legal levels before attempting to derive the relevant Middle Gray value.
Getting back to the math, in order to convert a data signal to a video legal range, we must use the quantization equation defined by the ITU:
If we plug this into the IRE equation and then simplify, we get the following Middle Gray value for Rec.709 Scene:
In the case of gamma curves that use video ranges, the Middle Gray IRE value can be obtained directly from the transfer function without the need to perform additional quantization and IRE calculations.
One can also verify these Middle Gray values on a NLE such as DaVinci Resolve by downloading the Linear Gray Chart below and performing the relevant Color Space Transform from Linear to the desired Gamma. The chart below shows Absolute Black, Middle Gray and Absolute White on a linear scale. To download the image, right click on it and select the “Save Image” option on your browser.
This chart can also be generated using a DCTL (DaVinci Color Transform Language) that I have released alongside others on GitHub. To use the DCTL, simply add the transform through the DCTL ResolveFX plugin on a node in the Color page and select Linear as the Gamma setting. Ensure this is followed by a Color Space Transform node going from Linear to the desired gamma setting.
Whilst math calculations are always the most accurate method of identifying a Middle Gray IRE, it’s understandable that this may not be everyone’s strong point and the transfer equation calculations can sometimes get complicated. The Middle Gray values for other gamma curves can be found easily by using Resolve and changing the output Gamma setting on the Color Space Transform. The Low or High reference level can then be manually adjusted to align with the Middle Gray block from the Chart – just ensure the useless Tone Mapping and OOTF options are disabled. It’s also important to note that DaVinci Resolve uses data levels internally, so the default waveform monitor will show results based on a full signal range.
Following the guide above, when the ITU-R BT.709 (Rec.709 Scene) Gamma curve is applied on the Linear Gray Chart, the Middle Gray value shows an output of 41% on the Waveform – exactly as per our calculations, albeit rounded to the nearest whole integer.
Now that we’ve elaborated on the mathematical functions and a somewhat rudimentary method of identifying the Middle Gray IRE using DaVinci Resolve, I’ve documented some commonly used values for future reference in the table below. Hopefully this write-up has been somewhat useful in clarifying any misconceptions surrounding Middle Gray.
|Gamma Curve||Middle Gray|