Photoshop Blend Modes - Part 1

I tried to figure out the frequency separation method for retouching portraits. Initially I didn’t really understand why which step was used. So I first had to dig deeper into the Photoshop (PS) blend modes. There’s a lot you can find on the internet regarding blend modes. Not everything I found was correct, let alone understandable for me. Especially photographers and PS users approach the subject rather intuitively, not many try to understand the math behind the tools they apply. Though that would help perdicting the effects that can be achieved.

So I decided to find out what exactly happens with the goal to write a concise, but not too complicated explanation myself. The first surprise during my research was that not everybody (not even the graphic software vendors) understands the same when they talk about soft light for example. Adobe is undisputedly one of the leaders on the market, but in PS in particular some of the blend modes are implemented not really well (my humble opinion of course).

The Task

Calculate a new image from two existing.

This is always used when you place two layers above each other in PS. The simplest, but also most boring blend mode is making the upper layer opaque so you see nothing of the lower layer. You can use other blend modes to manipulate colours ans luminosity of the lower source by the upper source (yes, in some cases the order is important, like with an opaque layer). That is what photographers use blend modes for.

Assumptions, Simplifications and Definitions

Assumption: the the value for a particular pixel of the new image (the target) can be deduced from the values of the corresponding pixels (same positioin, i. e. same coordinates) of the two source images.

Simplification: all I show I only show for luminosity or rather black and white images with just one channel. The same holds for RGB images with three separate channels, on just uses the same formulas thrice, they are not influencing each other. Transparency (alpha-channel) shall be ignored for now as well.

I will call the source images A and B, das target image C. If you are thinking layers, think A the lower layer, B the upper. C is what PS displays on the screen.
I shall use a common orthogonal coordinate system defined by counting pixel columns and rows from the lower left corner. The location of any pixel is precisely defined by its coordinates (x, y).

Let a(x,y) be the value (luminosity) of a pixel of image A, b(x,y) the value for a pixel of B with the same coordinates. As a result of a calculation you get a pixel-value of C: c(x,y) = f(a(x,y),b(x,y)).

For better readability I will leave out the coordinates, at least as long as no pixels with differring coordinates are involved in the calculatation.

Pixel-values will always be given in numbers between 0 (zero) for black and 1 (one) for white, regardless of the actual bit depth. When calculating c(x,y), you have to keep in mind that its value also is restricted to this interval.

a,b,c \in [0,1]

You will immediately see a difficulty: there are plenty of ways to combine 0 and 1 by a formula that gives values outside this interval. PS solves this problem by truncating the exceeding values. Anything below 0 or above 1 is ignored. That has some nasty consequences whenever you try to do several calculation steps in sequence. Part of the information is lost. You can not calculate \frac{a+b}{2} in PS by executing a+b and \frac{1}{2} this, though it seems mathematically correct to do so.

Visualisation

To visualise the results I use two images as a basis for all blends. These contain values linear from 0 to 1, once from left to right (a(x,y) = x, defines a horizontal axis for a from 0 to 1), once from bottom to top (b(x,y) = y, the vertical axis from 0 to 1). This makes sure the result contains all possible combinations and we will see how smooth transitions are.

Gradient-horizontal
Image A
Gradient-Vertikal
Image B

Blend Modes

To begin with I’ll have a look at some simple, but not trivial methods, multiplication and addition, then a combination of both and finally a version that uses two different formulas depending on the pixel-values of B. Further blend modes I will explain in the next part of this series.

Multiply

Multiplication is one of the simplest blends, because the function does not give any values outside the allowed interval or 0 to 1. By the way, PS indeed uses multiplication, not the geometric mean, though the latter might seem more plausible.

f(a,b) = a \cdot b

Results for a and b between 0 and 1 lie within that interval as well.

For my test images you get:

f(x,y) = a(x,y) \cdot b(x,y) = x \cdot y

Looking at the result you can see that two edges and hence three of the corners should be black, because a multiplication with 0 always yields 0. Only in the top right corner you get a value of 1 for white.

Multiply
Multipy

Aside: Geometric Mean (not available in Photoshop)

For me the geometric mean

f(a,b) = \sqrt{a \cdot b}

seems to be the better option. There’d be a nice linear transition along the diagonal.

Linear Dodge

Linear Dodge is the name given to the addition. It is immediately clear that an addition of two numbers between 0 and 1 yealds results between 0 and 2. For half of the pixels the results get truncated to 1. Used on photos, this can easily lead to burnt out areas.

f(a,b) = a + b

If the sum a+b gets larger then 1, it is replaced by 1. The formula never gives results below 0 anyway, so no truncating there. Hence you’d expect white on and above the diagonal between top left and bottom right, below that a linear gradient down to black in the bottom left corner.

Linear Abwedeln
Linear Dodge

Linear Burn

This is the negative inverse of linear dodge. It is the same as problematic on photos, you might get fully black areas.

f(a,b) = a + b - 1

If the sum a+b gets less then 1, f is replaced by 0. Values above 1 are never reached anyway, no truncating. Hence you’d expect black on and below the diagonal between top left and bottom right, above that a linear gradient up to white in the top right corner.

Linear-Burn
Linear Burn

Linear Light

Frequently you will find linear light described as a combination of linear dodge for b<0.5 and linear burn for b \geq 0.5. Not quite right, but close. If for b \geq 0.5 you compress the formula for linear dodge on the b-axis by a factor 2 and shift it up that axis by 1/2, and then also compress the one for linear burn for b \geq 0.5 by a factor 2 on the b-axis, you indeed get:

f(a,b) = \left\{\begin{array}{lr} a+2b-1 & \text{for } b < {1/2}\\ a + 2(b -1/2) & \text{for } b \geq {1/2} \end{array} \right.

Or, by resolving the terms, simply:

f(a,b) = a + 2b - 1

This is no longer commutative in a and b. Swapping the images A and B will yield a different resulting C.

Along the left edge (a=0) you expect black from the bottom up to b=0.5, then a linear transition to white. On the bottom edge (b=0) just black, because the -1 makes sure all possible results are negative. For b= 1 you get white on the top edge. On the right edge (a=1) you get from b=0 to b=0.5 a linear transition from black to white, above that just white.

Linear-Light
Lineares Licht

Of interest for the PS user is the fact that an image B with b=0.5 for all pixels transfers image A unchanged to C when combined with this blend mode. b=0.5 is 50 % grey, which is called the neutral colour for linear light. Linear light is often used to manipulate a photo by using an almost grey layer with only minimal deviations, for example in high-pass sharpening or as one step of the frequency separation method.

Linear light can be described as the sequential execution of linear dodge and linear burn (with B multiplied by 2) or as linear burn with doubled B. The latter unfortunately cannot be recreated in PS, as it would need multiple steps, one of them yielding results outside the allowed interval. Intermediate results would be truncated, the main result would be wrong.

f(a,b)= (a+b) + b - 1 = a + 2b - 1

Sources