7

I am working on a data visualization tool using OpenGL, and the LAB color space is the most comprehensible color space for visualization of the data I'm dealing with (3 axes of data are mapped to the 3 axes of the color space). Is there a fast (e.g. no non-integer exponentiation, suitable for execution in a shader) algorithm for approximate conversion of LAB values to and from RGB values?

Palec's user avatar
Palec
13.8k8 gold badges80 silver badges145 bronze badges
askedMar 20, 2015 at 19:11
Justin Olbrantz's user avatar
2
  • I hope there is, but I doubt it exists. The cube root portion is going to be hard to simulate. Maybe using linear interpolation between a small number of equivalent points?CommentedMar 20, 2015 at 19:30
  • Well, here's a subquestion: are the values specified in e.g. OpenGL such that RGB values are linear (gamma applied automatically), or not (explicit gamma compensation)? If they are linear, that would mean the XYZ->RGB step requires only a matrix multiplication, correct?CommentedMar 20, 2015 at 19:49

1 Answer1

1

If doing the actual conversion calculation in a shader is too complex/expensive, you can always use a lookup table. Since both color spaces have 3 components, you can use a 3D RGB texture to represent the lookup table.

Using a 3D texture might sound like a lot of overhead. Since 8 bits/component is often used to represent colors in OpenGL, you would need a 256x256x256 3D texture. At 4 bytes/texel, that's a 64 MByte texture, which is not outrageous, but very substantial.

However, depending on how smooth the values in the translation table are, you might be able to get away with a lower resolution. Keep in mind that texture sampling uses linear interpolation. If piecewise linear interpolation is good enough with a certain base-resolution of the lookup table, you can greatly reduce the size.

If you go this direction, and can't afford to use 64 MBytes for the LUT, you'll have to play with the size of the LUT, and make a possible size/performance vs. quality tradeoff.

answeredMar 21, 2015 at 3:04
Reto Koradi's user avatar
Sign up to request clarification or add additional context in comments.

3 Comments

I'm not sure I follow your math. If you have 8bits per component, doesn't your table need to be 256x256x256?
@MarkRansom Argh, yes, I does. It did sound a little too good to be true.
@MarkRansom Ok, updated. Might look slightly less attractive now, but at least I hope it's correct. Thanks for pointing this out.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.