Skip to content

ImageChops

from blanket import ImageChops provides channel arithmetic and blend operations on 8-bit L, RGB, and RGBA images. Arithmetic includes alpha and palette indices where supported. Binary operations use the top-left overlap when image sizes differ.

Group Functions
Arithmetic difference, add, subtract, add_modulo, subtract_modulo, multiply, screen, lighter, darker
Blend modes soft_light, hard_light, overlay
Other invert, offset, constant, duplicate, blend, composite
from blanket import ImageChops

changed_pixels = ImageChops.difference(before, after)

offset wraps pixels around image edges and also preserves high-bit-depth samples. Bilevel logical operations are not implemented.

Reference

difference

difference(image1: Image, image2: Image) -> Image

Return the absolute difference between corresponding channel values.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.difference(image, other)

multiply

multiply(image1: Image, image2: Image) -> Image

Multiply corresponding channel values and divide by 255.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.multiply(image, other)

screen

screen(image1: Image, image2: Image) -> Image

Invert, multiply, and invert again to lighten the inputs.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.screen(image, other)

lighter

lighter(image1: Image, image2: Image) -> Image

Return the larger value in each channel.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.lighter(image, other)

darker

darker(image1: Image, image2: Image) -> Image

Return the smaller value in each channel.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.darker(image, other)

add

add(image1: Image, image2: Image, scale: float = 1.0, offset: int = 0) -> Image

Add channels, divide by scale, add offset, and clip to 0..255.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required
scale float

Divisor applied before the offset; must be nonzero.

1.0
offset int

Value added after scaling.

0

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.add(image, other)

subtract

subtract(image1: Image, image2: Image, scale: float = 1.0, offset: int = 0) -> Image

Subtract channels, divide by scale, add offset, and clip to 0..255.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required
scale float

Divisor applied before the offset; must be nonzero.

1.0
offset int

Value added after scaling.

0

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.subtract(image, other)

add_modulo

add_modulo(image1: Image, image2: Image) -> Image

Add channels with wraparound modulo 256.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.add_modulo(image, other)

subtract_modulo

subtract_modulo(image1: Image, image2: Image) -> Image

Subtract channels with wraparound modulo 256.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.subtract_modulo(image, other)

soft_light

soft_light(image1: Image, image2: Image) -> Image

Combine images using Pillow's soft-light blend.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.soft_light(image, other)

hard_light

hard_light(image1: Image, image2: Image) -> Image

Multiply or screen according to the second image's channel values.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.hard_light(image, other)

overlay

overlay(image1: Image, image2: Image) -> Image

Multiply or screen according to the first image's channel values.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.overlay(image, other)

invert

invert(image: Image) -> Image

Subtract every channel, including alpha, from 255.

Parameters:

Name Type Description Default
image Image

Input image.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
result = ImageChops.invert(image)

offset

offset(image: Image, xoffset: int, yoffset: int | None = None) -> Image

Translate with wraparound; the vertical offset defaults to xoffset.

Parameters:

Name Type Description Default
image Image

Input image.

required
xoffset int

Horizontal translation in pixels; pixels wrap around.

required
yoffset int | None

Vertical translation, or None to use the horizontal offset.

None

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
result = ImageChops.offset(image, xoffset=2, yoffset=1)

constant

constant(image: Image, value: int) -> Image

Return a constant L image with the input's dimensions.

Parameters:

Name Type Description Default
image Image

Input image.

required
value int

Pixel value or channel tuple.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
result = ImageChops.constant(image, value=128)

duplicate

duplicate(image: Image) -> Image

Return an independent copy of an image.

Parameters:

Name Type Description Default
image Image

Input image.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
result = ImageChops.duplicate(image)

blend

blend(image1: Image, image2: Image, alpha: float) -> Image

Interpolate two images with a constant blending factor.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required
alpha float

Blending weight: 0 selects the first image and 1 the second; values outside this range extrapolate.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
result = ImageChops.blend(image, other, alpha=0.5)

composite

composite(image1: Image, image2: Image, mask: Image) -> Image

Select between images using an L or RGBA mask.

Parameters:

Name Type Description Default
image1 Image

First input image; its mode and dimensions must match the second image.

required
image2 Image

Second input image.

required
mask Image

Optional mask selecting pixels. Histogram operations require an L mask; compositing also accepts RGBA alpha.

required

Examples:

from blanket import Image, ImageChops

image = Image.new("RGB", (8, 8), (40, 100, 180))
other = Image.new("RGB", image.size, "white")
mask = Image.new("L", image.size, 128)
result = ImageChops.composite(image, other, mask)