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

17
LINES

< > BotCompany Repo | #1018643 // bwImageSimilarityResized_ignoreRatioMismatch

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

Libraryless. Click here for Pure Java version (2598L/16K).

static float bwImageSimilarityResized_ignoreRatioMismatch(BWImage a, BWImage b, double similarityRequired) {
  int aw = a.w(), ah = a.h();
  int bw = b.w(), bh = b.h();
  int wp = max(aw, bw), hp = max(ah, bh);
  float ratio1 = ((float) aw)/ah, ratio2 = ((float) bw)/bh;
  float factor = wp*hp;
  float maxError = (1f-(float) similarityRequired)*factor;
  float diff = 0;
  for (int y = 0; y < hp; y++)
    for (int x = 0; x < wp; x++) {
      diff += Math.abs(
        a.getPixel(x*aw/wp, y*ah/hp)-
        b.getPixel(x*bw/wp, y*bh/hp));
      if (diff > maxError) ret (float) similarityRequired-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, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1018643
Snippet name: bwImageSimilarityResized_ignoreRatioMismatch
Eternal ID of this version: #1018643/4
Text MD5: 17583baf3a52161cbd1c12e25543c866
Transpilation MD5: 1a431c138a90fb93e5567e25e6a4ef34
Author: stefan
Category: javax / ocr
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-23 19:52:24
Source code size: 650 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 282 / 382
Version history: 3 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)