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

65
LINES

< > BotCompany Repo | #1024658 // ParameterizedSegmenter - the "old" image segmenter (BWImage-based)

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

Libraryless. Click here for Pure Java version (9093L/54K).

1  
sclass ParameterizedSegmenter implements IF1<BufferedImage, L<Rect>> {
2  
  !include #1024657 // Image Segmenter Parameters
3  
  
4  
  // input
5  
  transient BufferedImage image;
6  
  
7  
  // output
8  
  transient BufferedImage filteredImage1; // before distanceToColor
9  
  transient BufferedImage filteredImage;
10  
  transient L<Rect> segments;
11  
  
12  
  run {
13  
    BufferedImage image = this.image;
14  
    int w = image.getWidth(), h = image.getHeight();
15  
    filteredImage = null;
16  
    if (filterLevel != 0)
17  
      if (eq(filter, 'blur))
18  
        image = filteredImage = new BoxBlurFilter(filterLevel).filter(image, null);
19  
      else if (eq(filter, 'min))
20  
        image = filteredImage = new MinimumFilter(filterLevel).filter(image, null);
21  
      else if (eq(filter, 'max))
22  
        image = filteredImage = new MaximumFilter(filterLevel).filter(image, null);
23  
      else
24  
        print("Unknown filter type: " + filter);
25  
    filteredImage1 = filteredImage;
26  
27  
    new AutoSegmenter as;
28  
    as.g = gridSize;
29  
    as.contrastThreshold = contrastThreshold;
30  
    BWImage bw;
31  
    if (distanceFromColor) {
32  
      bw = img_distanceFromColor_withGain(image, rgbFromInts(dc_r, dc_g, dc_b), dc_gain);
33  
      filteredImage = bw.getBufferedImage();
34  
    } else
35  
      bw = BWImage(image);
36  
    segments = as.go(bw);
37  
    IntRange wr = doubleToIntRange_endPlus1(w, widthRange);
38  
    IntRange hr = doubleToIntRange_endPlus1(h, heightRange);
39  
    IntRange xr = doubleToIntRange_endPlus1(w, xRange);
40  
    IntRange yr = doubleToIntRange_endPlus1(h, yRange);
41  
    segments = filterRectsByWidthRange(segments, wr);
42  
    segments = filterRectsByHeightRange(segments, hr);
43  
    segments = filterRectsByCenterXRange(segments, xr);
44  
    segments = filterRectsByCenterYRange(segments, yr);
45  
  }
46  
  
47  
  public L<Rect> get(BufferedImage img) {
48  
    image = img;
49  
    run();
50  
    ret segments;
51  
  }
52  
  
53  
  void distanceFromColor(RGB color) {
54  
    distanceFromColor = true;
55  
    dc_r = color.redInt();
56  
    dc_g = color.greenInt();
57  
    dc_b = color.blueInt();
58  
  }
59  
  
60  
  public ParameterizedSegmenter clone() {
61  
    ret shallowNonTransientClone(this);
62  
  }
63  
  
64  
  toString { ret sfu(this); }
65  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1024658
Snippet name: ParameterizedSegmenter - the "old" image segmenter (BWImage-based)
Eternal ID of this version: #1024658/10
Text MD5: 43d98204a7d0e2cd1d9a69a4a4e1a2d7
Transpilation MD5: 456753fcf068a9ca64da4297906b8869
Author: stefan
Category: javax / image analysis
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-12 03:06:56
Source code size: 2156 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 331 / 760
Version history: 9 change(s)
Referenced in: [show references]