static DoublePt centroidForColorPredicate(F1<Int, Bool> pred, RGBImage img) { int w = img.getWidth(), h = img.getHeight(); double sumX = 0, sumY = 0; int sum = 0; for y to h: for x to w: if (pred.get(img.getInt(x, y))) { sumX += x; sumY += y; ++sum; } if (sum == 0) null; ret DoublePt(sumX/sum, sumY/sum); }
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1022948 |
Snippet name: | centroidForColorPredicate - may return null |
Eternal ID of this version: | #1022948/9 |
Text MD5: | 73facaced81d99343a2cdc70998f85f5 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-04-15 04:18:21 |
Source code size: | 357 bytes / 13 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 293 / 343 |
Version history: | 8 change(s) |
Referenced in: | [show references] |