File Exchange

image thumbnail

Image blending functions

version 2.16.1.1 (5.07 MB) by DGM
Image blending with support for 4-D image sequences, influence scaling, and several uncommon modes

9 Downloads

Updated 12 Apr 2020

View License

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 for select modes.

COMPOSITION MODES:
gimp compatibility (default)
translucent
dissolve (6 variants)
src over
src atop
src in
src out
dst over
dst atop
dst in
dst out
xor

BLEND MODES:
==== Light & Contrast ====
softlight (5 variants)
overlay
hard light
linear light
vivid light
easy light
flat light (3 variants)
mean light (2 variants)
super light
pin light
hard mix (3 variants)
scale add
scale mult
contrast

==== Quadratic & Complements ====
glow
heat
reflect
freeze
frect
reeze
helow
gleat

==== Directional Pairs ====
color dodge & burn
linear dodge & burn
soft dodge & burn (3 variants)
easy dodge & burn
gamma dodge & burn
tint & shade
light & shadow
bright & dark
lighteneb & darkeneb

==== Relational ====
lighten RGB
darken RGB
lighten Y
darken Y
saturate
desaturate
near
far
replace color
exclude color

==== Mathematic ====
multiply
screen
divide
addition
subtraction
bleach
stain
difference
phoenix
exclusion
negation
sqrtdiff
compsqrtdiff
average
geometric
harmonic
interpolate
hard int
pnorm
arctan
curves
gammalight
gammadark
grain extract
grain merge

==== Mesh Modes ====
mesh
bomb
bomblocked
hard bomb

==== Modulo Modes ====
mod
mod shift
mod divide
cmod
cmod shift
cmod divide

==== Component ====
hue
saturation
color (5 variants)
value
luma
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 lch
recolor hsly
blurmask
blurmask ring

================== 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.

Archive includes support functions for image conversion and typecasting. IP Toolbox is used for 'recolor' and 'blurmask' modes in IMBLEND, but is otherwise not required.

Documentation with commentary, example code, and input/output images is available here:
http://myplace.frontier.com/~chooks9592/manual/html/imblend.html
This is part of my image manipulation toolbox:
http://www.mathworks.com/matlabcentral/fileexchange/53786-image-manipulation-toolbox

Cite As

DGM (2020). Image blending functions (https://www.mathworks.com/matlabcentral/fileexchange/52513-image-blending-functions), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

Updates

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

2.10.0.0

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

2.9.1.0

bugfix in replacepixels for certain images with NaNs and logical masks

2.9.0.0

update to support functions for image conversion
removed about 3MB of redundant stuff from the archive

2.9.0.0

Noted removal of BLENDMASK in description

2.9.0.0

removed IPT dependency

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

updated description text

2.7.1.0

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

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

2.2.0.0

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

1.10.0.0

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 link to web manual

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.

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

1.4.1.0

removed an unforeseen dependency

1.4.1.0

added other color blend modes

1.4.0.0

added legacy colorhsv mode

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).

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

1.3.0.0

added arbitrary channel transfer mode and made 'permute' code more flexible for possible generalization

1.2.1.0

massaged the description

1.2.1.0

fixed a range-enforcement bug in the quadratic modes

1.2.1.0

fixed a tiny bug with NaN handling in some modes, added 'contrast' blend mode

1.2.0.0

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

1.1.0.0

actually uploaded the correct file

1.1.0.0

tidied up some description and fixed the thumbnail

1.1.0.0

added masking functions

1.0.0.0

clarified description

1.0.0.0

added thumbnail image

1.0.0.0

my kingdom for a post editor that works

1.0.0.0

editing description

1.0.0.0

trying to format description text

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

Inspired by: Colorspace Transformations

blendtools

blendtools/hsiconversions

blendtools/hslconversions

blendtools/hsyconversions

blendtools/huslconversions

blendtools/lchconversions