# LAB Lightness to black and white using GIMP 2.9 and PhotoShop

This article shows mathematically correct and incorrect ways to use the LAB Lightness channel to convert a color image to black and white when using GIMP 2.9, explains the relationship between LAB Lightness and RGB Luminance, and summarizes mathematical mistakes behind the typical PhotoShop tutorial on using LAB Lightness to convert to black and white.

This article is Part 2 of a two-part article. Part 1, LAB Lightness to black and white using GIMP 2.8 explains how to make a mathematically correct conversion from LAB Lightness to RGB black and white using GIMP 2.8, and also explains why doing so is not a good idea (results are severely posterized because of the required 8-bit integer conversion to linear gamma sRGB and back).

Written September 2015.

## Introduction

This article is Part 2 of a two-part article on using the LAB Lightness channel to convert a color RGB image to black and white. Many GIMP and PhotoShop articles and tutorials on converting an RGB image to black and white have a section on using the LAB Lightness channel, but most of these tutorials are based on mathematical and "color management" mistakes.

Section B below shows mathematically correct and incorrect ways to use the LAB Lightness channel to convert a color image to black and white when using GIMP 2.9. As the GIMP code changes, I'll try to update this page, with the goal of eventually turning it into a GIMP 2.10 tutorial on decomposing to LAB.

Section C shows easier ways (that don't involve decomposing the image) for GIMP 2.9 users to convert from LAB Lightness to RGB black and white, and considers the relationship between LAB Lightness and RGB Luminance. And again, as the GIMP code changes I'll try to update this page, with the goal of turning it into a GIMP 2.10 tutorial on decomposing to LAB.

Section D explains the mathematical mistakes behind the typical PhotoShop tutorial on using LAB Lightness to convert to black and white. Eventually I plan to expand this section to show how to replicate PhotoShop tutorial results using GIMP 2.9/2.10. (But the real question is why you'd want to, as you can get the same results — and with a good deal more control — by converting to RGB Luminance and using Curves . . . )

Section E lists some suggested changes in the GIMP/GEGL "Decompose to LAB" code.

For reference, here's the color photograph that I'm using to illustrate mathematically correct and incorrect ways to use LAB Lightness to convert to black and white, along with a mathematically correct conversion from LAB Lightness to RGB black and white:

If you want to follow along and verify results shown below (highly recommended — you'll learn a lot more by doing than by just reading), here's a downloadable 16-bit png version of the color photograph in Figure 1, licenced as CC-BY-SA 3.0 unported.

## From LAB Lightness to RGB black and white in GIMP 2.9

### The mathematically correct "Decompose/Bucket Fill the A and B channels/Recompose" method for GIMP 2.9

This procedure has already been explained for GIMP 2.8. There are only slight differences between GIMP 2.8 and 2.9, having to do with picking the right shade of gray for "bucket-filling" the A and B channels. Two preliminary notes should be considered:

• The image must be already in the GIMP built-in sRGB color space. Just as with GIMP 2.8, GIMP 2.9's code for converting to LAB is hard-coded to use the sRGB primaries.
• Unlike GIMP 2.8, GIMP 2.9 automatically (and silently) linearizes the RGB values (more about that below). So don't convert the image from the built-in sRGB color space to a linear gamma sRGB color space. (Try it anyway — what happens?)

And here's the procedure for GIMP 2.9 (the GIMP 2.8 equivalent procedure has pictures of the layer stack):

1. Do "Colors/Components/Decompose" and choose Color model "LAB", making sure "Decompose to layers" is checked and "Foreground as registration color" is not checked.
2. Don't drag the "L" channel over to the linear gamma color image! Instead, use "Bucket Fill" to fill the entire A and B channels with the color "Value=0.501961".
3. Then recompose the LAB layer stack to RGB ("Colors/Components/Recompose"). And you are done.

And now you have a mathematically correct LAB "L" to conversion to black and white, this time without the data loss and posterized shadows that result from trying to make a mathematically correct conversion from LAB Lightness to RGB using GIMP 2.8.

Hopefully you noticed the odd Value required to fill the A and B channels. You can generate this odd Value by decomposing to LAB a solid white layer (or black or neutral gray; the only requirement is that R=G=B), and color picking the resulting A or B channel. See Bug 755270 - Decompose/recompose to/from LAB plugin: scaling code produces odd L, a, and b values for an explanation for why you need such an odd Value to get a mathematically correct LAB "L" conversion to black and white. Results aren't too far off if you use Value=0.500000, but the Red channel will be a bit low, the Green channel almost right, and the Blue channel a bit too high. White, for example, will recompose to (0.994662, 1.001333, 1.003732). In other words, the resulting recomposed image has been given very slight cyan-blue tint.

### "Decompose, drag, and drop" in GIMP 2.9: Very different results from GIMP 2.8

The commonly recommended "decompose, drag, and drop" procedure for using GIMP 2.8 to make a LAB Lightness ("L" channel) conversion to black and white has three steps:

1. Assign (or convert, as appropriate) to the GIMP built-in sRGB profile ("Image/Color Management/ . . . ").
2. Do "Colors/Components/Decompose" and choose Color model "LAB", making sure "Decompose to layers" is checked and "Foreground as registration color" is not checked.
3. Drag the "L" channel back to the original color image layer stack.

The only modification for GIMP 2.9 is that you should promote the image precision to 32-bit floating point ("Image/Precision/32-bit floating point (gamma)") before decomposing the RGB layer to LAB. Promoting the precision to 32-bit floating point reduces to essentially nil any potential posterization from the round-trip color space conversion from RGB to LAB and back to RGB.

Compared to "decompose, drag, and drop" results using GIMP 2.8, GIMP 2.9's "decompose, drag, and drop" produces an image that's actually pretty close to correct. But it's still not quite right:

The obvious question is what changed between GIMP 2.8 and 2.9, such that in GIMP 2.9 the "decompose, drag, and drop" method produces such drastically different and almost correct results. And the answer is simple:

As stated in Part 1 of this two-part article, a mathematically correct conversion from sRGB to LAB requires that the image be in a linear gamma version of the sRGB color space (technically speaking it's the conversion from sRGB to XYZ that requires linearized sRGB values, but converting to LAB requires first converting to XYZ). Or what amounts to the same thing, a correct conversion requires that the RGB values be "linearized" before making the conversion to LAB. GIMP 2.8 doesn't linearize the image's RGB values (and if it did, you'd get posterized results because GIMP 2.8 works with 8-bit integer values). But GIMP 2.9 does linearize the RGB values. This "linearization" happens silently, "under the hood" so to speak.

So the next question is why the GIMP 2.9 "decompose, drag, and drop" results are still slightly wrong, despite the "under the hood" linearization of the RGB values. If you read Part 1 of this article, you might assume it's because GIMP 2.9 still uses the wrong sRGB primaries to convert to LAB#incorrect-primaries, but actually those values were corrected quite awhile back.

The real reason why the GIMP 2.9 "decompose, drag, and drop" results are still slightly wrong has to do with the difference between the sRGB tone reproduction curve ("TRC") and a truly perceptually uniform TRC:

As an addendum, "Tools/GEGL Operation/Extract Components/Component LAB L" produces the same results as GIMP 2.9's "decompose, drag, and drop" method, which is to say, the resulting image is everywhere slightly too light, except in the deep shadows, where it's slightly too dark.

### Modifying the GIMP 2.9 "decompose, drag, and drop" method so it produces a correct conversion from LAB Lightness to black and white

Just as above, first promote the image precision to 32-bit floating point (gamma) precision. Then:

1. Assign (or convert to, as appropriate) the GIMP built-in sRGB profile ("Image/Color Management/ . . . ").
2. Do "Colors/Components/Decompose" and choose Color model "LAB", making sure "Decompose to layers" is checked and "Foreground as registration color" is not checked.
3. Working with the decomposed to LAB layer stack, do "Image/Mode/RGB" to turn the image from a grayscale layer stack to an RGB layer stack.

Notice that GIMP automatically assigns the built-in sRGB color space. This is the wrong color space profile. What you really need is an RGB profile with the LAB L TRC (in a grayscale-to-RGB image, with R=G=B everywhere, the profile primaries don't matter for properly interpreting the image RGB values; only the TRC matters).

4. Download the following modified sRGB color space profile: sRGB-elle-V4-labl.icc, which is a standard sRGB ICC profile, except the profile TRC matches the LAB L TRC. So don't use this profile for regular sRGB images!

5. Assign the downloaded "sRGB-elle-V4-labl.icc" profile to the LAB layer stack ("Image/Color Management/Assign").
6. Convert the LAB layer stack to GIMP's built-in sRGB profile ("Image/Color Management/Assign" and pick Convert to "Built-in RGB (GIMP built-in sRGB").
7. Then drag the "L" channel back to the original color image layer stack.

More recent versions of GIMP 2.9 will automatically do the profile conversion for you when you drag an RGB image from one XCF file to another, so all you really need to do is assign the sRGB-elle-V4-labl.icc profile and then drag the "L" channel back to your original layer stack.

And that's how to modify GIMP 2.9's "decompose, drag, and drop" method to give correct results when converting from LAB Lightness to RGB black and white.

## Easy ways to get a mathematically correct LAB Lightness conversion to black and white using GIMP 2.9

### Using the LCH Lightness blend mode to convert from LAB Lightness to RGB black and white

The easy ways to make a mathematically correct LAB "L" conversion to black and white using GIMP 2.9 don't even require decomposing to LAB. Here's one way:

1. Make a neutral gray layer (or black or white; the important thing is that R=G=B).
2. Move the color layer above the neutral gray layer.
3. Set the color layer blend mode to "Lightness (LCH)".

This works because the "LCH" color space is just a mathematical reformulation of the "LAB" color space, and "L" (Lightness) is the same for both color spaces.

4. Make a "New from Visible" layer, and you are done.

### Use RGB Luminance

Another easy way to make a LAB "L" conversion to black and white is to use "Colors/Desaturate (the second "Desaturate" in the menu)/Mono Mixer" and change the Channel Multipliers to Red: 0.222 / Green: 0.717 / Blue: 0.061, and *DON'T* use the gamma hack. Or use any other method for converting from RGB to Luminance that I gave in the following post to the GIMP user's list: Luminance and luma for an sRGB image using GIMP 2.9.

Well, you might be thinking, "Wait a minute. I thought we were talking about LAB Lightness. How did RGB Luminance get into this discussion?"

The answer is that when you do a mathematically correct conversion from the LAB Lightness channel to black and white (RGB black and white), what you get is RGB Luminance. This means any procedure for correctly producing RGB Luminance also produces a correct RGB rendition of the LAB Lightness channel. For example, using GIMP 2.9, convert your sRGB image to grayscale ("Image/Mode/Grayscale") and then back to RGB ("Image/Mode/RGB") — instant (and mathematically correct) LAB Lightness conversion to RGB black and white.

The only reason this "news" might come as a surprise is because just about every tutorial ever written on using the LAB Lightness channel to convert to black and white incorporates various mathematical errors in the conversion, such that the tonality of the resulting black and white image isn't anywhere near LAB Lightness/RGB Luminance. Well, maybe you aren't surprised, but the fact that "LAB Lightness" converts to "RGB Luminance" surprised me — my mental picture of what LAB Lightness "looked like" was based on results from following various PhotoShop "LAB Lightness to black and white", back when I still used PhotoShop and Windows.

I don't think users should be "visually misled" by image editing "how to" tutorials or software limitations, no matter how unintentionally or even how useful or aesthetically pleasing the resulting image might be. We've already seen two math errors incorporated into GIMP 2.8 tutorials on converting from LAB Lightness to RGB black and white:

1. Failing to linearize the RGB values before decomposing to LAB (this error does not affect GIMP 2.9).
2. Dragging the LAB "L" channel over to the RGB layer stack without first accounting for the fact that decomposing to LAB doesn't produce an RGB image in the sRGB color space (instead it produces a grayscale image that requires a grayscale profile with the LAB L TRC).

The typical PhotoShop tutorial on converting to black and white using LAB Lightness introduces a completely new twist on mathematically incorrect ways to get RGB black and white from LAB Lightness:

## Mathematical mistakes behind the typical PhotoShop tutorial on using LAB Lightness to convert to black and white

Unlike GIMP, PhotoShop allows to convert the layer stack to LAB (rather than just decomposing a layer to LAB), edit directly in the LAB color space, and see the resulting changes on the screen.

The procedure commonly found in PhotoShop tutorials on converting to black and white using the LAB L channel goes as follows:

1. Convert the image (or a flattened copy of the image) to LAB, either by changing the Mode from RGB to LAB, or using a profile conversion to PhotoShop's built-in LAB color space.
2. "Discard" ("delete", "deselect") the "a" and "b" channels by literally right-clicking on the channels and deleting them. Or else just select the L channel and make sure the a and b channels are invisible.
3. Then change the Mode to Grayscale (if it isn't already in Grayscale mode from deleting the "a" and "b" channels).
4. Then change the Mode from Grayscale to RGB.

What the authors of the various tutorials on making a LAB Lightness conversion to black and white seem to have not figured out, is that in PhotoShop the result of "discarding" ("throwing away", "deleting", "deselecting", etc) the color information in the LAB "a" and "b" channels depends entirely on the "Gray" Working Space that the user chose in the PhotoShop Color Settings dialog. Change the Gray Working Space (this has no effect on the RGB working space the image happens to be in), repeat the "Discard the "a" and "b" channels" procedure, and the result will change accordingly.

Figure 5 below shows sample results from following the "Discard the "a" and "b" channels" method of making a LAB Lightness conversion to black and white, for our example "red, green, and blue glass" photograph. For each "LAB Lightness to RGB black and white" conversion shown below, the image RGB working space was the regular sRGB working space. The only thing that changed in the procedure was the PhotoShop Color Setting for the Gray Working Space:

Here are sample PhotoShop tutorials providing various iterations of the "Discard the "a" and "b" channels" procedure, all taken from the first page of results from a Google search on "photoshop+convert+to+black+white+lab":

According to the author of the article from Digital Camera World (the last link in the above list of PhotoShop tutorials), the "'Lab Color' method . . . "generate[s] a particularly light, airy and smooth looking result that's well suited to delicate subjects and/or high-key or low-contrast treatments." The author doesn't specify what his Gray Working Space choice was. But given his descriptive terms "light, airy and smooth", I will guess that it was "Dot Gain 20%", which is the "lightest" result other than the result when using a custom linear gamma Gray setting, and also is the PhotoShop default setting for the Gray Working Space.

Why the usual PhotoShop tutorial produces mathematically incorrect conversions from LAB Lightness to RGB Luminance is exactly for the same reason the "decompose, drag, and drop" method produces mathematically incorrect results in GIMP 2.9: The wrong TRC is being used to interpret the RGB values. The image above and to the right shows deviations from perceptually uniform for the sRGB TRC, the gamma=1.8 TRC, and the gamma=1.0 TRC. Everywhere the curves are below the straight blue line, the "Discard the "a" and "b" channels" procedure produces RGB values that are lighter than the mathematically correct values.

As an aside, the mathematically correct way to get from LAB Lightness to RGB black and white using PhotoShop is to convert to LAB, fill the "a" and "b" channels with 50% gray, and convert back to RGB. And when you've converted back to RGB, what you have is plain old RGB Luminance.

To reiterate, "mathematically correct or incorrect" is not an aesthetic judgement. If you use PhotoShop, and you like the look you get following the "Discard the "a" and "b" channel" method of using the LAB Lightness channel to convert to RGB black and white, keep doing what you've been doing. But it would be nice if PhotoShop users weren't being misled into thinking that LAB Lightness is magically "light, airy, and smooth". All the "magic" is in the user's choice of a Gray Working Space, which dictates how far the resulting black and white image deviates from RGB Luminance.

## Take-away points relevant to GIMP 2.9 development

In the overall scheme of GIMP development, the following changes probably aren't especially high priority items. But it would nice if sometime before GIMP 2.10 is released:

1. The GIMP decompose to LAB code could be modified such that R=G=B decomposed to A and B channels where Value=0.500000 instead of Value=0.501961. It would also be nice to add "Decompose to LCH" to the Decompose menu (I already submitted a patch to do this).
2. The GEGL "Extract Components" code could be modified such that R=G=B decomposed to A and B channels where Value=0.500000 instead of Value=0.501961, and to produce a mathematically correct conversion from LAB Lightness to RGB (in other words, to produce RGB Luminance).
3. When dragging the LAB L (or A or B) channels back to the layer stack, the layer could be automatically converted from a profile with the LAB L TRC to the profile associated with the RGB layer stack. This would make the GIMP "decompose, drag, and drop" method of converting from LAB Lightness to RGB black and white produce mathematically correct results.
4. The decomposed to LAB layer stack could be color-managed by assigning a grayscale ICC profile with the LAB L TRC to the grayscale layer stack. As it stands, what the user sees depends on the monitor they use to view the grayscale layer stack (this is different from GIMP 2.8, which displays the grayscale image "as if" it were in the GIMP built-in sRGB color space, unless the user has chosen an RGB working space in Preferences).