## Need RGB->L*a*b* and L*a*b*->RGB algorithms

### Need RGB->L*a*b* and L*a*b*->RGB algorithms

Ben-

There's a number of color spaces that will give you something like that. Try
the color space FAQ :

http://www.faqs.org/faqs/graphics/colorspace-faq/

Usually there's just a few equations that relate the space to RGB so writing
the code is pretty easy.

> Hi, I've searched a long time on the net trying to find some C or Java
> code to do conversions from RGB to L*a*b* and back, but haven't found what
> I'm looking for. Actually, I'm not sure it's technically L*a*b* that I
> need, but I am basically looking to convert an 8-bit-per-channel RGB pixel
> into an 8-bit-per-channel format where ch.A would be the Luminance
> [0..255], ch.B and ch.C would describe the chrominance component in the
> range [0.255] each.

> So, I guess first, can anyone tell me exactly what that format would be
> called? I'm pretty sure it's similar to the L*a*b* concept, but I don't
> want to deal with white points, CIE XYZ etc., just a simple conversion
> that will allow me to make those RGB values more compressable.

> Then, does anyone have any hard code for me do do this?

> Thanks very much if you can help.

> - Ben

### Need RGB->L*a*b* and L*a*b*->RGB algorithms

Are you really sure that you want to do that?

I've got the algorithms if you really want them, but you should be aware
that there will be some rather substantial errors in the conversion of
double (L*a*b*) to integer (RGB) variables.

I've actually written some software to demonstrate these losses.

Kelvin Craig
Datacolor International

### Need RGB->L*a*b* and L*a*b*->RGB algorithms

> I understand that Photoshop uses L*a*b* internally for all
> it's calculations ...

Details are not publicly available, but this statement is certainly not true.

--
Charles Poynton

<http://www.inforamp.net/~poynton/>

### Need RGB->L*a*b* and L*a*b*->RGB algorithms

Hi,
I know exactly one place where Photoshop uses Lab.
Grayscale mode defines intensity of gray as L(RGB).
Roman Kris

> > I understand that Photoshop uses L*a*b* internally for all
> > it's calculations ...

> Details are not publicly available, but this statement is certainly not true.

> --
> Charles Poynton

> <http://www.inforamp.net/~poynton/>

### Need RGB->L*a*b* and L*a*b*->RGB algorithms

I'm sure I've put this up once already.  But maybe I didn't.....

Assuming a D65 illuminant, and NTSC primaries (taken from the Adobe Tiff
6.0 documentation)

RGB -> Lab

First convert to CIE XYZ tristimulus

X = (0.6070*R) + (0.1740*G)+(0.2000*B)
Y = (0.2990*R) + (0.5870*G) + (0.1140 * B)
Z = (0.0000*R) + (0.0.660*G) + (1.1110 * B)

Now the fun starts......

L = 116(Y/Yn)1/3 - 16
a = 500[(X/Xn)1/3 - (Y/Yn1/3)]
b = 200[(Y/Yn)1/3 - (Z/Zn)1/3]

1/3 means to the power of 1/3 by the way!

Here the values Xn, Yn, Zn are the values for white.  For a D65 illuminant,
and a standard 2 degree observer, use

Xn = 95.02
Yn = 100.00
Zn = 108.81

For values of X/Xn < 0.01, Y/Yn < 0.01, Z/Zn < 0.01, use this formula

L = 116[f(Y/Yn) - 16/116]
a = 500[f(X/Xn) - f(Y/Yn)]
b = 200[f(Y/Yn) - f(Z/Zn)]

where
f(Y/Yn) = (Y/Yn)1/3 when (Y/Yn) is greater than 0.008856, and f(Y/Yn) =
7.787(Y/Yn) + 16/116 when (Y/Yn) is less than or equal to 0.008856.

Use the same definitions for f(X/Xn) and f(Z/Zn)

You should be able to work out the reverse transformation!

Good luck

Hi!
Does anyone know, how to manage this:

I've got 1000+ images in RGB or with an own palette of 256 colours.
I have created a palette named MyPal and want to convert all these images to
this palette.

Settings:

Use custom palette: MyPal
Floyd-Steinberg
NO transparency
DO NOT remove unused colours

I'm using GIMP 1.1.19/Win32 :-( my Linux was messed up a couple of weeks ago