from cImage import * # possible improvements: # foreground image could be a different size # foreground image could be positioned arbitrarily # screen color could be set flexibly def composite(foreground, background): w=background.getWidth() h=background.getHeight() image = EmptyImage(w,h) for row in range(h): for col in range(w): pixel = foreground.getPixel(col, row) if isGreen(pixel): image.setPixel(col,row,background.getPixel(col,row)) else: image.setPixel(col,row,pixel) return image def isGreen(pixel): '''returns True if the pixel is green''' return pixel.getGreen() - pixel.getRed() - pixel.getBlue() > 200 def show(image): win = ImageWin('Image', image.getWidth(), image.getHeight()) image.draw(win) win.exitOnClick()