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

19
LINES

< > BotCompany Repo | #1006195 // bwImageSimilarityResized

JavaX fragment (include)

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

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: 606 / 637
Version history: 1 change(s)
Referenced in: [show references]