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

54
LINES

< > BotCompany Repo | #1036057 // G22MakeMaskCorrelationMatrix

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

Libraryless. Click here for Pure Java version (11384L/64K).

sclass G22MakeMaskCorrelationMatrix is MakesBufferedImage {
  settable long[][] imagesH;
  settable long[][] imagesW;
  
  // size w()*h(), every entry is a pixel diff count
  gettable int[] matrix;
  
  selfType images(long[][] images) {
    ret imagesW(images).imagesH(images);
  }
  
  selfType images(L<long[]> images) {
    ret images(toArray(long[].class, images));
  }
  
  public int w() { ret imagesH.length; }
  public int h() { ret imagesW.length; }
  
  int maxPixelDiff() { ret l(first(imagesW))*64; }
  
  bool symmetrical() { ret imagesW == imagesH; }
  
  run {
    int w = w(), h = h();
    var matrix = this.matrix = new int[w*h];
    int i = 0;
    if (symmetrical())
      for y to h: {
        long[] imageH = imagesH[y];
        // mirror along diagonal
        int x = 0, i2 = y;
        for (; x < y; x++, i2 += w)
          matrix[i++] = matrix[i2];
        for (; x < w; x++)
          matrix[i++] = countDifferingBits(imageH, imagesW[x]);
      }
    else
      for y to h: {
        long[] imageH = imagesH[y];
        for x to w:
          matrix[i++] = countDifferingBits(imageH, imagesW[x]);
      }
  }
  
  FloatBWImage get() {
    if (matrix == null) run();
    int w = w(), h = h();
    float max = maxPixelDiff();
    ret floatBWImageFromFunction(w, h,
      (x, y) -> 1f-matrix[y*w+x]/max);
  }
  
  public BufferedImage getBufferedImage() { ret toBufferedImage (get()); }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036057
Snippet name: G22MakeMaskCorrelationMatrix
Eternal ID of this version: #1036057/10
Text MD5: 3f3113d941f0911fa73a62672fd00446
Transpilation MD5: 1216d62e47d1d814ac1c502ab74a010c
Author: stefan
Category: javax / gazelle 22
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-09-03 03:50:25
Source code size: 1464 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 67 / 136
Version history: 9 change(s)
Referenced in: [show references]