1 | static DoublePt centroidForColorPredicate(F1<Int, Bool> pred, RGBImage img) { |
2 | int w = img.getWidth(), h = img.getHeight(); |
3 | double sumX = 0, sumY = 0; |
4 | int sum = 0; |
5 | for y to h: for x to w: |
6 | if (pred.get(img.getInt(x, y))) { |
7 | sumX += x; |
8 | sumY += y; |
9 | ++sum; |
10 | } |
11 | if (sum == 0) null; |
12 | ret DoublePt(sumX/sum, sumY/sum); |
13 | } |
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: | 294 / 344 |
Version history: | 8 change(s) |
Referenced in: | [show references] |