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