Image blending functions

Version 2.32 (11.3 MB) by DGM
Image blending and compositing tools from MIMT
Updated 20 May 2024
These tools effect image blending and masking functionality common in image manipulation applications such as GIMP, Krita, or Photoshop. For a layered image composition GUI based on this functionality, see the parent toolbox linked below.
================== BLENDING FUNCTION ==================
IMBLEND() can blend images or imagesets as one would blend layers in GIMP or Photoshop. See 'help imblend'
I assert that if nothing else, IMBLEND() stands as the single most comprehensive collection and demonstration of blend mode math from GIMP, ImageMagick, Photoshop, Krita, and elsewhere.
Inputs are image arrays of same H,V dimension; both can be single images or 4-D imagesets of equal length.
-- Mismatches of dimensions 1:2 are not supported. Use IMRESIZE, IMCROP, or PADARRAY
 to enforce desired colocation of layer content.
-- Mismatches of dimension 3:4 are handled by array expansion.
-- Either image may be replaced with a simple color tuple, with implicit expansion.
User can optionally specify compositing method independently of the blend method.
Unlike other image manipulation software, most blend and composition modes have been made parametric. This useful feature may allow the user to tailor the influence of blends in a manner which cannot be acheived using mixdown opacity, or control density/thresholding behavior in composition modes. See the synopsis for details.
This collection of blend modes is comprehensive; if a mode is not on this list, it is likely equivalent to one of the modes that is. The list of supported mode synonyms is in the synopsis.
Submission thumbnail shows contour plots for the majority of the non-component blend modes. Included in the zip file is a PDF containing this sheet as well as parameter sweeps and documentation of mathematical properties and relationships among modes.
  • gimp compatibility (default)
  • translucent
  • dissolve (8 variants)
  • src over
  • src atop
  • src in
  • src out
  • dst over
  • dst atop
  • dst in
  • dst out
  • xor
██ Bidirectional Modes
==== Contrast & Mixing ====
  • softlight (5 variants)
  • overlay
  • hard light
  • linear light
  • vivid light
  • easy light
  • flat light (3 variants)
  • mean light (2 variants)
  • super light
  • star light
  • moon light (2 variants)
  • pin light
  • hard mix (3 variants)
  • fog lighten
  • fog darken
==== Penumbrae ====
  • penumbra A (3 variants)
  • penumbra B (3 variants)
==== Quadratics ====
  • glow
  • heat
  • reflect
  • freeze
  • frect
  • reeze
  • helow
  • gleat
==== Mean-Scaled ====
  • scale add
  • scale mult
  • contrast
██ Unidirectional Complementary Pairs
==== Dodges & Burns ====
  • color dodge & burn
  • poly dodge & burn
  • linear dodge & burn
  • easy dodge & burn
  • gamma dodge & burn
  • suau dodge & burn
  • maleki dodge & burn
==== Hybrid Glow & Shadow ====
  • flat glow & shadow
  • mean glow & shadow
  • star glow & shadow
  • moon glow & shadow (2 variants)
==== Krita/EB Assortment ====
  • tint & shade
  • lighteneb & darkeneb
██ Relational
  • lighten RGB
  • darken RGB
  • lighten Y
  • darken Y
  • saturate
  • desaturate
  • most sat
  • least sat
  • near
  • far
  • replace
  • preserve
██ Mathematic & Technical
  • multiply
  • screen
  • divide
  • addition
  • subtraction
  • bleach
  • stain
  • difference
  • phoenix
  • exclusion
  • negation
  • sqrtdiff
  • average
  • agm
  • geometric
  • ghm
  • harmonic
  • interpolate
  • hard int
  • pnorm
  • arctan
  • curves
  • gammalight
  • gammadark
  • grain extract
  • grain merge
██ Mesh Modes
  • mesh
  • bomb
  • bomblocked
  • hard bomb
██ Selected Mesh Presets
  • lcd
  • +4 others
██ Modulo Modes
  • mod
  • mod shift
  • mod divide
  • cmod
  • cmod shift
  • cmod divide
