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