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

26
LINES

< > BotCompany Repo | #1005919 // bwImageSectionsSimilarity2 - returns similarity (not difference)

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

Libraryless. Click here for Pure Java version (5287L/34K).

1  
// works in similarity
2  
static float bwImageSectionsSimilarity2(BWImage big, BWImage pat, int x, int y, float similarity) {
3  
  int wp = pat.getWidth(), hp = pat.getHeight();
4  
  int w = big.getWidth(), h = big.getHeight();
5  
  float maxError = (1f-similarity)*wp*hp;
6  
  float diff = 0;
7  
  for (int yy = 0; yy < hp; yy++)
8  
    for (int xx = 0; xx < wp; xx++) {
9  
      diff += Math.abs(big.getPixel(x+xx, y+yy)-pat.getPixel(xx, yy));
10  
      if (diff > maxError) ret similarity-0.001f;
11  
    }
12  
  ret 1f-diff/(wp*hp);
13  
}
14  
15  
static float bwImageSectionsSimilarity2(IBWImage big, BWImage pat, int x, int y, float similarity) {
16  
  int wp = pat.getWidth(), hp = pat.getHeight();
17  
  int w = big.getWidth(), h = big.getHeight();
18  
  float maxError = (1f-similarity)*wp*hp;
19  
  float diff = 0;
20  
  for (int yy = 0; yy < hp; yy++)
21  
    for (int xx = 0; xx < wp; xx++) {
22  
      diff += Math.abs(big.getFloatPixel(x+xx, y+yy)-pat.getPixel(xx, yy));
23  
      if (diff > maxError) ret similarity-0.001f;
24  
    }
25  
  ret 1f-diff/(wp*hp);
26  
}

Author comment

Began life as a copy of #1005394

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: #1005919
Snippet name: bwImageSectionsSimilarity2 - returns similarity (not difference)
Eternal ID of this version: #1005919/6
Text MD5: 17d1f76518738b71bdbdd8dda59b02a9
Transpilation MD5: e0b821b5c797fba140687acac54aeede
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-12 02:28:34
Source code size: 1014 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 475 / 566
Version history: 5 change(s)
Referenced in: [show references]