Midterm exam 1 review Fall2006: Posterize
Back to Midterm Exam 1 Review Fall2006
Questions? Answers? Comments?
//If red is greater than 128, make it 255
//If red is less than or equal to 128, make it 5
// If blue is less than or equal to 250, make it 200
// If blue is greater than 250, make it 201
// If green is less than 10, make it 200.
// If green is greater than 200, make it 10. Leave other values of green alone
public void newPosterize()
{
Pixel pixel = null;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
// loop through the pixels
for (int x = 0; x < this.getWidth(); x++) {
for (int y = 0; y < this.getHeight(); y++) {
// get the current pixel and colors
pixel = this.getPixel(x,y);
redValue = pixel.getRed();
greenValue = pixel.getGreen();
blueValue = pixel.getBlue();
if (redValue > 128)
redValue = 255;
else if (redValue <= 128)
redValue = 5;
// check for green range
if (greenValue > 200)
greenValue = 10;
else if (greenValue < 10)
greenValue = 200;
// check for blue range
if (blueValue > 250)
blueValue = 255; //- Why are we assigning 255 here? it may be wrong (REMOVEDel)
else if (blueValue <= 250)
blueValue = 200;
// set the colors
pixel.setRed(redValue);
pixel.setGreen(greenValue);
pixel.setBlue(blueValue);
}
}
}
// oorrection for the blue part, check for blue range
if (blueValue > 250)
blueValue = 201;
else if (blueValue = 250)
blueValue = 200;
//chris
Link to this Page