PixelMath Blending Modes
by Enzo De Bernardini
The following examples show how to perform different blending operations between two images using PixelMath (see original PixInsight forum post). In the examples two images are blended: a vertical gradient (IMG1) and a horizontal gradient (IMG2). In the non-commutative operations indicated below, the operation is applied to IMG2 so IMG2 could be considered on a layer "above" IMG1.
The image IMG1 was created using this PixelMath expression:
max( 0, X() )
A copy was then made and rotated 90° anti-clockwise with FastRotation, and the image IDs were edited (see how to change the ID).
Here are the resulting gradient images:
And here are some blending operations performed with them:
- Darken
min( IMG1, IMG2 )
- Multiply
IMG1 * IMG2
- Color Burn (non-commutative)
~(~IMG1 / IMG2)
- Linear Burn
IMG1 + IMG2 - 1
- Lighten
Max( IMG1, IMG2 )
- Screen
~(~IMG1 * ~IMG2)
- Color Dodge (non-commutative)
IMG1 / ~IMG2
- Overlay (non-commutative)
iif( IMG1 > 0.5, ~(~(2*(IMG1 - 0.5)) * ~IMG2), 2*IMG1*IMG2 )
- Soft Light (non-commutative)
iif( IMG2 > 0.5, ~(~IMG1 * ~(IMG2 - 0.5)), IMG1*(IMG2 + 0.5) )
- Hard Light (non-commutative)
iif( IMG2 > 0.5, ~(~IMG1 * ~(2*(IMG2 - 0.5))), 2*IMG1*IMG2 )
- Hard Mix
iif( IMG1 < 1 - IMG2, 0, 1 )
- Vivid Light (non-commutative)
iif( IMG2 > 0.5, ~(~IMG1/(IMG2 - 0.5)/2), IMG1/~(2*IMG2) )
- Linear Light (non-commutative)
iif( IMG2 > 0.5, IMG1 + 2*(IMG2 - 0.5), IMG1 + 2*IMG2 - 1 )
- Pin Light (non-commutative)
iif( IMG2 > 0.5, Max( IMG1, 2*(IMG2 - 0.5) ), Min( IMG1, 2*IMG2 ) )
- Difference
IMG1 -- IMG2
- Exclusion
0.5 - 2*(IMG1 - 0.5)*(IMG2 - 0.5)
- Subtract
IMG1 - IMG2
PM_BlendingModes.xpsm
PixelMath instance icons collection.