background_composite¶

background_composite(image, fill=255, *, alpha)[source]¶

Image composite with specified background.

Parameters:
  • image (ndarray or Image) – Input image.

  • fill (int) – Fill value for the background, defaults to 255.

  • alpha (bool) – True if alpha channel is required.

Returns:

Image with background composite.

Return type:

numpy.ndarray

Examples

>>> from tiatoolbox.utils import transforms
>>> import numpy as np
>>> from matplotlib import pyplot as plt
>>> img_with_alpha = np.zeros((2000, 2000, 4)).astype('uint8')
>>> img_with_alpha[:1000, :, 3] = 255 # edit alpha channel
>>> img_back_composite = transforms.background_composite(
...     img_with_alpha
... )
>>> plt.imshow(img_with_alpha)
>>> plt.imshow(img_back_composite)
>>> plt.show()