Y’CbCr (“YUV”) conversion – part 1Image Processing
Ok this week let’s try something a little bit more useful than random manipulation of one picture.
Starting from the same beautiful Yosemite picture, we will convert it from RGB color space to Y’CbCr color space.
Many websites can help you to get more background on Y’CbCr color spaces, and commonly called “YUV”. I am still studying myself and I put some interesting links below.
In our case, we will convert to Y’CbCr using these formulas as suggested in the JFIF spec, and based on ITU-R BT.601 standard:
Y’ = 0.299 R’ + 0.587 G’ + 0.114 B’
Cb = – 0.1687 R’ – 0.3313 G’ + 0.5 B’ + 128 (127.5 ? see note 2)
Cr = 0.5 R’ – 0.4187 G’ – 0.0813 B’ + 128 (127.5 ? see note 2)
With these formulas, if R’, G’, B’ range is 0-255, then Y’, Cb, Cr range is also 0-255. If there is not chroma (=it is grey), then Cb=Cr=128.
This conversion from RGB colors to luma-chroma will allow us to process differently luma and chroma, so details and color. In particular it will allow us to work on brightness, contrast, sharpness on the luma channel. And color enhancement will be done on the chroma channel. Noise reduction can also be done differently on luma and chroma this way. So there are many interesting reasons to inplement this color space conversion.
Questions ? Corrections ? Feel free to comment and to share !
- primes ‘ mean that values are gamma corrected
- in the Y’CbCr formula, to really have the range 0-255, the offset to add should be +127.5, not +128 like written in the JFIF spec. Rounding down is another option of course.
- YUV and luminance considered harmful: http://www.poynton.com/PDFs/YUV_and_luminance_harmful.pdf
- About YUV Video: http://msdn.microsoft.com/en-us/library/windows/desktop/bb530104(v=vs.85).aspx
- and of course Wikipedia: YUV http://en.wikipedia.org/wiki/YUV, YCbCr http://en.wikipedia.org/wiki/YCbCr
- JPEG File Interchange Format: http://www.jpeg.org/public/jfif.pdf
[…] Then for every pixel we compute Y’, Cb and Cr values, using the formulas from the previous post. […]