PImage img = loadImage("robotmarko-g-low-contrast.jpg"); float rmin = 255, rmax = 0; size(600, 400); loadPixels(); img.loadPixels(); for (int y = 0; y < img.height; y++) for (int x = 0; x < img.width; x++) { int imgIndex = x + y * img.width; float r = brightness(img.pixels[imgIndex]); if (rmin > r) rmin = r; if (rmax < r) rmax = r; } for (int y = 0; y < img.height; y++) for (int x = 0; x < img.width; x++) { int imgIndex = x + y * img.width; float r = brightness(img.pixels[imgIndex]); float s = 255 * (r - rmin) / (rmax - rmin); pixels[imgIndex] = color(s); } updatePixels();