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

77
LINES

< > BotCompany Repo | #1031919 // U [dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 1113K of libraries. Click here for Pure Java version (3357L/17K).

1  
cmodule2 URecog > DynPrintLog {  
2  
  // returns 0, 1 or 2
3  
  int posterizeToInt(double x) {
4  
    ret ifloor(clampZeroToOne(x)*3);
5  
  }
6  
7  
  // returns 0, .5 or 1
8  
  double posterizeInPlace(double x) {
9  
    ret posterizeToInt(x)*.5;
10  
  }
11  
  
12  
  class Cell {
13  
    // Original image and which part we are looking at
14  
    IIntegralImage image;
15  
    DoubleRange xClip, yClip;
16  
17  
    // color transformations in place
18  
    DoubleRange[] colorClips = new[3];
19  
20  
    *() {} // internal
21  
22  
    // make the root cell
23  
    *(IIntegralImage *image) {
24  
      xClip = yClip = zeroToOne();
25  
      for i to 3: colorClips[i] = zeroToOne();
26  
    }
27  
28  
    Cell copy() {
29  
      new Cell c;
30  
      c.image = image;
31  
      c.xClip = xClip;
32  
      arrayCopy(colorClips, c.colorClips);
33  
      ret c;
34  
    }
35  
36  
    Rect rectInImage() {
37  
      ret toRect_floor(doubleRectFromRanges(xClip, yClip));
38  
    }
39  
40  
    // get color of cell
41  
42  
    double color(int channel) {
43  
      double color = ii_averageBrightnessOfArea(image, rectInImage());
44  
      ret transformBetweenDoubleRanges(color, colorClips[channel], zeroToOne());
45  
    }
46  
47  
    int posterizedIntColor(int channel) {
48  
      ret posterizeToInt(color(channel));
49  
    }
50  
51  
    // get sub-cells
52  
53  
    Cell[] xSplit() {
54  
      Cell[] cells = new[3];
55  
      for i to 3: cells[i] = xSlice(i, i+1);
56  
      ret cells;
57  
    }
58  
59  
    Cell xSlice(double a, double b) {
60  
      Cell c = copy();
61  
      c.xClip = transformBetweenDoubleRanges(DoubleRange(a, b), zeroToOne(), xClip);
62  
      ret c;
63  
    }
64  
    
65  
    Cell[] ySplit() {
66  
      Cell[] cells = new[3];
67  
      for i to 3: cells[i] = ySlice(i, i+1);
68  
      ret cells;
69  
    }
70  
71  
    Cell ySlice(double a, double b) {
72  
      Cell c = copy();
73  
      c.yClip = transformBetweenDoubleRanges(DoubleRange(a, b), zeroToOne(), yClip);
74  
      ret c;
75  
    }
76  
  }
77  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1031919
Snippet name: U [dev.]
Eternal ID of this version: #1031919/9
Text MD5: 9c2a0b17b85afdb12fb12c8ff67b4387
Transpilation MD5: d4ae873c81bac2cd260ed173a2907dd5
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-02 04:42:20
Source code size: 1753 bytes / 77 lines
Pitched / IR pitched: No / No
Views / Downloads: 168 / 282
Version history: 8 change(s)
Referenced in: [show references]