1 | static float bwImageSimilarityResized_v2(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*255; |
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.getInt_noRangeCheck(x*aw/wp, y*ah/hp)- |
15 | b.getInt_noRangeCheck(x*bw/wp, y*bh/hp)); |
16 | if (diff > maxError) ret similarityRequired-0.001f; |
17 | } |
18 | ret 1f-diff/factor*255; |
19 | } |
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: | 127 / 145 |
Version history: | 1 change(s) |
Referenced in: | [show references] |