1、在图像处理中经常需要对图像数据进行转换,最常见的莫过于YUV2RGB。并且这个转化在不同的标准下有不同的转化公式。
2、如果公式不匹配,则会导致转换后的图像效果有偏差。
3、full_range下Y\U\V的取值范围都为[0, 255];limit_range(也叫part_range)下Y的取值范围为[16, 235],UV的取值范围为[16, 240].
一、BT601
Full_Range:
bt601_full_range_yuv2rgb = {
1.0, -0.0, 1.402;
1.0, -0.3441, -0.7141;
1.0, 1.772, -0.0;
};
R = Y + 1.402 * (V - 128);
G = Y - 0.3441 * (U - 128) - 0.7141 * (V - 128);
B = Y + 1.772 * (U - 128);
bt601_full_range_rgb2yuv = {
0.299, 0.587, 0.114;
-0.1687, -0.3313, 0.5;
0.5, -0.4187, -0.0813;
};
Y = 0.299 * R + 0.587 * G + 0.114 * B;
U = -0.1687 * R - 0.3313 * G + 0.5 * B;
V = 0.5 * R - 0.4187 * G - 0.0813 * B;
Limit_Range:
bt601_limit_range_yuv2rgb = {
1.1644, 0.0, 1.5958;
1.1644, -0.3938, -0.8130;
1.1644, 2.0172, -0.0;
};
R = 1.1644 * (Y - 16) + 1.5958 * (V - 128);
G = 1.1644 * (Y - 16) - 0.3938 * (U - 128) - 0.8130 * (V - 128);
B = 1.1644 * (Y - 16) + 2.0172 * (U - 128);
bt601_limit_range_rgb2yuv = {
0.257, 0.504, 0.098;
-0.148, -0.291, 0.439;
0.439, -0.368, -0.0714;
};
Y = 0.257 * R + 0.504 * G + 0.098 * B;
U = -0.148 * R - 0.291 * G + 0.439 * B;
V = 0.439 * R - 0.368 * G - 0.0714 * B;
二、BT709
Full_Range:
bt709_full_range_yuv2rgb = {
1.0, 0.0, 1.5748;
1.0, -0.1873, -0.4681;
1.0, 1.8556, 0.0;
};
R = Y + 1.5748* (V - 128);
G = Y - 0.1873 * (U - 128) - 0.4681 * (V - 128);
B = Y + 1.8556 * (U - 128);
bt709_full_range_rgb2yuv = {
0.2126, 0.7152, 0.0722;
-0.1146, -0.3854, 0.500;
0.500, -0.4542, -0.0458;
};
Y = 0.2126 * R + 0.7152 * G + 0.0722 * B;
U = -0.1146 * R - 0.3854 * G + 0.5 * B;
V = 0.5 * R - 0.4542 * G - 0.0458 * B;
Limit_Range:
bt709_limit_range_yuv2rgb = {
1.1644, 0.0, 1.7927;
1.1644, -0.2132, -0.5329;
1.1644, 2.1124, -0.0;
};
R = 1.1644 * (Y - 16) + 1.7927 * (V - 128);
G = 1.1644 * (Y - 16) - 0.2132 * (U - 128) - 0.5329 * (V - 128);
B = 1.1644 * (Y - 16) + 2.1124 * (U - 128);
bt709_limit_range_rgb2yuv = {
0.1826, 0.6142, 0.0620;
-0.1006, -0.3386, 0.4392;
0.4392, -0.3989, -0.0403;
};
Y = 0.1826 * R + 0.6142 * G + 0.062 * B;
U = -0.1006 * R - 0.3386 * G + 0.4392 * B;
V = 0.4392 * R - 0.3989 * G - 0.0403 * B;
三、BT2020
Full_Range:
bt2020_full_range_yuv2rgb = {
1.0, -0.0, 1.4746;
1.0, -0.1646, -0.5714;
1.0, 1.8814, -0.0;
};
R = Y + 1.4746* (V - 128);
G = Y - 0.1646 * (U - 128) - 0.5714 * (V - 128);
B = Y + 1.8814 * (U - 128);
bt2020_full_range_rgb2yuv = {
0.2627, 0.6780, 0.0593;
-0.1396, -0.3604, 0.500;
0.500, -0.4598, -0.0402;
};
Y = 0.2627 * R + 0.6780 * G + 0.0593 * B;
U = -0.1396 * R - 0.3604 * G + 0.5 * B;
V = 0.5 * R - 0.4598 * G - 0.0402 * B;
Limit_Range:
bt2020_limit_range_yuv2rgb = {
1.1644, -0.0, 1.6787;
1.1644, -0.1873, -0.6504;
1.1644, 2.1418, 0.0;
};
R = 1.1644 * (Y - 16) + 1.6787 * (V - 128);
G = 1.1644 * (Y - 16) - 0.1873 * (U - 128) - 0.6504 * (V - 128);
B = 1.1644 * (Y - 16) + 2.1418 * (U - 128);
bt2020_limit_range_rgb2yuv = {
0.2256, 0.5823, 0.0509;
-0.1227, -0.3166, 0.4392;
0.4392, -0.4039, -0.0353;
};
Y = 0.2256 * R + 0.5823 * G + 0.0509 * B;
U = -0.1227 * R - 0.3166 * G + 0.4392 * B;
V = 0.4392 * R - 0.4039 * G - 0.0353 * B;