### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: [SOLVED] How do I use YCbCr Color space?  (Read 4254 times)

#### lulZghost

• New Member
• Posts: 15
##### [SOLVED] How do I use YCbCr Color space?
« on: January 08, 2019, 08:04:04 pm »
For a school project I have to make an converter that extracts Y, Cb and Cr channels from a picture.
I found the calculations on the internet but the result doesn't look like any example. So I think I didn't use the calculated value right. I don't really find anything for YCbCr in Pascal ... because I don't really know what to do I rounded them which brought the result you can see on the attached image.

y:= R *  0.29900 + G *  0.58700 + B *  0.11400;
cb:= R * -0.16874 + G * -0.33126 + B *  0.50000 + 128;
cr:= R *  0.50000 + G * -0.41869 + B * -0.08131 + 128;

//
Edit: I figured it out. I did an rough mistake while drawing the new canvases. New and correct result : https://i.gyazo.com/35034be3de10217561b98ddb4b4f243c.png.
« Last Edit: January 10, 2019, 06:50:28 pm by lulZghost »

#### lucamar

• Hero Member
• Posts: 3030
##### Re: How do I use YCbCr Color space?
« Reply #1 on: January 08, 2019, 08:18:37 pm »
You have probably seen this already but just in case: Wikipedia: YCbCr.

It includes the (correct) formulae to convert from RGB.

ETA: Charles Poynton's Color FAQ is a must-read-and-keep-close if you intend to do much work about color.
« Last Edit: January 08, 2019, 08:21:29 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!)
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

#### jamie

• Hero Member
• Posts: 3541
##### Re: How do I use YCbCr Color space?
« Reply #2 on: January 08, 2019, 11:47:12 pm »
G = 59%
R = 30%
B = 11%

Summed = Y; (Chroma)

As for the B and R channel color channels the two of them are at 50% for a gray scale.

By calculating the percentage of B and R difference of G  you get the 50%+/- depending on which
direction it is with the R channel.

So if R and B were both at 0 then Green would be the dominate color.

going the other way, that is B and R in the + range would reduce the G gain etc

Its hard to think about but I've done some slow scan software where I had to support these older style
of color formats.

The only true wisdom is knowing you know nothing