

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 do simple edge detection. To replace several colors in a picture: sepia-toned. To use a conditional with two possible results if and else.
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 height = sourcePic.getHeight(); // loop through the y values from 0 to (height-1) since we compare to pixel below for (int y = 0; y < (height-1); y++) { // loop through the x values from 0 to width for (int x = 0; x < width; x++) { // get the top and bottom pixels topPixel = sourcePic.getPixel(x,y); bottomPixel = sourcePic.getPixel(x,y+1); // compute the color averages for the two pixels topAverage = topPixel.getAverage(); bottomAverage = bottomPixel.getAverage(); // check if absolute value of the difference is less than distance if (Math.abs(topAverage - bottomAverage) < distance) topPixel.setColor(Color.WHITE); else topPixel.setColor(Color.BLACK); } //end inner loop } //end outer loop } ii) Type in the following code in the Program window in the main method and before the pic.show(); edgeDetection (sourcePicture, 10); iii) Test your program with different pictures and values for the distance (e.g. butterfly1.jpg, 10). EXTRA (if there is time)
6. 3 Sepia-tinted and Posterized Pictures: Using Multiple Conditionals to Choose a Color iv) Type in the following code in the Program window below the main method and before the last }: /** * Method to convert sourcePic to a sepia tint (modify the middle colors to a light brown * and the light colors to a light yellow and make the shadows darker * @param sourcePic - picture Object to be modified */ public static void sepiaTint(Picture sourcePic) { Pixel pixelObj = null; double redValue = 0; double greenValue = 0; double blueValue = 0; int width = sourcePic.getWidth(); int height = sourcePic.getHeight(); // first change the current picture to grayscale grayscale(sourcePic);