Alpha Blending

Block Category: Operations

Input Image Format

Input Image Requirements: RGB, and all input images must be the same size

Description: The Alpha Blending block blends two images by overlaying one image – typically the foreground image – with a background image. The alpha input allows you to select a masking area in which the background image is overlaid.

In the alpha blending operation, for every pixel of the output image (O), the foreground image color (F) is combined with the background image color (B) using the alpha mask (α):

O = αF + (1- α)B

      When α = 0, the output pixel color is the background

      When α = 1, the output pixel color is the foreground

      When 0 < α < 1, the output pixel color it is a blend of the foreground and background

Example

In the following example, the close-up picture of a cat (image 2) is overlaid on a video of a cat on a treadmill (image 1).

AlphaBlendingExample

The masking area is predominantly the gold colored wall with a specific pixel value. The Histogram, Back Projection, and Invert blocks are used to create the masking area:

AlphaBlendingExample2

Note that the image size (as highlighted with the red circle) is 368 x 208 pixels. Also note that the image is converted to HSV because this is a format restriction of the Histogram block. The Invert block is used to more easily see the masking area in black.

The close-up image of the cat’s face is the background area that will be applied to the masking area. Note that its size is also 368 x 208.

AlphaBlendingExample3

Finally, all three images (image with masking area (α), close-up cat face (background), and cat on treadmill video (foreground)) are feed into the Alpha Blending block. Before the image with masking area is fed into Alpha Blending, it must be converted back to RGB format:

AlphaBlendingExample4