Section

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:

PixelMath BlendPixelMath Blend

And here are some blending operations performed with them:

  • Darken
    min( IMG1, IMG2 )
    Darken
  • Multiply
    IMG1 * IMG2
    Multiply
  • Color Burn (non-commutative)
    ~(~IMG1 / IMG2)
    Color Burn
  • Linear Burn
    IMG1 + IMG2 - 1
    Linear Burn
  • Lighten
    Max( IMG1, IMG2 )
    Lighten
  • Screen
    ~(~IMG1 * ~IMG2)
    Screen
  • Color Dodge (non-commutative)
    IMG1 / ~IMG2
    Color Dodge
  • Overlay (non-commutative)
    iif( IMG1 > 0.5, ~(~(2*(IMG1 - 0.5)) * ~IMG2), 2*IMG1*IMG2 )
    Overlay
  • Soft Light (non-commutative)
    iif( IMG2 > 0.5, ~(~IMG1 * ~(IMG2 - 0.5)), IMG1*(IMG2 + 0.5) )
    Soft Light
  • Hard Light (non-commutative)
    iif( IMG2 > 0.5, ~(~IMG1 * ~(2*(IMG2 - 0.5))), 2*IMG1*IMG2 )
    Hards Light
  • Hard Mix
    iif( IMG1 < 1 - IMG2, 0, 1 )
    Hards Mix
  • Vivid Light (non-commutative)
    iif( IMG2 > 0.5, ~(~IMG1/(IMG2 - 0.5)/2), IMG1/~(2*IMG2) )
    Vivid Light
  • Linear Light (non-commutative)
    iif( IMG2 > 0.5, IMG1 + 2*(IMG2 - 0.5), IMG1 + 2*IMG2 - 1 )
    Linear Light
  • Pin Light (non-commutative)
    iif( IMG2 > 0.5, Max( IMG1, 2*(IMG2 - 0.5) ), Min( IMG1, 2*IMG2 ) )
    Pin Light
  • Difference
    IMG1 -- IMG2
    Difference
  • Exclusion
    0.5 - 2*(IMG1 - 0.5)*(IMG2 - 0.5)
    Exclusion
  • Subtract
    IMG1 - IMG2
    Subtract

PM_BlendingModes.xpsm
PixelMath instance icons collection.

Last Update: 27/11/2023 03:36 UT