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.
- Introduction: Editing in linear gamma color spaces
- Blurring and Normal Mode Blending: linear gamma and regular sRGB compared
- 100% bright, 100% saturated colors: very noticeable darkening artifacts
- Roughly 75% bright, 75% saturated colors: darkening is lessened, but is still obvious
- Roughly 50% bright, 50% saturated colors: darkening is visible but not especially noticeable
- Saturation vs brightness: which contributes most to the darkening artifacts that result when improperly mixing colors?
- Photographic images
- Final thoughts on blurring and normal mode blending in a linear gamma RGB color space
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.
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:
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.
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:
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.
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.
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 imagesThis 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!):
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
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.
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, 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.