Calculate image contrast using root mean square (RMS)
in
Programming Questions
•
8 months ago
Hi all, I'm trying to measure overall contrast in an image. Currently, I have the Michelson method working:
Looking at the Root Mean Square (RMS) method ( http://en.wikipedia.org/wiki/Contrast_%28vision%29#RMS_contrast), this seems a better bet. However, I can't figure out the formula! Any help or other suggestions would be fantastic!
- float getContrast() {
- float maxLum = 0;
- float minLum = 10000;
- for (int i=0; i<img.pixels.length; i++) {
- float r = img.pixels[i] >> 16 & 0xFF;
- float g = img.pixels[i] >> 8 & 0xFF;
- float b = img.pixels[i] & 0xFF;
- float brightness = (0.2126 * r) + (0.7152 * g) + (0.0722 * b);
- if (brightness > maxLum) maxLum = brightness;
- if (brightness < minLum) minLum = brightness;
- }
- return (maxLum - minLum)/(maxLum + minLum);
- }
Looking at the Root Mean Square (RMS) method ( http://en.wikipedia.org/wiki/Contrast_%28vision%29#RMS_contrast), this seems a better bet. However, I can't figure out the formula! Any help or other suggestions would be fantastic!
1