// images must have same size static FloatBWImage preciseAverageOfBinaryImages(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(); } float[] floats = new[w*h]; for i over pixels: floats[i] = pixels[i]/n; ret new FloatBWImage(w, h, floats); }