All pastes #1975246 Raw Edit

Anonymous

public text v1 · immutable
#1975246 ·published 2010-10-28 04:09 UTC
rendered paste body
#title: greenScreen.py
#author: Ariel (arielb@bu.edu)
#Description: A program to create a green screen effect by transposing one picture over another.

def greenscreen():
  message1= "Pick a foreground picture..."
  showInformation(message1)
  #pick a foreground (fg) picture file (with green background)
  fg=pickAFile()
  message2= "Now pick a background picture..."
  showInformation(message2)
  #pick a background (bg) picture file 
  bg=pickAFile()
  #make a picture out of the fg
  picfg=makePicture(fg)
  #make a picture out of the bg
  picbg=makePicture(bg)
  #show the before pictures
  show(picfg)
  show(picbg)
  #for each pixel in the fg image:
  for pixel in getPixels(picfg):
    #    get the red value
    valueR= getRed(pixel)
    #    get the green value
    valueG=  getGreen(pixel)
    #    get the blue value
    valueB= getBlue(pixel)
    #    if the red plus blue is less than green 
    if (valueR + valueB) < (valueG*5/4):
      #        get the pixel color from the bg image at the same location
      Xfg= getX(pixel)
      Yfg= getY(pixel)
      pixelfg= getPixel(picfg, Xfg, Yfg)
      pixelbg= getPixel(picbg, Xfg, Yfg)
      newPixel= getColor(pixelbg)
      #        set the fg pixel color to be the color obtained from the bg image
      setColor(pixelfg, newPixel)
  #show the resulting picture (repaint)
  repaint(picfg)
  #write the new picture to a file
  writePictureTo(picfg, "D:\CS101\greenScreened.jpg")