(foreground, background)
return out
Does alpha compositing of two RGBA images.

  Both inputs must be (..., 4) numpy arrays whose shapes are compatible for
  broadcasting. They are assumed to contain float RGBA values in [0, 1].

  Args:
    foreground: foreground RGBA image.
    background: background RGBA image.

  Returns:
    A numpy array of shape (..., 4) containing the blended image.
Does alpha compositing of two RGBA images.
Does alpha compositing of two RGBA images .
def _alpha_blend(foreground, background):
  """Does alpha compositing of two RGBA images.

  Both inputs must be (..., 4) numpy arrays whose shapes are compatible for
  broadcasting. They are assumed to contain float RGBA values in [0, 1].

  Args:
    foreground: foreground RGBA image.
    background: background RGBA image.

  Returns:
    A numpy array of shape (..., 4) containing the blended image.
  """
  fg, bg = np.broadcast_arrays(foreground, background)
  fg_rgb = fg[..., :3]
  fg_a = fg[..., 3:]
  bg_rgb = bg[..., :3]
  bg_a = bg[..., 3:]
  out = np.empty_like(bg)
  out_a = out[..., 3:]
  out_rgb = out[..., :3]
  # https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending
  out_a[:] = fg_a + bg_a * (1. - fg_a)
  out_rgb[:] = fg_rgb * fg_a + bg_rgb * bg_a * (1. - fg_a)
  # Avoid division by zero if foreground and background are both transparent.
  out_rgb[:] = np.where(out_a, out_rgb / out_a, out_rgb)
  return out
def _alpha_blend ( foreground , background ) : fg , bg = np . broadcast_arrays ( foreground , background ) fg_rgb = fg [ ... , : 3 ] fg_a = fg [ ... , 3 : ] bg_rgb = bg [ ... , : 3 ] bg_a = bg [ ... , 3 : ] out = np . empty_like ( bg ) out_a = out [ ... , 3 : ] out_rgb = out [ ... , : 3 ] # https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending out_a [ : ] = fg_a + bg_a * ( 1. - fg_a ) out_rgb [ : ] = fg_rgb * fg_a + bg_rgb * bg_a * ( 1. - fg_a ) # Avoid division by zero if foreground and background are both transparent. out_rgb [ : ] = np . where ( out_a , out_rgb / out_a , out_rgb ) return out