Libraryless. Click here for Pure Java version (4476L/30K/107K).
!752 static int viewSize = 20; static L<Pt> findCentroids(BWImage img, int size, bool dark) { float minOffset = 0f; int maxLoop = 3; int w = img.w()-size, h = img.h()-size; new L<Pt> points; if (w < 0 || h < 0) ret points; Pt[][] centroids = new Pt[h][w]; for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { Rect r = new Rect(x, y, size, size); Pair<Float, Float> c = bwCentroid(img.clip(r), dark); float cx = c.a-size/2, cy = c.b-size/2; centroids[y][x] = new Pt( x+signWithThreshold(cx, minOffset), y+signWithThreshold(cy, minOffset)); } for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) { int n = 0; int xx = x, yy = y; while (n++ < maxLoop) { Pt p = centroids[yy][xx]; xx = p.x; yy = p.y; if (xx < 0 || xx >= w || yy < 0 || yy >= h) break; if (x == xx && y == yy) { points.add(new Pt(x+viewSize/2, y+viewSize/2)); break; } } } ret points; } p { screenQuickSelect(voidfunc(BufferedImage screen, Rect r) { final BWImage img = new BWImage(clipBufferedImage(screen, r)); thread "Calc" { print("Finding centroids... (size=\*viewSize*/, \*img.w()*/*\*img.h()*/ px)"); L<Pt> dark = findCentroids(img, viewSize, true); printStruct("dark", dark); L<Pt> light = findCentroids(img, viewSize, false); printStruct("light", light); RGBImage rgb = img.toRGB(); markPointsInRGBImage(rgb, dark); markPointsInRGBImage(rgb, light, Color.green); showImage(rgb); } }); }
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: | #1006185 |
Snippet name: | Find centroids |
Eternal ID of this version: | #1006185/1 |
Text MD5: | df2ca167465c9787cb8ce718ba8eeae2 |
Transpilation MD5: | 503f8ec5a89a43c2571994e6297316a9 |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-12-22 22:33:42 |
Source code size: | 1658 bytes / 55 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 580 / 655 |
Referenced in: | -