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).

// works in similarity
static float bwImageSectionsSimilarity2(BWImage big, BWImage pat, int x, int y, float similarity) {
  int wp = pat.getWidth(), hp = pat.getHeight();
  int w = big.getWidth(), h = big.getHeight();
  float maxError = (1f-similarity)*wp*hp;
  float diff = 0;
  for (int yy = 0; yy < hp; yy++)
    for (int xx = 0; xx < wp; xx++) {
      diff += Math.abs(big.getPixel(x+xx, y+yy)-pat.getPixel(xx, yy));
      if (diff > maxError) ret similarity-0.001f;
    }
  ret 1f-diff/(wp*hp);
}

static float bwImageSectionsSimilarity2(IBWImage big, BWImage pat, int x, int y, float similarity) {
  int wp = pat.getWidth(), hp = pat.getHeight();
  int w = big.getWidth(), h = big.getHeight();
  float maxError = (1f-similarity)*wp*hp;
  float diff = 0;
  for (int yy = 0; yy < hp; yy++)
    for (int xx = 0; xx < wp; xx++) {
      diff += Math.abs(big.getFloatPixel(x+xx, y+yy)-pat.getPixel(xx, yy));
      if (diff > maxError) ret similarity-0.001f;
    }
  ret 1f-diff/(wp*hp);
}

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: 467 / 554
Version history: 5 change(s)
Referenced in: [show references]