██ Component
  • hue
  • saturation
  • color (12 variants)
  • value
  • luma (2 variants)
  • lightness
  • intensity
  • transfer inchan>outchan (directly transfer any channel to another)
  • permute inchan>H (rotate hue)
  • permute inchan>HS (rotate hue and blend saturation)
██ Specialty Modes
  • recolor {colormodel}
  • blurmap {kernel}
================== MASKING FUNCTION ==================
Also included is REPLACEPIXELS() which effects an opacity blending similar to GIMP's 'Layer Mask' functionality. Accepts two input images and a mask. Foreground image may be replaced by a color triplet for convenience. REPLACEPIXELS() supports multichannel and multiframe masks, and can support NaN throughput if mask is logical. REPLACEPIXELS() can optionally perform masking in linear RGB.
Archive includes support functions for image conversion and typecasting. IP Toolbox is not required.
Documentation with commentary, example code, and input/output images is available here:
This is part of my image manipulation toolbox:

Cite As

DGM (2024). Image blending functions (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2015b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

See release notes for this release on GitHub:

See release notes for this release on GitHub:

See release notes for this release on GitHub:

See release notes for this release on GitHub:

See release notes for this release on GitHub:

See release notes for this release on GitHub:


See release notes for this release on GitHub:


update to some minor support files


updated replacepixels(), other support files


minor update to support file noisedither.m


added linear RGB mode to replacepixels()


starting to split code into helper functions for sake of maintenance
added linear rgb options
minor bugfixes, code cleanup with imclamp() and splitalpha()


updated conversion tools sub-package
no changes to blend tools


added agm/ghm
externalized tf matrix generation


friggin description edit


packaging script had omitted a support file


speed improvement by removing LUTs, using fast rgb-linear tools


removed remaining IPT dependency


removed some IPT dependency related to pseudoblurmap > imfilter


generalized mesh blending code for cleanliness
added mesh mode presets
added 'lost_bomb_recovery' tool for recovering lost transfer function matrices


added 'suaudodge' and burn, unidirectional counterparts to 'softlighteb2'

updated description with new docs url

minor synopsis edits: meanlight, saturate/desaturate
sped up pnorm, superlight with fast cases

reclassified/renamed several modes for better organization and clarity:
softdodge/burns, base quadratics, bright/dark, light/shadow
flat/mean dodge/burn are now a unique hybrid category
added 'star' and 'moon hybrids
added most/least sat relationals

a couple minor bug fixes
changed flatdodge/burn, colordodge/burn paramzn
added meandodge/burn, polydodge/burn
improved overlay/hardlight/interpolate LUT interpolators for accuracy
improved info pdf

added parameterization to flatdodge/burn.
that was quick!

synopsis edit as usual

interpolate supports fractional iterations
added flatdodge, flatburn
replaced 'replacecolor' and 'excludecolor' with 'replace/preserve fg/bg' modes with better paramzn
improved paramzn for 'lighten/darken rgb'
minor speed improvement to some modes

added useful table documenting blend mode properties for better understanding of relationships
fixed minor issues in easylight, softmeanlight, farfg/bg
minor speed improvements, parameterization changes for some modes
added blue noise dissolve modes

FEX description typo


forgot to update the dumb FEX description thumbnail


added 'meanlight', 'softmeanlight', 'hardmixib'
changed parameterization of 'softlighteb2', 'hardmixps', 'hardmixkr'
other improvements

edited FEX description


Added documentation and several modes corresponding to recent releases of Krita. Added new 'flatlight' and 'softdodge' variants, as well as 'recolor' and 'blurmask' modes.


added 'softlighteb2', a parametric version of the most correct 'softlight' variant
included parameter sweep of 'softlighteb2' in pdf
included comparison of all softlight modes in pdf


synopsis edit


synopsis edit

try again to update screenshot


added 'soft flatlight', 'easylight'
removed 'soft linearlight' (it technically isn't a 'light' mode without a neutral response)
'bomb' modes now support vector parameters


Typo fixes in synopsis, indentation fixes.


bugfix for 'hardbomb' when verbose
prevent certain modes from producing complex output when fed out-of-range inputs
faster lighteny/darkeny default case
faster 'luma' mode
unrelated bugfix in supporting file stretchlimFB

faster for single-frame images (all modes) (avg 160% faster in R2015b)
faster for certain modes (all images) (280% - 1260% faster in R2015b)
older versions may see less improvement (based on testing in R2009b)

minor update to supporting files

Added Krita/EB/etc modes: softlightps, softlighteb, light, shadow, bright, dark, lighteneb, darkeneb, bleach, stain, sqrtdiff, invsqrtdiff, gammalight, gammadark, arctan, harmonic, bomblocked
Added verbosity & color model control

fixed archive contents
some support files were missing, some duplicated
that's what happens when i don't pay attention
bugfix in replacepixels for certain images with NaNs and logical masks

removed IPT dependency
update to support functions for image conversion
removed about 3MB of redundant stuff from the archive
Noted removal of BLENDMASK in description

better, controllable error messaging
Zhou-Fang and ordered dither dissolve & lindissolve compositions
rewrite of composition control structures for clarity, flexibility, and speed
reduction of overhead (especially in older matlab versions)

fixed a stupid bug in darkenrgb for nonunity parameter
added 'dissolve' as a composition method
updated description text

added dissolve mode
updated translucent mode

added or improved:
curves, lighten/darken rgb/y, scaleadd, scalemult, contrast
a few minor improvements elsewhere
companion GUI now available in the MIMT

added, updated, or parameterized:
replacecolor, excludecolor, softdodge/burn, flatlight, vividlight, linearlight, softlinearlight, superlight
combined scalableoverlay and overlay into a single mode
improved replacepixels
reduced package size

added or improved modes:
saturate, desaturate, pinlight, superlight, pnorm, geometric, scalableoverlay, scalablehardlight, mesh
removed external dependencies
expanded help page

updated thumbnail

Added several modes.
Sped up a few modes; added alpha as a supported channel under 'transfer'
reduced sensitivity of the quadratics to colors near the steep corner.
Prevents accentuation of noise near coincident extrema
Added composite-only blend modes

fixed a conditional which forced RGB mode for 'color dodge'
sped up 'lighteny' and 'darkeny'
made quadratic modes parametric
added complementary quadratic modes
removed useless 'posterize' mode

updated RGB-LCH conversion tools,
added alpha support for both GIMP and SVG methods
sanitized a few input cases (forces expansion if blend mode implies RGB content)
added second softlight mode to match variant in SVG spec
added SRLAB color blend

updated docs links
code cleanup in sRGB-LCH functions for accuracy & extensibility

updated maxchroma() for consistency
does not change anything in imblend()'s use of maxchroma()

updated HuSL and LCH conversion tools

removed useless color blend modes
updated LCH blend operations to use new RGB-LCH conversion function features

bugfix in the HSL transfer modes

added HSYp support
added HSL support to 'transfer' mode
removed obsolete dependency checks from several modes

Added support for expanded HuSL methods.
This offers operation in normalized CIELCHab and CIELCHuv with slight speed increase.
Removed absolute 'color lch' mode. It was mostly useless anyway.
added link to web manual

added support for HuSL methods; see submission #53423

increased 'color lch' speed by 20%, added example image sheet to demonstrate 'color' modes

expanded 'color' blend mode selection and clarified GIMP/Photoshop compatibility

updated description
added other color blend modes
removed an unforeseen dependency

added HSI conversion methods to work around issues with colorspace()
adapted many modes to operate in CIE-LCH instead of HSV to preserve perceived BG brightness when shifting hue or saturation (chroma).
added legacy colorhsv mode

added a few more modes to the 'permute' mode as I needed them

this description editor is unforgivably bad
added arbitrary channel transfer mode and made 'permute' code more flexible for possible generalization

fixed a tiny bug with NaN handling in some modes, added 'contrast' blend mode
massaged the description
fixed a range-enforcement bug in the quadratic modes

added more blend modes to imblend.m and made blendmask.m flexible along dim 3

tidied up some description and fixed the thumbnail
actually uploaded the correct file
added masking functions

clarified description
trying to format description text

editing description
my kingdom for a post editor that works
added thumbnail image

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.