Libraryless. Click here for Pure Java version (29432L/180K).
1 | sclass G22FindSimilarMasksTask<A> { |
2 | // Image we are looking up |
3 | settable Image2B queryImage; |
4 | |
5 | // optional - which primary mask holder is tasked with the search |
6 | settable IG22MasksHolder maskSet; |
7 | |
8 | // where the found masks go (probability = similarity) |
9 | settable new ProbabilisticList<FoundMask> outList; |
10 | |
11 | // probabilistic stack & scheduler |
12 | settable new PStack pstack; |
13 | |
14 | // how many full mask comparisons were made |
15 | int comparisons; |
16 | |
17 | // We all know what this is for |
18 | settable bool verbose; |
19 | |
20 | // Has the search been ended? |
21 | settable bool ended; |
22 | |
23 | class FoundMask { |
24 | settable IG22Mask<A> mask; |
25 | settable double similarity; // zero to one |
26 | settable int candidateNumber; |
27 | settable long stepCount; |
28 | settable double foundAtProbability; |
29 | |
30 | Image2B image() { ret mask.image(); } |
31 | A label() { ret mask.label(); } |
32 | |
33 | toString { |
34 | ret renderVars("FoundMask", |
35 | +label(), |
36 | similarity := formatPercent(similarity), |
37 | +candidateNumber); |
38 | } |
39 | } |
40 | |
41 | *() {} |
42 | *(IG22Mask<A> mask) { queryImage(mask.image()); } |
43 | *(Image2B image) { queryImage(image); } |
44 | *(IImageRegion region, IG22MasksHolder *maskSet) { |
45 | queryImage(maskSet.regionToMaskImage(region)); |
46 | } |
47 | |
48 | IProbabilisticScheduler scheduler() { ret pstack.scheduler(); } |
49 | |
50 | void tryMask(IG22Mask<A> candidate) { |
51 | if (candidate == null) ret; |
52 | comparisons++; |
53 | var candidateImage = candidate.image(); |
54 | long diff = binaryImagePixelDifference_sameSize(queryImage, candidateImage); |
55 | |
56 | double p = liftProbabilityOffGround(1-doubleRatio(diff, area(candidateImage))); |
57 | if (verbose) |
58 | printVars("Candidate tested", +diff, +p, +candidate); |
59 | foundMask(candidate, p); |
60 | } |
61 | |
62 | void foundMask(IG22Mask<A> mask, double similarity) { |
63 | long stepCount = scheduler().stepCount(); |
64 | if (verbose) |
65 | print("Found mask with similarity " + formatDouble3X(similarity) + " in step " + stepCount); |
66 | outList.at(similarity, |
67 | new FoundMask(). |
68 | // actual result |
69 | +mask.+similarity |
70 | |
71 | // stats to test effectivity of search heuristic |
72 | .candidateNumber(comparisons).+stepCount |
73 | .foundAtProbability(scheduler().currentProbability())); |
74 | } |
75 | |
76 | void endSearch { ended(true); } |
77 | |
78 | // one-stop function |
79 | ProbabilisticList<FoundMask> get(IG22MasksHolder maskSet default maskSet) { |
80 | pstack.run(maskSet.findSimilarMasks(this)); |
81 | ret outList; |
82 | } |
83 | } |
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036033 |
Snippet name: | G22FindSimilarMasksTask |
Eternal ID of this version: | #1036033/27 |
Text MD5: | 9c6918e89f26b4132ac59462319856a4 |
Transpilation MD5: | 4aa9e9b50f559559a0490b43a4dc6cc3 |
Author: | stefan |
Category: | javax / gazelle 22 |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2023-02-14 12:20:34 |
Source code size: | 2524 bytes / 83 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 268 / 457 |
Version history: | 26 change(s) |
Referenced in: | [show references] |