static double averageSaturation(BufferedImage img) { if (img == null) ret 0; int w = img.getWidth(), h = img.getHeight(); double sum = 0; for y to h: for x to w: sum += saturationFromRGB(img.getRGB(x, y)); ret doubleRatio(sum, w*h); }