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

25
LINES

< > BotCompany Repo | #1026934 // bwContrastQuadtree_minOfArea [OK]

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

Libraryless. Click here for Pure Java version (2400L/15K).

static int bwContrastQuadtree_minOfArea(BWContrastQuadTree qt, int originalSize, Rect rect) {
  ret bwContrastQuadtree_minOfArea(qt, Rect(0, 0, originalSize, originalSize), rect);
}

static int bwContrastQuadtree_minOfArea(BWContrastQuadTree qt, Rect block, Rect rect) {
  Rect r2 = intersectRects(rect, block);
  if (r2.empty()) ret 255; // simple case 1: no intersection
  print(rect + " => " + r2);
  
  // simple case 2: whole block
  if (eq(r2, block)) ret qt.min();
  
  // simple case 3: block is one color
  if (!(qt instanceof BWContrastQuadTree.Composite))
    ret qt.min();
  
  // complex case: process subregions
  BWContrastQuadTree.Composite qt2 = cast qt;
  int w = block.w, r = w/2;
  ret intMin(
    bwContrastQuadtree_minOfArea(qt2.a, Rect(block.x, block.y, r, r), r2),
    bwContrastQuadtree_minOfArea(qt2.b, Rect(block.x+r, block.y, r, r), r2),
    bwContrastQuadtree_minOfArea(qt2.c, Rect(block.x, block.y+r, r, r), r2),
    bwContrastQuadtree_minOfArea(qt2.d, Rect(block.x+r, block.y+r, r, r), r2));
}

Author comment

Began life as a copy of #1019596

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: #1026934
Snippet name: bwContrastQuadtree_minOfArea [OK]
Eternal ID of this version: #1026934/21
Text MD5: a2d3c4ec97a6e9bb1d2b7b72302d8487
Transpilation MD5: 55bb4ff411dc18b55467f12655c9b689
Author: stefan
Category: javax / ocr
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-03 13:18:31
Source code size: 1050 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 252 / 399
Version history: 20 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1026941 - bwContrastQuadtree_minOfArea [approach doesn't work]