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

38
LINES

< > BotCompany Repo | #1026931 // bwImageContrastQuadtree [approach doesn't work]

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

Transpiled version (5156L) is out of date.

1  
// img must be square with width/height being a power of 2
2  
static Pair<BWImage> 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  
  BWImage min = new(w, h);
7  
  BWImage max = new(w, h);
8  
  bwImageContrastQuadtree_make(img, min, max, 0, 0, w);
9  
  ret pair(min, max);
10  
}
11  
12  
svoid bwImageContrastQuadtree_make(BWImage img, BWImage min, BWImage max, int x, int y, int w) {
13  
  int val = img.getInt(x, y);
14  
  if (w == 1) {
15  
    min.setInt(x, y, val);
16  
    max.setInt(x, y, val);
17  
  } else {
18  
    int r = w/2;
19  
    // process 4 subsquares
20  
    bwImageContrastQuadtree_make(img, min, max, x+r, y+r, r);
21  
    bwImageContrastQuadtree_make(img, min, max, x+r, y, r);
22  
    bwImageContrastQuadtree_make(img, min, max, x, y+r, r);
23  
    bwImageContrastQuadtree_make(img, min, max, x, y, r);
24  
    
25  
    // bottom right square is ok, process the 3 other ones
26  
    int minTR, maxTR, minBL, maxBL,
27  
      minBR = min.getInt(x+r, y+r),
28  
      maxBR = max.getInt(x+r, y+r);
29  
    min.setInt(x+r, y, minTR = min(min.getInt(x+r, y), minBR));
30  
    max.setInt(x+r, y, maxTR = max(max.getInt(x+r, y), maxBR));
31  
    
32  
    min.setInt(x, y+r, minBL = min(min.getInt(x, y+r), minBR));
33  
    max.setInt(x, y+r, maxBL = max(max.getInt(x, y+r), maxBR));
34  
    
35  
    min.setInt(x, y, min3(min.getInt(x, y), minTR, minBL));
36  
    max.setInt(x, y, max3(max.getInt(x, y), maxTR, maxBL));
37  
  }
38  
}

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: #1026931
Snippet name: bwImageContrastQuadtree [approach doesn't work]
Eternal ID of this version: #1026931/5
Text MD5: 9ef7d0c6425b07221c5e186b582dcfbb
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 02:56:44
Source code size: 1497 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 147 / 210
Version history: 4 change(s)
Referenced in: [show references]