File Exchange

image thumbnail

Image blending functions

version 2.12.1 (2.47 MB) by DGM

DGM (view profile)

Image blending with support for 4-D image sequences, influence scaling, and several uncommon modes

9 Downloads

Updated 13 Sep 2018

View License

These tools effect image blending and masking functionality common in image manipulation applications such as GIMP. 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 are handled by array expansion.
 1 or 3 channel images are assumed to be monochrome or RGB, respectively
 2 or 4 channel images are assumed to have an added alpha channel
 blending a RGB image and a monochrome image results in an RGB image
 blending a I/RGB image with a IA/RGBA image results in an image with alpha
-- Mismatches of dimension 4 are handled by array expansion.
 both can be single images or 4-D imagesets of equal length
 can also blend a single image with a 4-D imageset

User can optionally specify compositing method independently of the blend method.

Most blend and composition modes are controllable via an AMOUNT parameter. This may internally scale the influence of blends in a manner which cannot be acheived using mixdown opacity, or may control density/thresholding behavior in composition 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 (4 variants)
overlay
hard light
soft linear light
linear light
vivid light
flat light
super light
pin light
hard mix
scale add
scale mult
contrast
curves

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

==== Niche Krita/EB Modes ====
light
shadow
bright
dark
lighteneb
darkeneb
bleach
stain

==== Dodge & Burn ====
color dodge
color burn
linear dodge
linear burn
soft dodge
soft burn
easy dodge
easy burn

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

==== Arithmetic ====
multiply
screen
divide
addition
subtraction
difference
phoenix
exclusion
negation
sqrtdiff
invsqrtdiff
average
geometric
harmonic
interpolate
hard int
pnorm
arctan
gammalight
gammadark
grain extract
grain merge

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

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

================== 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. Extra toolboxes should not be required.

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.

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

Comments and Ratings (1)

Robert Riley

Updates

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

MATLAB Online Live Editor Challenge

View the winning live scripts from faculty and students who participated in the recent challenge.

Learn more

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video