<div dir="auto">Not sure if it was explained to me elsewhere before<div dir="auto"><br></div><div dir="auto"><a href="https://sites.google.com/view/ananyamukherjeehome/image-processing/color-spaces" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">https://sites.google.com/view/ananyamukherjeehome/image-processing/color-spaces</a><br></div><div dir="auto"><br></div><div dir="auto">====</div><div dir="auto"><br></div><div dir="auto"><h2 dir="ltr"><div>UV coefficients from Y coefficients</div></h2><p dir="ltr">In a 3x3 RGB to YUV matrix, it is enough to know the RGB to Y conversion coefficients. The coefficients for U and V can be derived from them. </p><p dir="ltr"><br></p><p dir="ltr">[..]</p><p dir="ltr"><br></p><p dir="ltr">Often, x and y of red green and blue and a white point (eg <span style="text-decoration-line:underline"><a href="https://www.google.com/url?q=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FIlluminant_D65&sa=D&sntz=1&usg=AOvVaw1bJwIHCrhis7NKs6vy6VKk" rel="noreferrer noreferrer" target="_blank">D65</a></span>) are specified in specs such as <span style="text-decoration-line:underline"><a href="https://www.google.com/url?q=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FRec._709%23Primary_chromaticities&sa=D&sntz=1&usg=AOvVaw3wBydyI2YYVmqxo_GZ-eSM" rel="noreferrer noreferrer" target="_blank">BT 709</a></span>. Given the 6 primary chromaticity numbers and the 2 white point numbers, you can plug them in <span style="text-decoration-line:underline"><a href="http://www.google.com/url?q=http%3A%2F%2Fwww.russellcottrell.com%2Fphoto%2FmatrixCalculator.htm&sa=D&sntz=1&usg=AOvVaw3UhBjMsRqOR1VdSDooBpYP" rel="noreferrer noreferrer" target="_blank">here</a></span> and get your RGB->XYZ matrix. The mathematical details of the conversion can be found <span style="text-decoration-line:underline"><a href="http://www.google.com/url?q=http%3A%2F%2Fwww.brucelindbloom.com%2Findex.html%3FEqn_RGB_XYZ_Matrix.html&sa=D&sntz=1&usg=AOvVaw05o46rC34j3SnJHd_Mh6no" rel="noreferrer noreferrer" target="_blank">here</a></span>.
Now the middle row of this matrix converts from RGB to Y, and this Y is
the Y of YUV color space. So you can get the coefficients of Y from
here given primary chromaticities<br></p><p dir="ltr"><br></p><p dir="ltr">====</p><p dir="ltr">but of course it up to reader to figure out how limited/full range difference should be used in those calculations ....</p><p dir="ltr"><br></p><p dir="ltr">from example in </p><p dir="ltr">mjpegtools-2.2.1/lavtools/jpeg2yuv.c<br></p><p dir="ltr"><br></p><p dir="ltr">/** Rescales the YUV values from the range 0..255 to the range 16..235</p><p dir="ltr"> @param yp: buffer for Y plane of decoded JPEG</p><p dir="ltr"> @param up: buffer for U plane of decoded JPEG @param vp: buffer for V plane of decoded JPEG */</p><p dir="ltr">static void rescale_color_vals(int width, int height, uint8_t *yp, uint8_t *up, uint8_t *vp) {</p><p dir="ltr"> int x,y; for (y = 0; y < height; y++) for (x = 0; x < width; x++)</p><p dir="ltr"> yp[x+y*width] = (float)(yp[x+y*width]) * ((235.0 - 16.0)/255.0) + 16.0;</p><p dir="ltr"><br></p><p dir="ltr"> for (y = 0; y < height/2; y++) for (x = 0; x < width/2; x++)</p><p dir="ltr"> { up[x+y*width/2] = (float)(up[x+y*width/2]) * ((240.0 - 16.0)/255.0) + 16.0;</p><p dir="ltr"> vp[x+y*width/2] = (float)(vp[x+y*width/2]) * ((240.0 - 16.0)/255.0) + 16.0;</p><p dir="ltr"> }</p><p dir="ltr">}</p><p dir="ltr"><br></p><p dir="ltr">for 4:2:0 subsampled yuv arrays as far as I understand.</p><p dir="ltr"><br></p><p dir="ltr">so, this can be simplified to multiplication of chroma and luma values by their constants? Also matrix, but 2*1 ?</p><p dir="ltr">And what to do with two differently sized matrixes?</p><p dir="ltr">I am cornered myself .....</p><p dir="ltr"><br></p></div></div>