/** * Chromakey - Blue screen background/forground separation * * * @author Pat Troy: troy AT uic DOT edu */ import java.util.*; import java.awt.*; public class Lect1102a { public static void main(String[] args) { // get the foreground picture String fileName = FileChooser.pickAFile(); Picture pict = new Picture (fileName); // get the new background picture fileName = FileChooser.pickAFile(); Picture pict2 = new Picture (fileName); // call a method to do the background/foreground separation Picture pictNew; pictNew = chromakey (pict, pict2); pictNew.show(); } public static Picture chromakey (Picture p, Picture p2) { // set up the "background color" Color background = new Color (12, 48, 68); Pixel pix, pixNew; int red, green, blue, grayAmount; // set up two loops; one nested inside the other int xIndex, yIndex; for ( xIndex = 0 ; xIndex < p.getWidth() ; xIndex++ ) { for ( yIndex = 0 ; yIndex < p.getHeight() ; yIndex++ ) { // Access the pixel from the orignal image pix = p.getPixel (xIndex, yIndex); // check to see if the pixel's color is not close to the background color if ( pix.colorDistance (background) > 45.0 ) { //Access the pixl from the new background pixNew = p2.getPixel (xIndex, yIndex); // access the 3 color intensities red = pix.getRed(); green = pix.getGreen(); blue = pix.getBlue(); // set the 3 color values in the new pixel pixNew.setRed (red); pixNew.setGreen (green); pixNew.setBlue (blue); } } } return ( p2 ); } }