// images must have same size static BWImage averageOfBinaryImages(L l) { int n = l(l); if (n == 0) null; var it = iterator(l); var img = it.next(); int w = img.getWidth(), h = img.getHeight(); int[] pixels = new[w*h]; while true { int i = 0; for y to h: for x to w: { if (img.getBoolPixel(x, y)) pixels[i]++; i++; } if (!it.hasNext()) break; img = it.next(); } byte[] bytes = new[w*h]; for i over pixels: bytes[i] = (byte) iround(pixels[i]*(255/n)); ret new BWImage(w, h, bytes); }