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

21
LINES

< > BotCompany Repo | #1006762 // rgbImageSimilarityResized

JavaX fragment (include)

1  
// returns similarity (not diff)
2  
static float rgbImageSimilarityResized(RGBImage a, RGBImage b, float similarity) {
3  
  int aw = a.w(), ah = a.h();
4  
  int bw = b.w(), bh = b.h();
5  
  if (aw == bw && ah == bh) ret rgbImageSimilarity_sameSize(a, b, similarity);
6  
  int wp = max(aw, bw), hp = max(ah, bh);
7  
  float ratio1 = ((float) aw)/ah, ratio2 = ((float) bw)/bh;
8  
  float mismatch = ratio1/ratio2;
9  
  if (mismatch < 1f) mismatch = 1f/mismatch;
10  
  float factor = wp*hp/mismatch; // ratio mismatch punishment (greater mismatch => factor smaller => returned difference bigger)
11  
  float maxError = (1f-similarity)*factor;
12  
  float diff = 0;
13  
  for (int y = 0; y < hp; y++)
14  
    for (int x = 0; x < wp; x++) {
15  
      diff += rgbDiff(
16  
        a.getInt(x*aw/wp, y*ah/hp),
17  
        b.getInt(x*bw/wp, y*bh/hp));
18  
      if (diff > maxError) ret similarity-0.001f;
19  
    }
20  
  ret 1f-diff/factor;
21  
}

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: 476 / 478
Version history: 3 change(s)
Referenced in: [show references]