CS 248: Introduction to Computer Graphics

Pat Hanrahan

Grader: Maneesh Agrawala

2. One of the most important imaging operations used in computer graphics is compositing. Compositing operators allow multiple elements to be combined into a single composite image.

2A. (5 points) Suppose each pixel in a foreground image has color Cf = (Rf,Gf,Bf) and alpha Af, and each pixel in the background image has color Cb = (Rb,Gb,Bb) and alpha Ab. Alpha represents the percentage of each pixel covered by the image. Assume that alpha has not been premultiplied into the color. Write and expression for C = Cf OVER Cb:

C = AfCf + (1-Af)AbCb
Note: It was also acceptable to divide out the composite alpha from C.


5 points for a correct answer.
3 if second term not multiplied by Ab
0 for completely wrong expression.

2B. (15 points) In class we described a method called blue-screening that makes it possible to separate a foreground from a blue background. This procedure is actually fairly tricky and involves heuristics, because the number of unknowns (Rf,Gf,Bf,Af) is greater than the number of knowns (R,G,B).

Suppose however, that you take two pictures, each of the same foreground, but overlayed different backgrounds. Suppose the 1st picture results in a pixel color C1 = (R1,G1,B1) and was over a background color (Rb1,Gb1,Bb1), and the 2nd picture results in a pixel color C2 = (R2,G2,B2) and was over the background color (Rb2,Gb2,Bb2). Since the background is opaque, the alpha is equal to 1. Can you compute the foreground color and alpha (Rf,Gf,Bf,Af) from this information?


C1 = Cf OVER Cb1
C2 = Cf OVER Cb2

C1 = AfCf + (1-Af)Cb1 (1)
C2 = AfCf + (1-Af)Cb2 (2)

Now we subtract (1) - (2) to get
C1-C2 = (1-Af)Cb1 - (1-Af)Cb2
1-Af = (C1-C2)/(Cb1-Cb2)

Af = (C2-C1)/(Cb1-Cb2) + 1

Now we can solve for Cf. Rearraging equation 1 we get
Cf = (C1 - (1-Af)Cb1)/Af
Plugging the value of Af we solved for earlier we can determine the value of Cf.


15 points for anwers similar to the one given above.
12 points if the initial OVER equations (from part A) were wrong but hte methodology was correct.
10 points if the methodology was described but little or no algebra was performed.
5 for answering Yes with no mathematical explanation or an incorrect explanation.
0 points for a wrong answer.

Copyright © 1997 Pat Hanrahan