Image blending functions

Version 2.31.0.0 (11.3 MB) by DGM
Image blending and compositing tools from MIMT
1.4K Downloads
Updated 23 Sep 2023
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.
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.
COMPOSITION 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
BLEND MODES:
██ 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 (https://github.com/291ce4321ac/MIMT-blend-tools/releases/tag/v2.31), 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
2.31.0.0

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-blend-tools/releases/tag/v2.31

2.30.0.0

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-blend-tools/releases/tag/v2.30

2.29.1.0

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-blend-tools/releases/tag/v2.29.1

2.29.0.0

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-blend-tools/releases/tag/v2.29

2.28.0.0

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-blend-tools/releases/tag/v2.28

2.27.2

See release notes for this release on GitHub: https://github.com/291ce4321ac/MIMT-blend-tools/releases/tag/v2.27.2

2.27.1

update to some minor support files

2.27

updated replacepixels(), other support files

2.26

minor update to support file noisedither.m

2.25

added linear RGB mode to replacepixels()

2.24

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

2.23.3

updated conversion tools sub-package
no changes to blend tools

2.23.2

added agm/ghm
externalized tf matrix generation

2.23.1.2

ugh

2.23.1.1

friggin description edit

2.23.1

packaging script had omitted a support file

2.23

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

2.22.2

removed remaining IPT dependency

2.22.1

removed some IPT dependency related to pseudoblurmap > imfilter

2.22

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

2.21

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

2.20.1.1

updated description with new docs url

2.20.1.0

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

2.20.0.0

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

2.19.0.0

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

2.18.1.0

added parameterization to flatdodge/burn.
that was quick!

2.18.0.1

synopsis edit as usual

2.18.0.0

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

2.17.0.0

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

2.16.1.1

FEX description typo

2.16.1

forgot to update the dumb FEX description thumbnail

2.16

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

2.15.0.1

edited FEX description

2.15

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

2.14

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

2.13.2

synopsis edit

2.13.1

synopsis edit

2.13.0.1

try again to update screenshot

2.13

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

2.12.1

Typo fixes in synopsis, indentation fixes.

2.12

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

2.11.0.0

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)

2.10.1.0

minor update to supporting files

2.10.0.0

typo
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

2.9.1.0

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

2.9.0.0

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

2.8.0.0

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)

2.7.1.0

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

2.7.0.0

added dissolve mode
updated translucent mode

2.6.0.0

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

2.5.0.0

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

2.4.0.0

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

2.3.0.0

updated thumbnail

2.2.0.0

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

2.1.0.0

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

2.0.0.0

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

1.10.0.0

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

1.9.1.0

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

1.9.0.0

updated HuSL and LCH conversion tools

1.8.0.0

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

1.7.1.0

bugfix in the HSL transfer modes

1.7.0.0

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

1.6.0.0

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

1.5.0.0

added support for HuSL methods; see submission #53423

1.4.3.0

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

1.4.2.0

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

1.4.1.0

updated description
added other color blend modes
removed an unforeseen dependency

1.4.0.0

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

1.3.1.0

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

1.3.0.0

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

1.2.1.0

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

1.2.0.0

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

1.1.0.0

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

1.0.0.0

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.