Skip to main content

ImageComposer

ClassSource

ImageComposer()

The image mixing operators extended to the alpha-channel (RGBA) domain.

This composer extends the scope of ImageChops, which only works with non- transparent images (such as L and RGB). Using this extended version, users can stack either RGB or RGBA images, where the stacking algorithm will take the alpha channel into consideration.

Arguments​

No argument is needed.

Methods​

add​

v_1: Image = self.add(image_bg: Image, image_fg: Image)

Equivalent to ImageChops.add.

Adds two images by:

out = clip(image1 + image2, (0, 255))

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

add_modulo​

v_1: Image = self.add_modulo(image_bg: Image, image_fg: Image)

Equivalent to ImageChops.add_modulo.

Add two images, without clipping the result.

out = ((image1 + image2) % MAX)

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

alpha_composite​

v_1: Image = self.alpha_composite(image_bg: Image, image_fg: Image)

Equivalent to Image.alpha_composite.

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

by_name​

v_1: Callable[[Image, Image], Image] = self.by_name(mode: ImageComposerMode)

Fetch the composer method by the mode name.

Requires​

NameTypeRequired
Description
modeImageComposerModeThe name of the composer binary operator.

Returns​

NameType
Description
v_1Callable[[Image, Image], Image]The selected composer operator.

darker​

v_1: Image = self.darker(image_bg: Image, image_fg: Image)

Equivalent to ImageChops.darker.

Compares the two images, pixel by pixel, and returns a new image containing the darker values.

out = min(image1, image2)

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

difference​

v_1: Image = self.difference(image_bg: Image, image_fg: Image)

Equivalent to ImageChops.difference.

Returns the absolute value of the pixel-by-pixel difference between the two images.

out = abs(image1 - image2)

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

hard_light​

v_1: Image = self.hard_light(image_bg: Image, image_fg: Image)

Equivalent to ImageChops.hard_light.

Superimposes two images on top of each other using the Hard Light algorithm.

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

invert​

v_1: Image = self.invert(image: Image)

Equivalent to ImageChops.invert.

Invert an image (channel).

out = MAX - image

Note that this operator will be applied to each channel except the alpha channel if the alpha channel exists.

Requires​

NameTypeRequired
Description
imageImageThe image to be inverted.

Returns​

NameType
Description
v_1ImageThe image with the inverted colors.

invert_luminance​

v_1: Image = self.invert_luminance(image: Image)

Modified ImageChops.invert, where we only invert the luminance of the image, while preserve the color of the image.

If the input image has the transparency channel, it will be preserved.

Requires​

NameTypeRequired
Description
imageImageThe image to be inverted.

Returns​

NameType
Description
v_1ImageThe image with the inverted colors.

lighter​

v_1: Image = self.lighter(image_bg: Image, image_fg: Image)

Equivalent to ImageChops.lighter.

Compares the two images, pixel by pixel, and returns a new image containing the lighter values.

out = max(image1, image2)

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

logical_and​

v_1: Image = self.logical_and(image_bg: Image, image_fg: Image, threshold: int = 128)

Equivalent to ImageChops.logical_and.

Both of the images will be converted to mode "1". If you would like to perform a logical AND on an image with a mode other than "1", try self.multiply instead, using a black-and-white mask as the second image.

out = ((image1 and image2) % MAX)

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.
thresholdintThe threshold used for converting image_bg and image_fg to binary images.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

logical_or​

v_1: Image = self.logical_or(image_bg: Image, image_fg: Image, threshold: int = 128)

Equivalent to ImageChops.logical_or.

Logical OR between two images.

Both of the images will be converted to mode "1".

out = ((image1 or image2) % MAX)

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.
thresholdintThe threshold used for converting image_bg and image_fg to binary images.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

logical_xor​

v_1: Image = self.logical_xor(image_bg: Image, image_fg: Image, threshold: int = 128)

Equivalent to ImageChops.logical_xor.

Logical XOR between two images.

Both of the images will be converted to mode "1".

out = ((bool(image1) != bool(image2)) % MAX)

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.
thresholdintThe threshold used for converting image_bg and image_fg to binary images.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

multiply​

v_1: Image = self.multiply(image_bg: Image, image_fg: Image)

Equivalent to ImageChops.multiply.

Superimposes two images on top of each other.

If you multiply an image with a solid black image, the result is black. If you multiply with a solid white image, the image is unaffected.

out = image1 * image2 / MAX

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

overlay​

v_1: Image = self.overlay(image_bg: Image, image_fg: Image)

Equivalent to ImageChops.overlay.

Superimposes two images on top of each other using the Overlay algorithm.

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

screen​

v_1: Image = self.screen(image_bg: Image, image_fg: Image)

Equivalent to ImageChops.screen.

Superimposes two inverted images on top of each other.

out = MAX - ((MAX - image1) * (MAX - image2) / MAX)

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

soft_light​

v_1: Image = self.soft_light(image_bg: Image, image_fg: Image)

Equivalent to ImageChops.soft_light.

Superimposes two images on top of each other using the Soft Light algorithm.

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

subtract​

v_1: Image = self.subtract(image_bg: Image, image_fg: Image)

Equivalent to ImageChops.subtract.

Subtracts two images.

out = clip(image1 - image2, (0, 255))

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

subtract_modulo​

v_1: Image = self.subtract_modulo(image_bg: Image, image_fg: Image)

Equivalent to ImageChops.subtract_modulo.

Subtract two images, without clipping the result.

out = ((image1 - image2) % MAX)

Requires​

NameTypeRequired
Description
image_bgImageThe background image.
image_fgImageThe foreground image that will lay over image_bg.

Returns​

NameType
Description
v_1ImageThe mixed image. This returned image has the same mode of image_bg.

threshold​

v_1: Image = self.threshold(image: Image, threshold: int = 128)

Given a threshold, use this threshold to convert the image into a binary image.

If the image have multiple channels, will perform the conversion with respect to the luminance channel.

Requires​

NameTypeRequired
Description
imageImageThe image to be inverted.
thresholdintThe threshold used for dividing the image.

Returns​

NameType
Description
v_1ImageThe image mask in the mode "L" or "LA". Note that we do not perform the mode "1" conversion because the alpha channel needs to be preserved if it exists.