1 | // returns null if unknown |
2 | static DoublePt bwCentroid2(BWImage img, bool dark) {
|
3 | int w = img.getWidth(), h = img.getHeight(); |
4 | double sumX = 0, sumY = 0, sum = 0; |
5 | for y to h: for x to w: {
|
6 | float weight = img.getPixel(x, y); |
7 | if (dark) weight = 1-weight; |
8 | sumX += weight*x; |
9 | sumY += weight*y; |
10 | sum += weight; |
11 | } |
12 | if (sum == 0) null; |
13 | ret DoublePt(sumX/sum, sumY/sum); |
14 | } |
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: | 477 / 526 |
| Version history: | 2 change(s) |
| Referenced in: | [show references] |