void setup() {
size(512, 512); background(0); PImage img = loadImage("Lenna.png"); imageMode(CENTER); image(img, width/2, height/2); println("Width = " + img.width + ", Height = " + img.height);
// Print the RGB values of pixel[0] loadPixels(); color darkBlue = color(0, 51, 76); color lightBlue = color(112, 150, 158); color red = color(217, 26, 33); color yellow = color(252, 227, 166);
for (int i = 0; i < pixels.length; i++) { // get and change the value of each pixel color pixelValue = pixels[i]; float r = red(pixelValue); float g = green(pixelValue); float b = blue(pixelValue); float total = r + g + b;
if (total < 182) { pixels[i] = darkBlue; } else if (total < 182*2) { pixels[i] = lightBlue; } else if (total < 182*3) { pixels[i] = yellow; } else { pixels[i] = red; } } updatePixels(); color c = pixels[0]; println("R = " + red(c) + ", G = " + green(c) + ", B = " + blue(c)); } // setup()