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

60
LINES

< > BotCompany Repo | #1035867 // G22GhostImage - average image of a number of masks

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

Libraryless. Click here for Pure Java version (11272L/65K).

1  
persistable sclass G22GhostImage is IBWImage {
2  
  int w, h;
3  
  
4  
  public int getWidth() { ret w; }
5  
  public int getHeight() { ret h; }
6  
  
7  
  // number of images averaged
8  
  int imageCount;
9  
  
10  
  // array contains raw sum over images
11  
  // (1 for white pixel, 0 for black pixel)
12  
  int[] pixels;
13  
  
14  
  *(L<Image2B> maskImages) {
15  
    imageCount = l(maskImages);
16  
    if (imageCount == 0) ret;
17  
    var img = first(maskImages);
18  
    w = img.w(); h = img.h();
19  
    pixels = sumOfBinaryImages(maskImages);
20  
  }
21  
  
22  
  public float getFloatPixel(int x, int y) {
23  
    ret imageCount == 0 ? 0.5f : floatRatio(pixels[y*w+x], imageCount);
24  
  }
25  
  
26  
  FloatBWImage toFloatBWImage() {
27  
    float[] floatPixels = new[pixels.length];
28  
    if (imageCount == 0)
29  
      fillArray(floatPixels, 0.5f);
30  
    else
31  
      for i over pixels:
32  
        floatPixels[i] = floatRatio(pixels[i], imageCount);
33  
    ret new FloatBWImage(w, h, floatPixels);
34  
  }
35  
  
36  
  public BufferedImage getBufferedImage() {
37  
    ret toFloatBWImage().getBufferedImage();
38  
  }
39  
  
40  
  FloatBWImage certaintyImage() {
41  
    ret preciseCertaintyImage(this);
42  
  }
43  
  
44  
  simplyCached double certainty() {
45  
    if (imageCount == 0) ret 0;
46  
    double sum = 0;
47  
    int n = pixels.length;
48  
    for i to n:
49  
      sum += g22pixelCertainty(doubleRatio(pixels[i], imageCount));
50  
    ret sum/(w*h);
51  
  }
52  
  
53  
  G22GhostImage minus(G22GhostImage img) {
54  
    new G22GhostImage ghost;
55  
    ghost.w = w; ghost.h = h;
56  
    ghost.imageCount = imageCount-img.imageCount;
57  
    ghost.pixels = intArray_minus(pixels, img.pixels);
58  
    ret ghost;
59  
  }
60  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035867
Snippet name: G22GhostImage - average image of a number of masks
Eternal ID of this version: #1035867/13
Text MD5: b9ee29b430c634f53079cabf89bc13ec
Transpilation MD5: a22f4ab591b92d0a78c2a150540a852f
Author: stefan
Category: javax / gazelle 22
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-05 19:20:35
Source code size: 1592 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 87 / 175
Version history: 12 change(s)
Referenced in: [show references]