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

41
LINES

< > BotCompany Repo | #1035846 // preciseAverageOfBinaryImages - as FloatBWImage

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

Transpiled version (11068L) is out of date.

1  
// images must have same size
2  
static FloatBWImage preciseAverageOfBinaryImages(L<? extends IBinaryImage> images) {
3  
  int n = l(images);
4  
  if (n == 0) null;
5  
  var it = iterator(images);
6  
  var img = it.next();
7  
  int w = img.getWidth(), h = img.getHeight();
8  
  int[] pixels = new[w*h];
9  
  int nBytes = (w*h+7)/8;
10  
  var pingSource = pingSource();
11  
  
12  
  while (true) {
13  
    ping(pingSource);
14  
    Image2B realizedImage = img.toImage2B();
15  
    byte[] imgPixels = realizedImage.pixels;
16  
    int j = 0;
17  
    for i to nBytes: {
18  
      int b = imgPixels[i];
19  
      for bit to 8: {
20  
        ifdef preciseAverageOfBinaryImages_useIf
21  
        // This version is half as fast (don't set this flag)
22  
        if ((b & 1) != 0)
23  
          pixels[i*8+bit]++;
24  
        endifdef
25  
        ifndef preciseAverageOfBinaryImages_useIf
26  
        pixels[j++] += b & 1;
27  
        endifndef
28  
        b >>= 1;
29  
      }
30  
    }
31  
    
32  
    if (!it.hasNext()) break;
33  
    img = it.next();
34  
  }
35  
  
36  
  float[] floats = new[w*h];
37  
  double factor = 1.0/n;
38  
  for i over pixels:
39  
    floats[i] = (float) (pixels[i]*factor);
40  
  ret new FloatBWImage(w, h, floats);
41  
}

Author comment

Began life as a copy of #1035825

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1035846
Snippet name: preciseAverageOfBinaryImages - as FloatBWImage
Eternal ID of this version: #1035846/11
Text MD5: 1c2356a27782b91a98d2017451a2751e
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:46:22
Source code size: 1134 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 130 / 210
Version history: 10 change(s)
Referenced in: [show references]