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

16
LINES

< > BotCompany Repo | #1020127 // rgbImageSimilarity_sameSize

JavaX fragment (include)

1  
// returns similarity (not diff)
2  
static float rgbImageSimilarity_sameSize(RGBImage a, RGBImage b, float similarity) {
3  
  int w = a.w(), h = a.h();
4  
  if (w != b.w() || h != b.h()) fail("not same size");
5  
  float factor = w*h;
6  
  float maxError = (1f-similarity)*factor;
7  
  float diff = 0;
8  
  for (int y = 0; y < h; y++)
9  
    for (int x = 0; x < w; x++) {
10  
      diff += rgbDiff(
11  
        a.getInt(x, y),
12  
        b.getInt(x, y));
13  
      if (diff > maxError) ret similarity-0.001f;
14  
    }
15  
  ret 1f-diff/factor;
16  
}

Author comment

Began life as a copy of #1006762

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020127
Snippet name: rgbImageSimilarity_sameSize
Eternal ID of this version: #1020127/4
Text MD5: c6fd9a8c8a4a05b964fc86a2f99bbfd0
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:15:47
Source code size: 514 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 231 / 260
Version history: 3 change(s)
Referenced in: [show references]