Libraryless. Click here for Pure Java version (4640L/26K).
1 | // is it a split? is it a join? depends on your view |
2 | sclass IIHorizontalSplit extends Meta implements IIntegralImage { |
3 | // x coordinate of split point |
4 | // - isn't this just a.getWidth()? |
5 | int splitPoint; |
6 | |
7 | // a and b must have same height |
8 | |
9 | // [0; splitPoint) |
10 | RegisteredReference<IIntegralImage> a = new(this); |
11 | |
12 | // [splitPoint; width) |
13 | RegisteredReference<IIntegralImage> b = new(this); |
14 | |
15 | *() {} |
16 | *(IIntegralImage img) { |
17 | int w = img.getWidth(); |
18 | if (w < 2) fail("Can't split image horizontally - too small"); |
19 | init(img, w/2); |
20 | } |
21 | *(IIntegralImage img, int splitPoint) { |
22 | init(img, splitPoint); |
23 | } |
24 | |
25 | *(IIntegralImage img1, IIntegralImage img2) { |
26 | a.set(img1); |
27 | b.set(img2); |
28 | splitPoint = img1.getWidth(); |
29 | } |
30 | |
31 | void init(IIntegralImage img, int splitPoint) { |
32 | this.splitPoint = splitPoint; |
33 | int w = img.getWidth(), h = img.getHeight(); |
34 | a.set(img.clip(0, 0, splitPoint, h)); |
35 | b.set(img.clip(splitPoint, 0, w-splitPoint, h)); |
36 | } |
37 | |
38 | public simplyCached int getWidth() { ret a->getWidth()+b->getWidth(); } |
39 | public int getHeight() { ret a->getHeight(); } |
40 | |
41 | public double getIntegralValue(int x, int y, int channel) { |
42 | if (x < splitPoint) |
43 | ret a->getIntegralValue(x, y, channel); |
44 | else ret |
45 | a->getIntegralValue(splitPoint, y, channel) |
46 | + b->getIntegralValue(x-splitPoint, y, channel); |
47 | } |
48 | |
49 | public double getIntegralValue(int x, int y) { |
50 | if (x < splitPoint) |
51 | ret a->getIntegralValue(x, y); |
52 | else ret |
53 | a->getIntegralValue(splitPoint, y) |
54 | + b->getIntegralValue(x-splitPoint, y); |
55 | } |
56 | |
57 | public BufferedImage getBufferedImage() { |
58 | BufferedImage img = newBufferedImage(getWidth(), getHeight()); |
59 | var g = graphics(img); |
60 | a->drawAt(g, 0, 0); |
61 | b->drawAt(g, splitPoint, 0); |
62 | ret img; |
63 | } |
64 | |
65 | IIntegralImage a() { ret a!; } |
66 | IIntegralImage b() { ret b!; } |
67 | void setA(IIntegralImage a) { this.a.set(a); } |
68 | void setB(IIntegralImage b) { this.b.set(b); } |
69 | } |
Began life as a copy of #1031959
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1031964 |
Snippet name: | IIHorizontalSplit - IIntegralImage composed of 2 horizontal parts (OK) |
Eternal ID of this version: | #1031964/9 |
Text MD5: | 5d172666eec330c400a528247f65ea36 |
Transpilation MD5: | c43df0bb97b9f28fda64cef6ba32e6b0 |
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-17 13:48:23 |
Source code size: | 2046 bytes / 69 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 176 / 340 |
Version history: | 8 change(s) |
Referenced in: | [show references] |