# cbloom rants

## 12/01/2006

### 12-01-06 - 2

I found these really nice J2K slides if you want to learn about JPEG2000.

I couldn't find this info easily anywhere on the web, so here you go. Lossless color transforms :

```
Color transform notes :

JPEG-LS (LOCO-I) uses :

{RGB} -> { (R-G), G, (B-G) }

and the inverse is obvious
BTW this is very nice in that you can go 8bit -> 8bit using modulo arithmetic,
many of the others require 9 bit YUV coefficients.

J2K (aka RCT aka CREW) uses :

{RGB} ->
Y = (R + 2G + B)/4
U = R-G
V = B-G

G = Y - (U+V)/4;
R = U + G
B = V + G

(the divides are floored)

YCoCg is :
(similar to "RCT" but decorrelates better)

lossy :

Y = (R + 2G + B)/4
Co= (R-B)/2
Cg= (2G - R - B)/4

G = Y + Cg
R = Y - Cg + Co
B = Y - Cg - Co

lossless :
(Co and Cg are effectively scaled up by 2)

Co = R-B
t = B + (Co/2)
Cg = G-t
Y = t + (Cg/2)

s = Y - (Cg/2)
G = Cg + s
B = s - (Co/2)
R = B + Co

```

In general with the lossless YUV type transforms, the chromatic coefficients are roughly 2X bigger than they should be in a perceptual space in order to have the bits to get back to RGB exactly.

Note that YUV was created for perceptual uniformity, NOT for decorrelation, so it's no surprise that you can beat it for decorrelation. In fact, doing the 3x3 KLT and sending the coefficients is totally worth it if you're doing compression. (actually YUV was created for some weird use in televisions)