

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Lab; Professor: Summers; Class: Data Structures; Subject: Computer Science; University: Columbus State University; Term: Unknown 2007;
Typology: Lab Reports
1 / 3
This page cannot be seen from the preview
Don't miss anything!
Topics To replace a range of colors with one color in a picture: posterizing. To average nearby pixels: blur To combine Boolean expressions with and and or.
Type in the following code in the Program window (changing the comments): import java.awt.Color; /* Program that transforms pictures using loops and conditionals
for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { // get the current pixel and color values pix = sourcePic.getPixel(x,y); // if the distance from white or black is less than passed amount // use the replacement color if (pix.colorDistance(Color.white) < amount || pix.colorDistance(Color.black) < amount) pix.setColor(replacementColor); } } } ii) Type in the following code in the Program window in the main method and before the pic.show(); highlightLightAndDark(sourcePicture, 50.0, Color.yellow); iii) Test your program with different pictures, values for the distance and colors (e.g. butterfly1.jpg, 50, yellow).
6. 5 Combining Pixels: Blurring iv) Type in the following code in the Program window below the main method and before the last }: /** * Method to blur the pixels of the picture * @param pict - picture Object to be modified * @param numPixels - number of pixels to average in all directions */ public static void blur(Picture sourcePic, int numPixels) { Pixel pix = null; Pixel samplePix = null; int width = sourcePic.getWidth(); int height = sourcePic.getHeight(); int redValue = 0; int greenValue = 0; int blueValue = 0; int count = 0; // loop through the pixels for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { // get the current pixel and color values pix = sourcePic.getPixel(x,y); // reset the count and red, green, and blue values count = 0; redValue = greenValue = blueValue = 0; // loop through pixel numPixels before x and after x and sum values of colors