code: def overlay_pixel_saliency(
      image_str: str,
      saliency: np.ndarray,
      cm_name: str,
      clip_fraction: float,
      alpha_mul: float,
      signed: bool,
      pixel_saliency: bool,
  ) -> PILImage.Image:
      """Overlays saliency data on top of the input image."""
  
      # Convert original image to PIL.
      img = convert_image_str_to_pil(image_str)
      img = img.convert(mode="RGBA")
  
      # Normalize saliency values.
      if signed:
          clipped_saliency = clip_signed_saliency(
              saliency, fraction=clip_fraction
          )
          norm_saliency = normalize_signed_saliency(clipped_saliency)
      else:
          saliency = np.abs(saliency)
          clipped_saliency = clip_unsigned_saliency(
              saliency, fraction=clip_fraction
          )
          norm_saliency = normalize_unsigned_saliency(clipped_saliency)
  
      # Map saliency to RGB values.
      cm = plt_cm.get_cmap(cm_name)
      saliency_bytes = cm(norm_saliency)
  
      # Assign alpha values.
      if pixel_saliency:
          if signed:
              alphas = map(
                  lambda e: abs(e - 0.5) * 2, norm_saliency.flatten()
              )
          else:
              alphas = map(lambda e: 1.0 - e, norm_saliency.flatten())
          alphas = np.reshape(
              list(alphas), newshape=norm_saliency.shape
          )
      else:
          alphas = 1.0
  
      alphas *= alpha_mul
      saliency_bytes[:, :, 3] = alphas
  
      # Adjust the original image brightness.
      brightness_enhancer = PILImageEnhance.Brightness(img)
      img = brightness_enhancer.enhance(0.5)
      color_enhancer = PILImageEnhance.Color(img)
      img = color_enhancer.enhance(0.0)
  
      # Overlay original image with the saliency heatmap.
      saliency_bytes = (saliency_bytes * 255).astype(np.uint8)
      saliency_img = PILImage.fromarray(saliency_bytes, mode="RGBA")
      saliency_img = saliency_img.resize(
          size=img.size, resample=PILImage.Resampling.BILINEAR
      )
      heatmap_img = PILImage.alpha_composite(img, saliency_img)
      heatmap_img = heatmap_img.convert(mode="RGB")
      return heatmap_img
  
file_path: lit/lit_nlp/lib/image_utils.py
imports: import base64
  import io
  from typing import Optional
  import matplotlib.cm
  import numpy
  from PIL import Image
  from PIL import ImageEnhance
label_desc: Use image node_id 8 for calling a global function with example usage: overlay_pixel_saliency(image_str, saliency, cm_name, clip_fraction, alpha_mul, signed, pixel_saliency) and returns: heatmap_img