torchcam.utils

torchcam.utils.overlay_mask(img: Image, mask: Image, colormap: str = 'jet', alpha: float = 0.7) Image[source]

Overlay a colormapped mask on a background image

>>> from PIL import Image
>>> import matplotlib.pyplot as plt
>>> from torchcam.utils import overlay_mask
>>> img = ...
>>> cam = ...
>>> overlay = overlay_mask(img, cam)
Parameters:
  • img – background image

  • mask – mask to be overlayed in grayscale

  • colormap – colormap to be applied on the mask

  • alpha – transparency of the background image

Returns:

overlayed image

Raises:
  • TypeError – when the arguments have invalid types

  • ValueError – when the alpha argument has an incorrect value