Libraryless. Click here for Pure Java version (10962L/63K).
1 | // images must have same size |
2 | static BWImage averageOfBinaryImages(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 | byte[] bytes = new[w*h]; |
21 | for i over pixels: |
22 | bytes[i] = (byte) iround(pixels[i]*(255/n)); |
23 | ret new BWImage(w, h, bytes); |
24 | } |
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035825 |
Snippet name: | averageOfBinaryImages |
Eternal ID of this version: | #1035825/2 |
Text MD5: | 1d7bf7a515531d0dd79fa58cd4d19611 |
Transpilation MD5: | 741d0ed3fd0064d5f7e95f22850f17ee |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-08-02 00:09:16 |
Source code size: | 609 bytes / 24 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 128 / 185 |
Version history: | 1 change(s) |
Referenced in: | [show references] |