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

21
LINES

< > BotCompany Repo | #1006762 // rgbImageSimilarityResized

JavaX fragment (include)

// returns similarity (not diff)
static float rgbImageSimilarityResized(RGBImage a, RGBImage b, float similarity) {
  int aw = a.w(), ah = a.h();
  int bw = b.w(), bh = b.h();
  if (aw == bw && ah == bh) ret rgbImageSimilarity_sameSize(a, b, similarity);
  int wp = max(aw, bw), hp = max(ah, bh);
  float ratio1 = ((float) aw)/ah, ratio2 = ((float) bw)/bh;
  float mismatch = ratio1/ratio2;
  if (mismatch < 1f) mismatch = 1f/mismatch;
  float factor = wp*hp/mismatch; // ratio mismatch punishment (greater mismatch => factor smaller => returned difference bigger)
  float maxError = (1f-similarity)*factor;
  float diff = 0;
  for (int y = 0; y < hp; y++)
    for (int x = 0; x < wp; x++) {
      diff += rgbDiff(
        a.getInt(x*aw/wp, y*ah/hp),
        b.getInt(x*bw/wp, y*bh/hp));
      if (diff > maxError) ret similarity-0.001f;
    }
  ret 1f-diff/factor;
}

Author comment

Began life as a copy of #1006195

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006762
Snippet name: rgbImageSimilarityResized
Eternal ID of this version: #1006762/4
Text MD5: 900f57bf47aeae273de2128cb7443f97
Author: stefan
Category: javax / ocr
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-08 22:04:37
Source code size: 887 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 553 / 553
Version history: 3 change(s)
Referenced in: [show references]