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).

// img must be square with width/height being a power of 2
static BWContrastQuadTree bwImageContrastQuadtree(BWImage img) {
  int w = img.getWidth(), h = img.getHeight();
  assertEquals("width/height", w, h);
  if (!isPowerOf2(w)) fail("image size not a power of 2: " + w);
  ret bwImageContrastQuadtree_make(img, 0, 0, w);
}

static BWContrastQuadTree bwImageContrastQuadtree_make(BWImage img, int x, int y, int w) {
  if (w == 1) ret BWContrastQuadTree(img.getInt(x, y));
  
  int r = w/2;
  BWContrastQuadTree
    a = bwImageContrastQuadtree_make(img, x, y, r),
    b = bwImageContrastQuadtree_make(img, x+r, y, r),
    c = bwImageContrastQuadtree_make(img, x, y+r, r),
    d = bwImageContrastQuadtree_make(img, x+r, y+r, r);
    
  int min = intMin(a.min(), b.min(), c.min(), d.min());
  int max = intMax(a.max(), b.max(), c.max(), d.max());
  if (min == max)
    ret BWContrastQuadTree(min, max);
    
  ret new BWContrastQuadTree.Composite(min, max, a, b, c, d);
}

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: 198 / 301
Version history: 9 change(s)
Referenced in: [show references]