sclass MakeMaskCorrelationMatrix is MakesBufferedImage { settable long[][] imagesH; settable long[][] imagesW; // size w()*h(), every entry is a pixel diff count gettable int[] matrix; public int w() { ret imagesH.length; } public int h() { ret imagesW.length; } int maxPixelDiff() { ret l(first(imagesW))*64; } run { int w = w(), h = h(); var matrix = this.matrix = new int[w*h]; int i = 0; for y to h: { long[] imageH = imagesH[y]; for x to w: matrix[i++] = countDifferingBits(imageH, imagesW[x]); } } FloatBWImage get() { if (matrix == null) run(); int w = w(), h = h(); float max = maxPixelDiff(); ret floatBWImageFromFunction(w, h, (x, y) -> 1f-matrix[y*w+x]/max); } public BufferedImage getBufferedImage() { ret toBufferedImage (get()); } }