background_composite

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

Image composite with specified background.

Parameters
  • image (ndarray or PIL.Image) – input image

  • fill (int) – fill value for the background, default=255

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

Returns

image with background composite

Return type

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