// images must have same size static FloatBWImage preciseAverageOfBinaryImages(L images) { int n = l(images); if (n == 0) null; var it = iterator(images); var img = it.next(); int w = img.getWidth(), h = img.getHeight(); int[] pixels = new[w*h]; int nBytes = (w*h+7)/8; while ping (true) { Image2B realizedImage = img.toImage2B(); byte[] imgPixels = realizedImage.pixels; int i = 0; for i to nBytes: { int b = bytes[i]; for bit to 8: { if ((b & 1) != 0) pixels[i*8+bit]++; b >>= 1; } } if (!it.hasNext()) break; img = it.next(); } float[] floats = new[w*h]; double factor = 1.0/n; for i over pixels: floats[i] = (float) (pixels[i]*factor); ret new FloatBWImage(w, h, floats); }