

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Topics To replace the background in a picture: chromakey.
Type in the following code in the Program window (changing the comments): import java.awt.Color; /* Program that transforms pictures using loops and conditionals
int width = sourcePic.getWidth(); int height = sourcePic.getHeight(); // loop through the pixels for (Pixel currPixel : pixelArray) { if (currPixel.getRed() + currPixel.getBlue() < currPixel.getGreen()) { newPixel = newBg.getPixel(currPixel.getX(), currPixel.getY()); currPixel.setColor(newPixel.getColor()); } //endif } //end for-each } ii) Type in the following code in the Program window in the main method and before the pic.show(); chromakeyGreen(sourcePicture, backgroundPicture) iii) Test your program with different pictures and backgrounds. iv) You may have noticed some residual splotches of green on your chromakeyed picture. If you use explorer(), you will see that there are lots of RGB values on the green background and that sometimes R+B is not greater than G even though the background appears green. Try multiplying both R and B with different percentages to get a “cleaner” picture.