static int bwContrastQuadtree_minOfArea(BWImage min, Rect rect) { ret bwContrastQuadtree_minOfArea(min, rect, imageRect(min)); } static int bwContrastQuadtree_minOfArea(BWImage min, Rect rect, Rect block) { 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 min.getInt(block.x, block.y); // complex case: process subregions int w = block.w, hx = (w+1)/2; int h = block.h, hy = (h+1)/2; ret intMin( // top left area bwContrastQuadtree_minOfArea(min, r2, Rect(block.x, block.y, hx, hy)), // tall slice on the right bwContrastQuadtree_minOfArea(min, r2, Rect(block.x+hx, block.y, w-hx, h)), // wide slice on the bottom bwContrastQuadtree_minOfArea(min, r2, Rect(block.x, block.y+hy, w, h-hy)), // bottom right area bwContrastQuadtree_minOfArea(min, r2, Rect(block.x+hx, block.y+hy, w-hx, h-hy))); }