Chromakey - Georgia Institute of Technology

advertisement
Chromakey
Barb Ericson
Georgia Institute of Technology
Oct 2010
Chromakey
Chroma Key – Blue Screen
• For TV and movie special
effects they use a blue or
green screen
– Here just a blue sheet was
used
– Professionally you need an
evenly lit, bright, pure blue
background
• With nothing blue in the
scene
Chromakey
Chromakey Function
def chromakey(source ,bg):
# source should have something in front of blue
# bg is the new background
for x in range(0, getWidth(source )):
for y in range(0, getHeight(source )):
p = getPixel(source ,x,y)
# if red + green < blue
if (getRed(p) + getGreen(p) < getBlue(p)):
setColor(p,getColor(getPixel(bg ,x,y)))
return source
Chromakey
Testing chromakey
markP = makePicture(getMediaPath("blue-mark.jpg"))
newBack =
makePicture(getMediaPath("moon-surface.jpg"))
chromakey(markP,newBack)
explore(markP)
Chromakey
Chromakey with a Greenscreen
• Many movies use a green screen background
for special effects
• They use a program to replace the green
background with a different background
• We can do the same thing!
Chromakey
Chromakey Green
def chromakeyGreen(source ,bg):
# source should have something in front of a green background
# bg is the new background
for x in range(0, getWidth(source )):
for y in range(0, getHeight(source )):
p = getPixel(source ,x,y)
# if green replace with new background
if getGreen(p) > getBlue(p) + 10 and getGreen(p) > getRed(p) + 10:
setColor(p,getColor(getPixel(bg ,x,y)))
return source
Chromakey
Testing Chromakey Green
jFile = getMediaPath("jenny2-green-small.jpg")
jPict = makePicture(jFile)
explore(jPict)
bFile = getMediaPath("moon-surface.jpg")
newBack = makePicture(bFile)
chromakeyGreen(jPict,newBack)
explore(jPict)
Chromakey
Challenge
• Try copying just the non green pixels from the
source picture (with the green background) to
the new background
– You can even specify where to start the copy at in the
new background (initial x and y location)
Chromakey
Download