// returns null if unknown static DoublePt bwCentroid2(BWImage img, bool dark) { int w = img.getWidth(), h = img.getHeight(); double sumX = 0, sumY = 0, sum = 0; for y to h: for x to w: { float weight = img.getPixel(x, y); if (dark) weight = 1-weight; sumX += weight*x; sumY += weight*y; sum += weight; } if (sum == 0) null; ret DoublePt(sumX/sum, sumY/sum); }
Began life as a copy of #1005817
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: | #1022952 |
Snippet name: | bwCentroid2 - get centroid of dark or light pixels in BWImage (better version?) |
Eternal ID of this version: | #1022952/3 |
Text MD5: | fa791fc4b3258a7d8f28a44e9d8bfb8b |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-04-15 04:09:36 |
Source code size: | 405 bytes / 14 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 281 / 319 |
Version history: | 2 change(s) |
Referenced in: | [show references] |