// by default returns dark regions as foreground sclass G22ForegroundFinder { // input settable L allRegions; // internal gettable Rect borderRect; // output Set foregroundRegions; *() {} *(L *allRegions) {} Set foregroundRegions aka get() { 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 defaultDecolorizer().toGrayScale(region.color()) < 128; } }