Reference

This page documents all function available in blend_modes in detail. If this documentation cannot answer your questions, please raise an issue on blend_modes’ GitHub page.

Overview

addition Apply addition blending mode of a layer on an image.
darken_only Apply darken only blending mode of a layer on an image.
difference Apply difference blending mode of a layer on an image.
divide Apply divide blending mode of a layer on an image.
dodge Apply dodge blending mode of a layer on an image.
grain_extract Apply grain extract blending mode of a layer on an image.
grain_merge Apply grain merge blending mode of a layer on an image.
hard_light Apply hard light blending mode of a layer on an image.
lighten_only Apply lighten only blending mode of a layer on an image.
multiply Apply multiply blending mode of a layer on an image.
normal Apply “normal” blending mode of a layer on an image.
overlay Apply overlay blending mode of a layer on an image.
screen Apply screen blending mode of a layer on an image.
soft_light Apply soft light blending mode of a layer on an image.
subtract Apply subtract blending mode of a layer on an image.

Note

All examples on this page are blends of two images: As a bottom layer, there is a rainbow-filled square with some transparent border on the right and bottom edges. The top layer is a small rectangle that is filled with a colorful circular gradient. The top layer is blended upon the bottom layer with 50% transparency in all of the examples below.

Bottom and top layers for blending examples
logo1 logo2

Detailed Documentation

addition(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply addition blending mode of a layer on an image.

Example

_images/addition.png
import cv2, numpy
from blend_modes import addition
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = addition(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

darken_only(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply darken only blending mode of a layer on an image.

Example

_images/darken_only.png
import cv2, numpy
from blend_modes import darken_only
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = darken_only(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

difference(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply difference blending mode of a layer on an image.

Example

_images/difference.png
import cv2, numpy
from blend_modes import difference
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = difference(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

divide(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply divide blending mode of a layer on an image.

Example

_images/divide.png
import cv2, numpy
from blend_modes import divide
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = divide(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

dodge(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply dodge blending mode of a layer on an image.

Example

_images/dodge.png
import cv2, numpy
from blend_modes import dodge
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = dodge(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

grain_extract(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply grain extract blending mode of a layer on an image.

Example

_images/grain_extract.png
import cv2, numpy
from blend_modes import grain_extract
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = grain_extract(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information in the GIMP Documentation.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

grain_merge(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply grain merge blending mode of a layer on an image.

Example

_images/grain_merge.png
import cv2, numpy
from blend_modes import grain_merge
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = grain_merge(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information in the GIMP Documentation.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

hard_light(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply hard light blending mode of a layer on an image.

Example

_images/hard_light.png
import cv2, numpy
from blend_modes import hard_light
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = hard_light(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

lighten_only(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply lighten only blending mode of a layer on an image.

Example

_images/lighten_only.png
import cv2, numpy
from blend_modes import lighten_only
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = lighten_only(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

multiply(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply multiply blending mode of a layer on an image.

Example

_images/multiply.png
import cv2, numpy
from blend_modes import multiply
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = multiply(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

normal(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply “normal” blending mode of a layer on an image.

Example

_images/normal_50p.png
import cv2, numpy
from blend_modes import normal
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = normal(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

overlay(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply overlay blending mode of a layer on an image.

Note

The implementation of this method was changed in version 2.0.0. Previously, it would be identical to the soft light blending mode. Now, it resembles the implementation on Wikipedia. You can still use the soft light blending mode if you are looking for backwards compatibility.

Example

_images/overlay.png
import cv2, numpy
from blend_modes import overlay
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = overlay(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

screen(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply screen blending mode of a layer on an image.

Example

_images/screen.png
import cv2, numpy
from blend_modes import screen
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = screen(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

soft_light(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply soft light blending mode of a layer on an image.

Example

_images/soft_light.png
import cv2, numpy
from blend_modes import soft_light
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = soft_light(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0

subtract(img_in, img_layer, opacity, disable_type_checks: bool = False)

Apply subtract blending mode of a layer on an image.

Example

_images/subtract.png
import cv2, numpy
from blend_modes import subtract
img_in = cv2.imread('./orig.png', -1).astype(float)
img_layer = cv2.imread('./layer.png', -1).astype(float)
img_out = subtract(img_in,img_layer,0.5)
cv2.imshow('window', img_out.astype(numpy.uint8))
cv2.waitKey()

See also

Find more information on Wikipedia.

Parameters:
  • img_in (3-dimensional numpy array of floats (r/g/b/a) in range 0-255.0) – Image to be blended upon
  • img_layer (3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0) – Layer to be blended with image
  • opacity (float) – Desired opacity of layer for blending
  • disable_type_checks (bool) – Whether type checks within the function should be disabled. Disabling the checks may yield a slight performance improvement, but comes at the cost of user experience. If you are certain that you are passing in the right arguments, you may set this argument to ‘True’. Defaults to ‘False’.
Returns:

Blended image

Return type:

3-dimensional numpy array of floats (r/g/b/a) in range 0.0-255.0