1 | // images must have same size |
2 | static FloatBWImage preciseAverageOfBinaryImages(L<? extends IBinaryImage> l) { |
3 | int n = l(l); |
4 | if (n == 0) null; |
5 | var it = iterator(l); |
6 | var img = it.next(); |
7 | int w = img.getWidth(), h = img.getHeight(); |
8 | int[] pixels = new[w*h]; |
9 | while true { |
10 | int i = 0; |
11 | for y to h: |
12 | for x to w: { |
13 | if (img.getBoolPixel(x, y)) |
14 | pixels[i]++; |
15 | i++; |
16 | } |
17 | if (!it.hasNext()) break; |
18 | img = it.next(); |
19 | } |
20 | float[] floats = new[w*h]; |
21 | double factor = 1.0/n; |
22 | for i over pixels: |
23 | floats[i] = (float) (pixels[i]*factor); |
24 | ret new FloatBWImage(w, h, floats); |
25 | } |
Began life as a copy of #1035846
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1035864 |
Snippet name: | preciseAverageOfBinaryImages (backup) |
Eternal ID of this version: | #1035864/1 |
Text MD5: | 4409d1b7c6b3f75331825d12c79921f3 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-08-04 20:01:09 |
Source code size: | 650 bytes / 25 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 142 / 146 |
Referenced in: | [show references] |