def overlay_image(foreground_image, mask, background_image):
  """ Overlay foreground image onto the background given a mask
  :param foreground_image: foreground image points
  :param mask: [0-255] values in mask
  :param background_image: background image points
  :returns: image with foreground where mask > 0 overlaid on background image
  """
  blend_ratio = mask / 255
  blend_ratio = blend_ratio.reshape(background_image.shape[0], background_image.shape[1], 1)
  background_image[..., :3] = background_image[..., :3] * (1 - blend_ratio) + foreground_image[..., :3] * blend_ratio
  return background_image