peal.global_utils.high_contrast_heatmap

peal.global_utils.high_contrast_heatmap(x, counterfactual)[source]

Colour-code the change from an image to its counterfactual.

The difference is split into an intensity part, shown in red where the image got brighter and in blue where it got darker, and a colour part, the deviation of the per-channel change from the mean change, shown in green and boosted by 1.3 because colour shifts read weaker. The result is max-pooled with a 3x3 window so that connected regions stay visible and normalised to its maximum. Greyscale inputs only produce the red/blue intensity part and are tiled to three channels.

Parameters:
  • x (torch.Tensor) – A single image each, shape (C, H, W) with C 1 or 3.

  • counterfactual (torch.Tensor) – A single image each, shape (C, H, W) with C 1 or 3.

Returns:

  • heatmap_high_contrast (torch.Tensor) – RGB heatmap of shape (3, H, W) in [0, 1].

  • x_in (torch.Tensor) – The original, tiled to three channels.

  • counterfactual_rgb (torch.Tensor) – The counterfactual, tiled to three channels.