With the 2.0 SDK version, we added a gpu_pipeline support. With this mode enabled, you can use a powerful instrument to change the brightness or color levels of the video in MPlatform and MFormats.
Important! This feature works only with the GPU-pipeline mode enabled.
What is a color transformation matrix?
In its most common form, color correction takes a form of 3x3 matrix operation, where each line is multiplied to some constant parameter (level), so we can imagine it as 4x3 matrix:
and the color correction calculation looks like:
Rcc = Lr*(Rr*Ro + Rg*Go + Rb*Bo),
Gcc = Lg*(Gr*Ro + Gg*Go + Gb*Bo),
Bcc = Lb*(Br*Ro + Bg*Go + Bb*Bo),
Where Rcc, Gcc, and Bcc are the color-corrected output signals, Rr – Bb are the matrix coefficients for the color correction matrix, and Ro, Go, and Bo are the original signals.
How to set the matrix?
The matrix is set like a string of 12 coefficients separated by commas. The coefficients are in this order:
Rr, Rg, Rb, Lr, Gr, Gg, Gb, Lg, Br, Bg, Bb, Lb
For example, a matrix that doesn't transform colors - uses original signals - is "1,0,0,0,0,1,0,0,0,0,1,0"
To enable a color conversion you can specify the "gpu.rgb_transform_matrix" property in the system registry for MPlatform:
//MPlatform
HKEY_CURRENT_USER\Software\Medialooks\MPlatform\MFile
HKEY_CURRENT_USER\Software\Medialooks\MPlatform\MPlaylist
HKEY_CURRENT_USER\Software\Medialooks\MPlatform\MPreview
HKEY_CURRENT_USER\Software\Medialooks\MPlatform\MRenderer
gpu.rgb_transform_matrix = 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0
or in a source code with PropsSet method.
MPlatform
string BT2020_BT709 =@"
1.6605, -0.5876, -0.0728, 0.0,
-0.1246, 1.1329, -0.0083, 0.0,
-0.0182, -0.1006, 1.1187, 0.0";
m_objMFile.PropsSet("object::gpu.rgb_transform_matrix", BT2020_BT709 );
MFormats
Here you transform each and every frame separately:
pFrame.MFStrSet("gpu.rgb_transform_matrix", "1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0");
Shorten matrix values
You can set a full-sized matrix every time you use it - with all 12 parameters specified. But there are shorten version of the matrix:
Example value | Parameters | Explanation |
---|---|---|
"0.5" |
Specifies only the main diagonal color elements Rr = Gg = Bb, |
|
"0.5, 0.5" |
Specifies the main diagonal color elements (with the same value) Rr = Gg = Bb, |
|
"0.7,0.5,0.9, 0.1,1.5,-0.2" | Specifies the main diagonal color elements with individual values (Rr, Gg, Bb), and the level values for each color (Lr, Lg, Lb). Other parameters are 0. |
Predefined matrixes
There are a few predefined matrixes in SDK - for common color conversion scenarios like conversion of BT.709 colors into BT.2020.
You can specify such matrices by its shorten names with the PropsSet method:
Shorten name | Full matrix value | Description |
---|---|---|
BT2020_BT709 | 1.6605, -0.5876, -0.0728, 0.0, -0.1246, 1.1329, -0.0083, 0.0, -0.0182, -0.1006, 1.1187, 0.0 |
Converts original video as it was BT.2020 to BT.709. |
BT709_BT2020 | 0.627, 0.329, 0.0433, 0.0, 0.0691, 0.92, 0.0113, 0.0, 0.0164, 0.088, 0.896, 0.0 |
Converts original video as it was BT.709 to BT.2020. |
RGB_YUV_601 | 0.257, 0.504, 0.098, 0.0625, -0.148, -0.291, 0.439, 0.500, 0.439, -0.368, -0.071, 0.500 |
Converts original video as it was RGB to YUV BT.709. |
RGB_YUV_709 | 0.183, 0.614, 0.062, 0.0625, -0.101, -0.338, 0.439, 0.500, 0.439, -0.399, -0.040, 0.500 |
Converts original video as it was RGB to YUV BT.709. |
RGB_YUV_2020 | 0.225613, 0.582282, 0.050928, 0.062745, -0.119918, -0.309494, 0.429412, 0.500, 0.429412, -0.394875, -0.034537, 0.500 |
Converts original video as it was RGB to YUV BT.2020. |
YUV_RGB_601 | 1.164, 0.000, 1.596, -0.87075, 1.164, -0.813, -0.391, 0.52925, 1.164, 2.018, 0.000, -1.08175 |
Converts original video as it was YUV to RGB BT.601. |
YUV_RGB_709 | 1.164, 0.000, 1.793, -0.96925, 1.164, -0.213, -0.534, 0.30075, 1.164, 2.115, 0.000, -1.13025 |
Converts original video as it was YUV to RGB BT.709. |
YUV_RGB_2020 | 1.164384,0.000000,1.717000,-0.931559, 1.164384,-0.191603,-0.665274,0.355379, 1.164384,2.190671,0.000000,-1.168395 |
Converts original video as it was YUV to RGB BT.2020. |
Full_To_16_235 | 0.856305, 0.0, 0.0, 0.0625, 0.0, 0.856305, 0.0, 0.0625, 0.0, 0.0, 0.856305, 0.0625 |
Converts original video as it was a full RGB range (0..255) to a shorten RGB range (16..235). |
Full_From_16_235 | 1.167808, 0.0, 0.0, -0.0729880, 0.0, 1.167808, 0.0, -0.0729880, 0.0, 0.0, 1.167808, -0.0729880 |
Converts original video as it was a shorten RGB range(16..235) to a full RGB range (0..255). |
Examples
There is a sample application attached to this article where the functionality of matrix color correction is illustrated.
Here is a sample of how it looks:
Original video with the original matrix value of "1,0,0,0,0,1,0,0,0,0,1,0" (doesn't change anything):
And a transformed one (with defined in the sample grayscale transformation) with the matrix value of "1,0,0,0,1,0,0,0,1,0,0,0":