Libraryless. Click here for Pure Java version (4296L/29K/97K).
!752 p { BWImage img = shootScreenBW(); print(go(img)); setFrameTitle("g = " + g, showImageWithSelections(img.getBufferedImage(), clips)); g = 3; print(go(img)); setFrameTitle("g = " + g, showImageWithSelections(img.getBufferedImage(), clips)); } static L<Rect> clips; static int[] grid; static int gw, gh; static int g = 4; static Rect fill(int x, int y, Rect r) { if (x < 0 || y < 0 || x >= gw || y >= gh) return r; int idx = y*gw+x; if (grid[idx] == 0) return r; grid[idx] = 0; Rect me = new Rect(x, y, 1, 1); if (r == null) r = me; else r = rectUnion(r, me); r = fill(x-1, y, r); r = fill(x+1, y, r); r = fill(x, y-1, r); r = fill(x, y+1, r); return r; } static S go(BWImage img) { int w = img.getWidth(), h = img.getHeight(); gw = w/g; gh = h/g; // width & height of grid grid = new int[gw*gh]; for (int gy = 0; gy <= h- g; gy += g) next: for (int gx = 0; gx <= w- g; gx += g) { float min = 1, max = 0; for (int y = gy; y < gy + g; y++) for (int x = gx; x < gx + g; x++) { float b = img.getPixel(x, y); min = Math.min(min, b); max = Math.max(max, b); if (min < 0.5 && max > 0.5) { grid[(gy / g) * gw + (gx / g)] = 2; continue next; } } } new L<S> result; clips = new L; for (int y = 0; y < gh; y++) for (int x = 0; x < gw; x++) { Rect r = fill(x, y, null); if (r != null) { r = scaleRect(r, g); clips.add(r); r = autoCropOfBWImage(img, r); BWImage cropped = img.clip(r); String hash = md5OfBWImage(cropped); result.add(r + " -> " + hash); } } return "Floodfill: " + join("|", result); }
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005836 |
Snippet name: | Test Auto-Segmenting ["Lua411", dev.] |
Eternal ID of this version: | #1005836/1 |
Text MD5: | 22d5afdb572c824456d748a1e2867381 |
Transpilation MD5: | 28925e03f4fab9a09b3fc75de6f59bfb |
Author: | stefan |
Category: | javax / ocr |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-12-11 02:39:48 |
Source code size: | 1836 bytes / 78 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 522 / 621 |
Referenced in: | [show references] |