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).

persistable sclass G22GhostImage is IBWImage {
  int w, h;
  
  public int getWidth() { ret w; }
  public int getHeight() { ret h; }
  
  // number of images averaged
  int imageCount;
  
  // array contains raw sum over images
  // (1 for white pixel, 0 for black pixel)
  int[] pixels;
  
  *(L<Image2B> maskImages) {
    imageCount = l(maskImages);
    if (imageCount == 0) ret;
    var img = first(maskImages);
    w = img.w(); h = img.h();
    pixels = sumOfBinaryImages(maskImages);
  }
  
  public float getFloatPixel(int x, int y) {
    ret imageCount == 0 ? 0.5f : floatRatio(pixels[y*w+x], imageCount);
  }
  
  FloatBWImage toFloatBWImage() {
    float[] floatPixels = new[pixels.length];
    if (imageCount == 0)
      fillArray(floatPixels, 0.5f);
    else
      for i over pixels:
        floatPixels[i] = floatRatio(pixels[i], imageCount);
    ret new FloatBWImage(w, h, floatPixels);
  }
  
  public BufferedImage getBufferedImage() {
    ret toFloatBWImage().getBufferedImage();
  }
  
  FloatBWImage certaintyImage() {
    ret preciseCertaintyImage(this);
  }
  
  simplyCached double certainty() {
    if (imageCount == 0) ret 0;
    double sum = 0;
    int n = pixels.length;
    for i to n:
      sum += g22pixelCertainty(doubleRatio(pixels[i], imageCount));
    ret sum/(w*h);
  }
  
  G22GhostImage minus(G22GhostImage img) {
    new G22GhostImage ghost;
    ghost.w = w; ghost.h = h;
    ghost.imageCount = imageCount-img.imageCount;
    ghost.pixels = intArray_minus(pixels, img.pixels);
    ret ghost;
  }
}

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: 176 / 310
Version history: 12 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)