Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1035839 // G22ForegroundFinder - determines foreground from background regions

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (13130L/76K).

// by default returns dark regions as foreground

sclass G22ForegroundFinder {
  // input
  settable L<IImageRegion> allRegions;
  
  // internal
  gettable Rect borderRect;
  
  // output
  Set<IImageRegion> foregroundRegions;
  
  *() {}
  *(L<IImageRegion> *allRegions) {}
  
  Set<IImageRegion> foregroundRegions aka get() {
    run();
    ret foregroundRegions;
  }
  
  L<IImageRegion> 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;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035839
Snippet name: G22ForegroundFinder - determines foreground from background regions
Eternal ID of this version: #1035839/13
Text MD5: 3cd216be7532c3eac9cae33f5ec37642
Transpilation MD5: 64864944c655fb61c24b70f63abf6d68
Author: stefan
Category: javax / gazelle 22
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-02 21:07:58
Source code size: 893 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 140 / 243
Version history: 12 change(s)
Referenced in: [show references]