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

19
LINES

< > BotCompany Repo | #1006195 // bwImageSimilarityResized

JavaX fragment (include)

static float bwImageSimilarityResized(BWImage a, BWImage b, float 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 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-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 similarityRequired-0.001f;
    }
  ret 1f-diff/factor;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1006195
Snippet name: bwImageSimilarityResized
Eternal ID of this version: #1006195/2
Text MD5: e50a121a4763b705d7cb7de8db20f79b
Author: stefan
Category: javax / ocr
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-10 18:48:41
Source code size: 799 bytes / 19 lines
Pitched / IR pitched: No / No
Views / Downloads: 607 / 638
Version history: 1 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1006762 - rgbImageSimilarityResized
#1018643 - bwImageSimilarityResized_ignoreRatioMismatch
#1034855 - bwRawImageDiff_sameSize - returns long (between 0 and 255*nPixels)
#1035774 - bwImageSimilarityResized_v2 (bit faster, to be tested)