Specifications

Image Arithmetic and Logical Operations
5-17
5
Using the opacity channel for image compositing provides the capability of
overlaying the arbitrarily shaped and transparent images in arbitrary
positions. It also reduces aliasing effects along the edges of the combined
regions by allowing some of the bottom image’s color to show through.
Let us consider the example of RGBA images. Here each pixel is a
quadruple (r, g, b, α) where r, g, b, and α are the red, green, blue and alpha
channels, respectively. In the formulas that follow, the Greek letter α with
subscripts always denotes the normalized (scaled) alpha value in the range
0 to 1. It is related to the integer alpha value
aphaValue
as follows:
[[[[[[[[[[ α =
aphaValue
/
max_val
where
max_val
is 255 for 8-bit or 65535 for 16-bit unsigned pixel data.
There are many ways of combining images using alpha values. In all
compositing operations a resultant pixel (r
C
,g
C
,b
C
, [α
C
) in image C is
created by overlaying a pixel (r
A
,g
A
,b
A
, α
A
) from the foreground image A
over a pixel (r
B
,g
B
,b
B
, α
B
) from the background image B. The resulting
pixel values for an OVER operation (A OVER B) are computed as shown
below.
r
C
= α
A
*r
A
+(1- α
A
)*α
B
*r
B
g
C
= α
A
*g
A
+(1- α
A
)*α
B
*g
B
b
C
= α
A
*b
A
+(1- α
A
)*α
B
*b
B
The above three expressions can be condensed into one as follows:
C=α
A
*A+(1- α
A
)*α
B
*B
In this example, the color of the background image B influences the color
of the resultant image through the second term (1 - α
A
)*α
B
*B.The
resulting alpha value is computed as
α
C
= α
A
+(1- α
A
)*α
B