Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So you want to convert an RGB color into the Lab color space? Sure, that's possible.</p> <p>But there are a lot of different standards that are all referred to with the general name "Lab" color. You'll need to select one to use when writing your algorithm. Photoshop in particular <a href="http://help.adobe.com/en_US/photoshop/cs/using/WSfd1234e1c4b69f30ea53e41001031ab64-73eea.html#WSfd1234e1c4b69f30ea53e41001031ab64-73eaa" rel="nofollow noreferrer">uses</a> the CIELAB D50 standard, so you would want to use that one if you need to accurately simulate its processing.</p> <p>Another thing you have to keep in mind is that the RGB model is <strong>device-dependent</strong>, which means that in order to convert from RGB to Lab, you'll first need to convert from RGB into some device-independent, absolute color space. Adobe does this with their "Adobe RGB" format, but you can use something standard like sRGB. The adjustment process considers the device-dependence of the RGB color, but transforms the color into one that is device-independent. Once you have that, you can take the last step of transforming the color into the Lab color space.</p> <p>The <a href="http://en.wikipedia.org/wiki/Lab_color_space" rel="nofollow noreferrer">Wikipedia article</a> provides some background information and useful formulas when writing a conversion algorithm. And <a href="http://cookbooks.adobe.com/post_Useful_color_equations__RGB_to_LAB_converter-14227.html" rel="nofollow noreferrer">here's someone that has already written such a conversion algorithm</a>. And <a href="http://robotics.stanford.edu/~ruzon/software/rgblab.html" rel="nofollow noreferrer">one for MATLAB</a> you could probably convert.</p> <p>Depending on how serious you are (so probably not), you could also download the source for <a href="http://en.wikipedia.org/wiki/GIMP" rel="nofollow noreferrer">GIMP</a> and see how they've implemented the conversion algorithms. Their software claims to support the Lab space.</p> <p>Be careful, though, when converting <em>back</em> to RGB. The Lab color space can represent colors that are well outside the range of sRGB. Even in Photoshop, most of what you see in Lab mode is discarded once you convert the image back to RGB (or CMYK).</p> <hr> <p><strong>Edit:</strong> It's also worth considering that if your only goal is to lighten a color in a color space that better approximates human color perception than RGB, you might not need to fuss with Lab at all. Lots of applications do this by converting to either the <a href="http://en.wikipedia.org/wiki/HSL_and_HSV" rel="nofollow noreferrer">HSL or HSV color space</a>. (Photoshop calls HSV, HSB).</p> <p>The advantage is that you can simply adjust the "Lightness" or "Value" values to alter the intensity of the color (much like you would adjust the "Luminance" value in the Lab color space), but the conversion algorithms are much simpler (and often built into the standard libraries of your language of choice). </p> <p>For example, see <a href="https://stackoverflow.com/questions/4123998/algorithm-to-switch-between-rgb-and-hsb-color-values/4124469#4124469">my answer to this question</a> for a conversion algorithm written in a .NET language.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload