Linear Gamma vs Higher Gamma RGB Color Spaces: Gaussian Blur and Normal Blend Mode

Technically speaking, RGB color mixing should always be done in a linear gamma color space. When you blur or use the normal blend mode to mix colors in the regular sRGB color space, the resulting color is darker than it should be and sometimes acquires a noticeable color cast.

Written May 2012. Updated February 2015.

  1. Introduction: Editing in linear gamma color spaces
  2. Blurring and Normal Mode Blending: linear gamma and regular sRGB compared
    1. 100% bright, 100% saturated colors: very noticeable darkening artifacts
    2. Roughly 75% bright, 75% saturated colors: darkening is lessened, but is still obvious
    3. Roughly 50% bright, 50% saturated colors: darkening is visible but not especially noticeable
    4. Saturation vs brightness: which contributes most to the darkening artifacts that result when improperly mixing colors?
  3. Photographic images
    1. Flowers: regular sRGB turned a blue sky into a mottled green sky
    2. State Fair corn dog stand: regular sRGB turned silver hair to yellow and a turquoise shirt to green
  4. Final thoughts on blurring and normal mode blending in a linear gamma RGB color space
    1. Linear and regular gamma: technically correct vs "prettier"
    2. It's not easy being linear
    3. If it's not easy, is it worth the hassle?

Editing in linear gamma color spaces

This article compares blurring and normal mode blending of colors in a linear gamma version of the sRGB color space to blurring/blending the same colors using the regular (approximately gamma=2.2) sRGB color space. This article is the first of a planned series of articles on editing in a linear gamma color space. Upcoming articles will examine channel mixing, converting a color image to black and white, applying curves, and using different blend modes.

Above left: Krita brush strokes, linear gamma sRGB color space.

Above right: Krita brush strokes, regular sRGB color space.

Comparing brush strokes in linear gamma and perceptually uniform sRGB color spaces.

Note: please disregard the darker green between the green and blue background in the regular sRGB image; it's there because I added a stroke of darker green to the regular sRGB image, but forgot to add the same stroke to the linear sRGB image.

Even at a glance, the differences between the linear gamma sRGB and regular sRGB images are obvious :

  • There are dark lines around some of the letters in the regular sRGB image.
  • The red and magenta letters in the regular sRGB image on the right are darker than their counterparts done in the linear gamma sRGB image.
  • Compare the crossed "t"s in the word "magenta": In the linear gamma version, the "t" is darker at the intersection of the vertical and horizontal stroke, which is what intuitively one would expect, magenta being perceptually darker than teal. In the regular sRGB version, the "t" is lighter where the vertical and horizontal strokes cross. This is because the second stroke masks the incorrect darkening effect of painting magenta over teal in the regular sRGB color space.

Technically speaking, the linear gamma sRGB image is correct — there should not be dark lines around any of the letters, and painting red or magenta letters over green should lighten rather than darken the letters.

The color block images below systematically explore the phenomenon pictured above. I recommend that you scroll through and look at all the pictures before you read the text.

Blurring and Normal Mode Blending: linear and regular sRGB

The test images below are composed of blocks and bars of six different colors: red, green, blue, yellow, cyan, and magenta. The image color blocks and bars are arranged so that each color is shown juxtaposed next to all the other colors, plus white and and black. There are three sets of the test images, as follows:

Above left: 100% bright, 100% saturated.

Above middle: 75% bright, 75% saturated.

Above right: 50% bright, 50% saturated.

Color block test images.

Right-click to download and save these regular sRGB test images; change precision to 16 bits and use cctiff or tificc (use the "-p" flag with cctiff and the "-c 0" flag with tificc) or a high bit depth image editor to convert to linear gamma sRGB.

Set 1: 100% bright, 100% saturated colors: very noticeable darkening:

100% saturated, 100% bright, 10px gaussian blur.

Above left: linear gamma sRGB, created by giving the original linear gamma sRGB image a 10-pixel gaussian blur.

Above right: regular sRGB, created by giving the original regular sRGB image a 10-pixel gaussian blur. In the regular sRGB image on the right, there are dark lines separating red from green and teal, and blue from red and green; purple lines separate teal from red and magenta; a hint of green separates yellow from teal. These dark lines are artifacts produced by mixing colors in a nonlinear RGB color space.

100% saturated, 100% bright, 40px gaussian blur.

Above left: linear gamma sRGB, created by giving the original linear gamma sRGB image a 40 pixel gaussian blur. If you look closely, you can see darkish yellow separating green from red, which is as expected: in an RGB color space, red+green=yellow. You can also see teal separating green from blue (green+blue=teal), magenta separating red from blue (red+blue=magenta), and orange separating red from yellow (red+yellow=orange). All of these new "colors between the colors", that are produced by blurring in the linear sRGB color space (above left), are exactly what you should get when you mix RGB colors together, because this is how light and color combine out there in the real world (very different from combining pigments on canvas or inks on paper!).

Above right: regular sRGB, created by giving the original regular sRGB image a 40 pixel gaussian blur. All the black, purple, green, and dark blue lines noted in the regular sRGB image in Row 1 above are now broad smudges of dark color, artifacts of blurring in a nonlinear color space. Most image editors fail to compensate for the color space gamma when blurring colors in a non-linear gamma RGB color space.

100% saturated, 100% bright, normal blend mode.

Above left: linear gamma sRGB.

Above right: regular sRGB. The images above were created by offsetting a duplicated layer by 25 pixels and setting the blend mode to Normal, using 50% opacity.

If done in a non-linear-gamma RGB color space, the Normal blend mode produces the same darkening artifacts as blurring. The darkening caused by using the Normal blend mode in the regular sRGB image above on the right is very obvious. In particular, note the dark gray color produced by mixing teal with red, magenta with green, and blue with yellow. These colors in fact should be a light neutral gray, not a dark neutral gray.

Ah ha! you are saying, there is an obvious teal cast to the linear gamma sRGB blend between red and teal! And look at how strong the magenta color cast is in the linear gamma sRGB blend between green and magenta! Actually there does seem to be a rounding error somewhere in the blending and/or color conversion routines — for example, the actual linear-gamma sRGB eye-droppered values of the light gray patch between red and teal are (127,128,128); the light gray between magenta and green eye-droppers as (128,127,128), and the light gray patch between yellow and blue eyedroppers as (127,127,128).

However, the "strong color cast" is an optical illusion. If you zoom in on the blocks as close as your browser will allow you, the apparent strong teal color cast of the light gray block between red and teal will magically disappear, as will the magenta color cast of the light gray patch between magenta and green and the yellow color cast of the light gray patch between blue and yellow.

Speaking of optical illusions — if you see something along the lines of a thin white line between the teal and magenta color blocks — in either color space — or a thin black line between the red and green color blocks, I assumed that these lines are examples of the Mach band optical illusion. However, a very kind reader wrote in and let me know that these bands are actually a "real artifact of the physical subpixel layout of the display" and so will vary from one display to the next. See Subpixel rendering and Subpixel layout for more information.

There is no rounding error in the corresponding regular sRGB 50% Normal Blend gray color patches. In all cases R=G=B=127, which is roughly one and one/third stop too dark. Also note that even the blend between white and the color patches at the top, and the blend between black and the color patches at the bottom, is too dark.

Set 2: Roughly 75% bright, 75% saturated colors: darkening is lessened, but is still obvious

The second set of images below shows that at roughly 75% saturation combined with roughly 75% brightness (as measured by Hue/Saturation/Value sliders), the differences between mixing colors in the linear gamma sRGB color space vs the regular sRGB color space are obvious, but not nearly as obvious as at 100% saturation and brightness:

75% bright, 75% saturated colors, 10px blur.

Above left: linear gamma sRGB, created by giving the linear gamma image in Row 1 above a 10-pixel gaussian blur.

Above right: regular sRGB, created by giving the sRGB image in Row 1 above a 10-pixel gaussian blur. Unlike the technically correct linear sRGB image on the left, in the regular sRGB image on the right dark lines separate the various color blocks. The lines are obvious, but not nearly as dark as with the 100% saturated, 100% bright colors.

75% bright, 75% saturated colors, 40px blur.

Above left: linear gamma sRGB, created by giving the linear gamma image in Row 1 above a 40 pixel gaussian blur.

Above right: regular sRGB, created by giving the sRGB image in Row 1 above a 40 pixel gaussian blur. There are still obvious broad smudges of dark color between the different color blocks, but the smudges of dark colors are less prominent than in the very bright, very saturated colors in the first set of images above.

75% bright, 75% saturated colors, Normal blend mode.

Above left: linear gamma sRGB.

Above right: regular sRGB. The darkening caused by using the Normal blend mode in the regular sRGB color space is still obvious.

Set 3: roughly 50% bright, 50% saturated colors: darkening is visible but not especially noticeable

By the time you reach roughly 50% saturation and 50% brightness (as measured by Hue/Saturation/Value sliders), the differences between using linear gamma sRGB vs regular sRGB are much diminished, though when comparing the results side by side, the regular sRGB results are still noticeably smudgy-looking around the edges.

50% bright, 50% saturated colors, 10px blur.

Above left: linear gamma sRGB, created by giving the linear gamma image in Row 1 above a 10-pixel gaussian blur

.

Above right: regular sRGB, created by giving the sRGB image in Row 1 above a 10-pixel gaussian blur. In the regular sRGB image on the right, the dark lines separating the various color blocks are only really noticeable upon close comparison with the technically correct linear gamma image on the left.

50% bright, 50% saturated colors, 40px blur.

Above left: linear gamma sRGB, created by giving the linear gamma image in Row 1 above a 40 pixel gaussian blur.

Above right: regular sRGB, created by giving the sRGB image in Row 1 above a 40 pixel gaussian blur. There are still broad smudges of dark color between the different color blocks, particularly noticeable between red and green and between teal and magenta. But the smudges of dark colors are far less obvious than in the previous two sets of images.

50% bright, 50% saturated colors, Normal blend mode.

Above left: linear gamma sRGB.

Above right: regular sRGB. Using the Normal blend mode to blend equal parts of these less bright, less saturated colors in the regular sRGB color space on the right still darkens the resulting colors, compared to the same blending in the linear gamma sRGB color space on the left. The most obvious darkening is the color patches that have been blended with black (bottom row of blocks).

Saturation vs brightness: which contributes most to the darkening that results when improperly mixing colors?

In the second and third set of images above, saturation and brightness are decreased together, from one set to the next. So a natural question is, is it saturation or brightness that contributes the most to the differences between editing in the linear gamma sRGB color space, compared to editing in the regular sRGB color space? The next two sets of images suggest that saturation is the main source of the differences. On the one hand, the differences persist all the way down to very dark values if the saturation is kept at 100%. On the other hand, the differences fade quickly as the saturation is lessened.

100% saturation, decreasing brightness.

Above left: linear gamma sRGB.

Above right: regular sRGB. The dark borders caused by blurring in the regular sRGB color space are visible all the way down to very low RGB values.

100% brightness, decreasing saturation.

Above left: linear gamma sRGB.

Above right: regular sRGB. The dark borders caused by blurring in the regular sRGB color space fade quickly as the saturation lessens. Below about 50% saturation the dark borders start to disappear.

In isolation, in test images, saturation contributes more than brightness to banding between colors that have been mixed by blurring or normal blending (I only show blurring above, but the same principles apply for normal blending). However, in practice, in real images, mixing a saturated color with a light-toned pastel color (such as mixing saturated red with light, pale blue) results in very obvious hue shifting, plus darkening of the tonality of the mixed colors. See the photographic images below for examples.

Photographic images

This article started with a comparison of linear gamma and regular sRGB images created in Krita using brush strokes. So I thought I would conclude with a comparison of some photographic images blended in Gimp 2.9 from git (Gimp 2.9 from git supports 16-bit integer and 32-bit floating point image editing; don't try linear gamma image blending with the 8-bit-only Gimp 2.8!):

Flowers, Normal blend mode, 50% opacity:

Sample flower images for comparing Normal blend mode in the linear gamma and regular sRGB color spaces.

Left to right: a bright yellow dandelion, a blurry sprig of purple flowers against a blue sky, and a dark red rose.

The dandelion blended with the blue sky and blurry sprig of purple flowers.
Above left: blended using linear gamma sRGB. Above right: blended using regular sRGB. After blending in the regular sRGB color space, the green from the dandelion image has blended with the purple flowers to produce tones that are too dark and too gray, the spots of blue sky on the left side of the dandelion have lost a great deal of their blueness, and the "blue" sky in the lower right corner of the regular sRGB blend looks bruised rather than blue.

The rose blended with the blue sky and blurry sprig of purple flowers.

Above left: blended using linear gamma sRGB.

Above right: blended using regular sRGB. Compare the spots of blue sky blended with the rose in each image: in the linear sRGB-blended image, the spots of blue sky over the rose retain an impression of blueness, almost like water drops on the rose. In the regular sRGB-blended image, when blended with the dark red rose, the spots of blue sky fail to retain any impression of blueness; also, the rose's red color is darker than it should be and seems to have been pushed too far toward magenta, compared to the original, unblended rose.

Corn dog stand at the State Fair, Normal blend mode, 50% opacity:

Sample non-flower images for comparing Normal blend mode in the linear gamma and regular sRGB color spaces.

Left: corn dogs at the State Fair; Right: the Corn Dog Stand (cropped to avoid showing the vendor's face).

Comparing Normal blend mode results from blending in the linear gamma and regular sRGB color spaces.

Above left: Corn dogs and Stand blended in the linear gamma sRGB color space.

Above right: Corn dogs and Stand blended in the regular sRGB color space. This comparison shows a lot of the problems with using the regular sRGB color space to blend colors:

First, the silver hair of the customer standing at the lower right edge of the picture is still silver in the linear gamma-blended image. But the man's silver hair and also his gray jacket, the styrofoam cups and all the other bright white elements in the original image have acquired a grayish-yellow color cast in the regular sRGB-blended image.

Second, the vendor's shirt has completely changed color in the regular sRGB-blended image, from turquoise to a peculiar shade of green-blue-green. In the linear-gamma sRGB-blended image, all the original colors are still recognizable.

Third, in the linear gamma image on the left, you can see the outline and color of the corn dogs. But in the regular sRGB image on the right, the corn dog color has changed from golden-brown to a darker, grayish brown that is harder to discern against the busy background.

If you are blending images for product advertising, try using a linear gamma color space: the colors and tonality in the blended result will stay truer to the original images.

You might ask, "how hard did I have to look to find photographic images that clearly illustrate the differences between linear and regular sRGB when using normal mode blending, before I found the ones I show on this page?" The answer is "not very". I already knew from the color block test images that the darkening artifacts are more noticeable when mixing saturated colors, and especially when mixing green/teal with red/magenta. Plus I have a folder full of raw files of colorful garden flowers.

So I picked a handful of promising flower image candidates and rendered them with UFRaw (making sure none of the images were clipping highlights in the sRGB color space — the blue sky in the corner of the "blurry sprig" image was clipped in the raw file). And sure enough, the artifacts revealed by the test images were easily seen when blending two flower images together. The State Fair corn dog stand images (which, when blended, mixes medium-dark yellow with bright teal blue) were a lucky hunch and were the only non-flower images that I checked while preparing this article.

Final thoughts on blurring and normal mode blending in a linear gamma RGB color space

Linear and regular gamma: technically correct vs "prettier"

In all comparisons above, the colors in the images on the left, edited in the linear gamma version of the sRGB color space, are technically correct. The colors in the images on the right, edited in the regular sRGB color space are technically wrong because blurring and normal mode blending of colors in an RGB color space with a gamma greater than 1 artificially darkens the resulting colors unless the color space gamma is taken into account "behind the scenes". I don't know of any image editing program that "undoes" the gamma effect before performing blurs and normal mode blends. (Update: this "undoing" of the color space gamma is done automatically in GIMP 2.9 from git. But the "linearizing" of the RGB data only works if the RGB working space has precisely the sRGB TRC, and gives horrendously wrong results if the image really is already in a linear gamma RGB working space. Also, the user has only limited control over whether any given editing operation is done using linearized RGB or perceptually uniform RGB, which is unfortunate because some operations, for example adding and removing noise, work better on perceptually uniform RGB.)

Whether you get "prettier" results when using a gamma=1.0 or a gamma=2.2 RGB color space is an entirely subjective call, and in my opinion, the artist is always right.

It's not easy being linear

If you've never used a linear gamma RGB color space before, think of it as a kind of new tool for image creation and editing. Learning to use a new tool is never easy. If you decide to try linear gamma image editing, be prepared to forget everything you know about using curves, levels, and blend modes. Behind the scenes, these tools are just number crunchers, and the meaning of the numbers being crunched changes radically when you switch from a regular gamma to a linear gamma RGB color space.

A major issue when using a linear gamma working space for image creating and editing is that most image editing programs assume you are editing in a relatively perceptually uniform RGB color space such as regular sRGB:

  • Part of that assumption is reflected in how the imaging program performs ICC profile conversions. ArgyllCMS (all versions), Krita 2.6 and newer, GIMP 2.8 and later, and Cinepaint (if you don't use black point compensation and you do choose "dont Precalculate [sic]" in the color management settings) all use high quality settings when doing ICC profile conversions. But many image editing programs use various optimization routines for profile conversions that end up trashing the shadows of linear gamma ICC profiles, and these optimizations usually assume the RGB data is perceptually uniform.

    Update: As of LCMS version 2.7 (not yet released as of February 2015), matrix to matrix ICC profile conversions will be accurate even in the shadows, because the algorithm has been changed — yeah!

  • Another part of that assumption is that none of the open source imaging programs (at least none that I know of) are set up to allow the user to easily make curves adjustments in a linear gamma RGB color space. The curves interface window is too small (Cinepaint). Or even when editing a 16-bit image, the curves adjustment only works in 8-bit chunks (PhotoShop, at least as of CS2). Or both. Update: GIMP 2.9 does allow to make the Curves interface window very large, and does allow to work in sufficiently small increments as to allow adjusting the shadows in linear gamma images.

A word of caution: you can't use a linear gamma RGB color space for editing an 8-bit image. If you try, you will produce extensive banding in the shadow areas of your image. Indeed, the simple act of converting an 8-bit image to a linear gamma RGB color space is enough to cause banding in the shadows.

If it's not easy being linear, is it worth the hassle?

If it's not easy, is editing in a linear gamma RGB color space worth the hassle? That's a personal decision, of course. But in general, you will get much nicer blurring and blending if you edit in a linear gamma color space.

However, if you never blur or use the normal blend mode in the course of editing a digital photograph, or if you always and only work with low saturation images, or if you work in the ProPhotoRGB color space, avoid adding excessive saturation to your images, and don't mind a little residual hue-shifting and tone-darkening; or if you use paint applications to create digital art and you actually like the dark edges around brush strokes and the general darkening effect and hue alterations that result from using the regular sRGB color space, then nothing on this page should entice you to undertake the hassle of working in a linear gamma RGB color space.

Keep in mind that blurring and normal mode blending is only part of the story: I haven't yet shown you side-by-side comparisons of channel blending, converting to black and white, and applying curves in linear vs regular gamma RGB color spaces.