PImage myImage; //define an image object myImage = loadImage("memorial.jpg"); //load it size(myImage.width,myImage.height); //size it to fit the window image(myImage, 0,0); //display the image loadPixels(); //get access to the array of pixels[] for(int index=0;index> 16 & 0xFF; // get red(myPixel) int g = myPixel >> 8 & 0xFF; // get green(myPixel) int b = myPixel & 0xFF; // get blue(myPixel) int av= (g + b) /2; // average only green and blue if(av>128){ //e.g. if av is 00000000 00000000 00000000 11111111 r = av << 16; // Binary: 00000000 11111111 00000000 00000000 g = av << 8; // Binary: 00000000 00000000 11111111 00000000 b = av; // Binary: 00000000 00000000 00000000 11111111 pixels[index] = r | g | b; //compose a color using bitwise OR } } updatePixels(); // see the result save("memorial_altered.jpg"); // save the image as a file