Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

24
LINES

< > BotCompany Repo | #1035825 // averageOfBinaryImages

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10962L/63K).

// images must have same size
static BWImage averageOfBinaryImages(L<? extends IBinaryImage> l) {
  int n = l(l);
  if (n == 0) null;
  var it = iterator(l);
  var img = it.next();
  int w = img.getWidth(), h = img.getHeight();
  int[] pixels = new[w*h];
  while true {
    int i = 0;
    for y to h:
      for x to w: {
        if (img.getBoolPixel(x, y))
          pixels[i]++;
        i++;
      }
    if (!it.hasNext()) break;
    img = it.next();
  }
  byte[] bytes = new[w*h];
  for i over pixels:
    bytes[i] = (byte) iround(pixels[i]*(255/n));
  ret new BWImage(w, h, bytes);
}

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: 127 / 182
Version history: 1 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1035846 - preciseAverageOfBinaryImages - as FloatBWImage