English Español Français

Blending Modes with PixelMath

by Enzo De Bernardini

The following list of examples shows how to recreate different blending modes between two images using PixelMath (see original PixInsight forum post). In the examples were used as test images two grayscale gradients from black to white, vertical (IMG1) and a horizontal (IMG2), so that in terms of "layers" the blending mode is applied to IMG2 which would be "above" IMG1. This detail is important for non-commutative expressions (detailed in brackets).

The gradients were created PixelMath, and one of them rotated 90 ° anti-clockwise with FastRotation. Then the corresponding IDs were edited (see how to change the ID).

PixelMath expression (RGB/K) gradient generation:

max( 0,  X() )

Used gradients:

PixelMath BlendPixelMath Blend

  • 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
  • Substract
    IMG1 - IMG2
    Subtract

PM_BlendingModes.xpsm
PixelMath instance icons collection.

Last Update: 07/09/2014 01:05 UT

English Español Français