PImage img = loadImage("robotmarko-g-low-contrast.jpg"); size(600, 400); loadPixels(); img.loadPixels(); int[] h = new int[256]; int[] heq = new int[256]; for (int y = 0; y < img.height; y++) for (int x = 0; x < img.width; x++) { int imgIndex = x + y * img.width; int r = int(brightness(img.pixels[imgIndex])); h[r]++; } int temp = 0; for(int i = 0; i < 256; i++){ temp += h[i]; heq[i] = (int) 255 * temp / (img.width * img.height); } for (int y = 0; y < img.height; y++) for (int x = 0; x < img.width; x++) { int imgIndex = x + y * img.width; int r = int(brightness(img.pixels[imgIndex])); pixels[imgIndex] = color(heq[r]); } updatePixels();