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

96
LINES

< > BotCompany Repo | #1031932 // URecognizer [backup with xClip, yClip]

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

Libraryless. Click here for Pure Java version (7002L/40K).

1  
sclass URecognizer {
2  
  IIntegralImage image;
3  
  
4  
  *() {}
5  
  *(IIntegralImage *image) {}
6  
  *(BufferedImage image) {
7  
    this.image = IntegralImage(image);
8  
  }
9  
  
10  
  // returns 0, 1 or 2
11  
  int posterizeToInt(double x) {
12  
    ret ifloor(clampZeroToOne(x)*3);
13  
  }
14  
15  
  // returns 0, .5 or 1
16  
  double posterizeInPlace(double x) {
17  
    ret posterizeToInt(x)*.5;
18  
  }
19  
  
20  
  class Cell {
21  
    // Original image and which part we are looking at
22  
    DoubleRange xClip, yClip;
23  
  
24  
    // color transformations in place
25  
    DoubleRange[] colorClips = new[3];
26  
  
27  
    Cell copy() {
28  
      new Cell c;
29  
      c.xClip = xClip;
30  
      arrayCopy(colorClips, c.colorClips);
31  
      ret c;
32  
    }
33  
  
34  
    Rect rectInImage() {
35  
      ret toRect_floor(doubleRectFromRanges(xClip, yClip));
36  
    }
37  
  
38  
    // get color of cell
39  
  
40  
    double color(int channel) {
41  
      double color = ii_averageBrightnessOfArea(image, rectInImage(), channel);
42  
      ret transformBetweenDoubleRanges(color, colorClips[channel], zeroToOne());
43  
    }
44  
    
45  
    // unposterized color of all 3 channels
46  
    double[] color() {
47  
      double[] c = new[3];
48  
      for i to 3:
49  
        c[i] = color(i);
50  
      ret c;
51  
    }
52  
    
53  
    toString {
54  
      ret "Color: " + asList(color());
55  
    }
56  
  
57  
    int posterizedIntColor(int channel) {
58  
      ret posterizeToInt(color(channel));
59  
    }
60  
  
61  
    // get sub-cells
62  
  
63  
    Cell[] xSplit() {
64  
      Cell[] cells = new[3];
65  
      for i to 3: cells[i] = xSlice(i/3.0, (i+1)/3.0);
66  
      ret cells;
67  
    }
68  
  
69  
    Cell xSlice(double a, double b) {
70  
      Cell c = copy();
71  
      c.xClip = transformBetweenDoubleRanges(DoubleRange(a, b), zeroToOne(), xClip);
72  
      ret c;
73  
    }
74  
    
75  
    Cell[] ySplit() {
76  
      Cell[] cells = new[3];
77  
      for i to 3: cells[i] = ySlice(i/3.0, (i+1)/3.0);
78  
      ret cells;
79  
    }
80  
  
81  
    Cell ySlice(double a, double b) {
82  
      Cell c = copy();
83  
      c.yClip = transformBetweenDoubleRanges(DoubleRange(a, b), zeroToOne(), yClip);
84  
      ret c;
85  
    }
86  
  }
87  
88  
  // make the root cell
89  
  Cell rootCell() {
90  
    new Cell c;
91  
    c.xClip = doubleRange(0, image.getWidth());
92  
    c.yClip = doubleRange(0, image.getHeight());
93  
    for i to 3: c.colorClips[i] = doubleRange(0, 255);
94  
    ret c;
95  
  }
96  
}

Author comment

Began life as a copy of #1031930

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1031932
Snippet name: URecognizer [backup with xClip, yClip]
Eternal ID of this version: #1031932/4
Text MD5: b77a8c251349350772ec73df8563e83f
Transpilation MD5: 5a8a19dc832fd7f4b08a1ba9c61a50bd
Author: stefan
Category: javax / image recognition
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-02 05:24:02
Source code size: 2258 bytes / 96 lines
Pitched / IR pitched: No / No
Views / Downloads: 80 / 133
Version history: 3 change(s)
Referenced in: [show references]