code: def add_header(img, labels, mark_midpoints=True, header_height=20):
      """Adds labels to the image, evenly distributed across the top.
  
      This is primarily useful for showing the names of channels.
  
      Args:
        img: A PIL Image.
        labels: list of strs. Labels for segments to write across the top.
        mark_midpoints: bool. Whether to add a small vertical line marking the
          center of each segment of the image.
        header_height: int. Height of the header in pixels.
  
      Returns:
        A new PIL Image, taller than the original img and annotated.
      """
  
      # Create a taller image to make space for a header at the top.
      new_height = header_height + img.size[1]
      new_width = img.size[0]
  
      if img.mode == "RGB":
          placeholder_size = (new_height, new_width, 3)
      else:
          placeholder_size = (new_height, new_width)
      placeholder = np.ones(placeholder_size, dtype=np.uint8) * 255
  
      # Divide the image width into segments.
      segment_width = img.size[0] / len(labels)
  
      # Calculate midpoints for all segments.
      midpoints = [
          int(segment_width * (i + 0.5)) for i in range(len(labels))
      ]
  
      if mark_midpoints:
          # For each label, add a small line to mark the middle.
          for x_position in midpoints:
              placeholder[
                  header_height - 5 : header_height, x_position
              ] = 0
              # If image has an even width, it will need 2 pixels marked as the middle.
              if segment_width % 2 == 0:
                  placeholder[
                      header_height - 5 : header_height, x_position + 1
                  ] = 0
  
      bigger_img = Image.fromarray(placeholder, mode=img.mode)
      # Place the original image inside the taller placeholder image.
      bigger_img.paste(img, (0, header_height))
  
      # Add a label for each segment.
      draw = ImageDraw.Draw(bigger_img)
      for i in range(len(labels)):
          text = labels[i]
          text_width = draw.textbbox((0, 0), text, anchor="lt")[2]
          # xy refers to the left top corner of the text, so to center the text on
          # the midpoint, subtract half the text width from the midpoint position.
          x_position = int(midpoints[i] - text_width / 2)
          draw.text(xy=(x_position, 0), text=text, fill="black")
      return bigger_img
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import enum
  import math
  from typing import List, NamedTuple, Tuple
  from etils import epath
  from IPython import display
  import numpy
  from PIL import Image
  from PIL import ImageDraw
  from third_party.nucleus.protos import variants_pb2
label_desc: Use image node_id 8 for calling a global function with example usage: add_header(img, labels, mark_midpoints, header_height) and returns: bigger_img