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).

1  
// by default returns dark regions as foreground
2  
3  
sclass G22ForegroundFinder {
4  
  // input
5  
  settable L<IImageRegion> allRegions;
6  
  
7  
  // internal
8  
  gettable Rect borderRect;
9  
  
10  
  // output
11  
  Set<IImageRegion> foregroundRegions;
12  
  
13  
  *() {}
14  
  *(L<IImageRegion> *allRegions) {}
15  
  
16  
  Set<IImageRegion> foregroundRegions aka get() {
17  
    run();
18  
    ret foregroundRegions;
19  
  }
20  
  
21  
  L<IImageRegion> backgroundRegions() {
22  
    ret listMinusSet(allRegions, foregroundRegions());
23  
  }
24  
  
25  
  run {
26  
    if (foregroundRegions != null) ret;
27  
    borderRect = mergeRects(map(allRegions, r -> r.bounds()));
28  
    foregroundRegions = new LinkedHashSet;
29  
    for (r : allRegions)
30  
      if (isForegroundRegion(r))
31  
        foregroundRegions.add(r);
32  
  }
33  
  
34  
  swappable bool isForegroundRegion(IImageRegion region) {
35  
    ret defaultDecolorizer().toGrayScale(region.color()) < 128;
36  
  }
37  
}

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: 141 / 244
Version history: 12 change(s)
Referenced in: [show references]