/* * This version of grayscaling is based on a nonuniform * weighting of red,green,blue components known as luminosity. * luminosity = 0.21 R + 0.72 G + 0.07 B. * * This is the formula used by PImage.filter(GRAY) function. */ // Can either load an image stored locally, as follows: // PImage slu = loadImage("campus4.jpg"); // Or can load an image from a URL PImage slu = loadImage("http://business.slu.edu/uploads/2012/11/08/slu-homepage-campus4.jpg"); int w = slu.width; int h = slu.height; for (int x=0; x < w; x++) { for (int y=0; y < h; y++) { color c = slu.get(x,y); float gray = (0.21 * red(c) + 0.72 * green(c) + 0.07 * blue(c)); color replace = color(gray); slu.set(x,y,replace); } } // time to display it size(w,h); image(slu,0,0);