!752 static int viewSize = 20; static L findCentroids(BWImage img, int size, bool dark) { float minOffset = 0f; int maxLoop = 3; int w = img.w()-size, h = img.h()-size; new L points; if (w < 0 || h < 0) ret points; Pt[][] centroids = new Pt[h][w]; for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { Rect r = new Rect(x, y, size, size); Pair c = bwCentroid(img.clip(r), dark); float cx = c.a-size/2, cy = c.b-size/2; centroids[y][x] = new Pt( x+signWithThreshold(cx, minOffset), y+signWithThreshold(cy, minOffset)); } for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { int n = 0; int xx = x, yy = y; while (n++ < maxLoop) { Pt p = centroids[yy][xx]; xx = p.x; yy = p.y; if (xx < 0 || xx >= w || yy < 0 || yy >= h) break; if (x == xx && y == yy) { points.add(new Pt(x+viewSize/2, y+viewSize/2)); break; } } } ret points; } p { screenQuickSelect(voidfunc(BufferedImage screen, Rect r) { final BWImage img = new BWImage(clipBufferedImage(screen, r)); thread "Calc" { print("Finding centroids... (size=\*viewSize*/, \*img.w()*/*\*img.h()*/ px)"); L dark = findCentroids(img, viewSize, true); printStruct("dark", dark); L light = findCentroids(img, viewSize, false); printStruct("light", light); RGBImage rgb = img.toRGB(); markPointsInRGBImage(rgb, dark); markPointsInRGBImage(rgb, light, Color.green); showImage(rgb); } }); }