static float bwImageSimilarityResized_v2(BWImage a, BWImage b, float similarityRequired) { int aw = a.w(), ah = a.h(); int bw = b.w(), bh = b.h(); int wp = max(aw, bw), hp = max(ah, bh); float ratio1 = ((float) aw)/ah, ratio2 = ((float) bw)/bh; float mismatch = ratio1/ratio2; if (mismatch < 1f) mismatch = 1f/mismatch; float factor = wp*hp/mismatch; // ratio mismatch punishment (greater mismatch => factor smaller => returned difference bigger) float maxError = (1f-similarityRequired)*factor*255; float diff = 0; for (int y = 0; y < hp; y++) for (int x = 0; x < wp; x++) { diff += Math.abs( a.getInt_noRangeCheck(x*aw/wp, y*ah/hp)- b.getInt_noRangeCheck(x*bw/wp, y*bh/hp)); if (diff > maxError) ret similarityRequired-0.001f; } ret 1f-diff/factor*255; }
Began life as a copy of #1006195
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035774 |
Snippet name: | bwImageSimilarityResized_v2 (bit faster, to be tested) |
Eternal ID of this version: | #1035774/2 |
Text MD5: | 5f9ab1c96a97b2d169a10870995941cd |
Author: | stefan |
Category: | javax / ocr |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-07-23 22:20:39 |
Source code size: | 832 bytes / 19 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 126 / 143 |
Version history: | 1 change(s) |
Referenced in: | [show references] |