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

25
LINES

< > BotCompany Repo | #1026940 // bwImageContrastQuadtree [OK for square images with side length power of 2]

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

Libraryless. Click here for Pure Java version (5187L/33K).

1  
// img must be square with width/height being a power of 2
2  
static BWContrastQuadTree bwImageContrastQuadtree(BWImage img) {
3  
  int w = img.getWidth(), h = img.getHeight();
4  
  assertEquals("width/height", w, h);
5  
  if (!isPowerOf2(w)) fail("image size not a power of 2: " + w);
6  
  ret bwImageContrastQuadtree_make(img, 0, 0, w);
7  
}
8  
9  
static BWContrastQuadTree bwImageContrastQuadtree_make(BWImage img, int x, int y, int w) {
10  
  if (w == 1) ret BWContrastQuadTree(img.getInt(x, y));
11  
  
12  
  int r = w/2;
13  
  BWContrastQuadTree
14  
    a = bwImageContrastQuadtree_make(img, x, y, r),
15  
    b = bwImageContrastQuadtree_make(img, x+r, y, r),
16  
    c = bwImageContrastQuadtree_make(img, x, y+r, r),
17  
    d = bwImageContrastQuadtree_make(img, x+r, y+r, r);
18  
    
19  
  int min = intMin(a.min(), b.min(), c.min(), d.min());
20  
  int max = intMax(a.max(), b.max(), c.max(), d.max());
21  
  if (min == max)
22  
    ret BWContrastQuadTree(min, max);
23  
    
24  
  ret new BWContrastQuadTree.Composite(min, max, a, b, c, d);
25  
}

Author comment

Began life as a copy of #1026931

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1026940
Snippet name: bwImageContrastQuadtree [OK for square images with side length power of 2]
Eternal ID of this version: #1026940/10
Text MD5: 827723880b82cfd342e897da7e41f8a8
Transpilation MD5: 7316ab6cb054b2204b2e7473d66aa5e2
Author: stefan
Category: javax / image analysis
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-03 13:19:27
Source code size: 994 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 316 / 418
Version history: 9 change(s)
Referenced in: [show references]