// see https://nanonets.com/blog/optical-flow/ srecord noeq GoodThingsToTrack(BWImage image) { int windowSize = 3; run { int w = image.getWidth(), h = image.getHeight(); int wn = windowSize*windowSize; for (int y = 0; y < h-windowSize-1; y++) for (int x = 0; x < w-windowSize-1; x++) { double[] ix = new[wn]; double[] iy = new[wn]; int iw = 0; for yy to windowSize: for xx to windowSize: { double value = image.getInt(x+xx, y+yy); double right = image.getInt(x+xx+1, y+yy); double below = image.getInt(x+xx, y+yy+1); ix[iw] = right-value; iy[iw] = below-value; iw++; } } } }