// by default returns dark regions as foreground sclass G22ForegroundFinder { // input settable L allRegions; // internal gettable Rect borderRect; // output Set foregroundRegions; Set foregroundRegions() { run(); ret foregroundRegions; } run { if (foregroundRegions != null) ret; borderRect(mergeRects(map(allRegions, r -> r.getBounds()))); foregroundRegions = new LinkedHashSet; for (r : allRegions) if (isForegroundRegion(r)) foregroundRegions.add(r); } swappable bool isForegroundRegion(IImageRegion region) { ret region.brightness() < 128; } }