平均値算出プログラム

mean1.pde
PImage img;
String target = "no_filter_all.png";
	
void setup() {
  size(100,100);
  img = loadImage(target);
  int w = img.width;
  int h = img.height;
  float sumR = 0, sumG = 0, sumB = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      color c = img.pixels[y * w + x];
      sumR = sumR + red(c);
      sumG = sumG + green(c);
      sumB = sumB + blue(c);
    }
  }
  
  sumR = sumR / (w * h);
  sumG = sumG / (w * h);
  sumB = sumB / (w * h);
  
  println("ファイル名:" + target);
  println("平均値:(" + sumR + " , " + sumG + " , " + sumB + ")");
}
	
void draw() {}