Libraryless. Click here for Pure Java version (29432L/180K).
sclass G22FindSimilarMasksTask<A> { // Image we are looking up settable Image2B queryImage; // optional - which primary mask holder is tasked with the search settable IG22MasksHolder maskSet; // where the found masks go (probability = similarity) settable new ProbabilisticList<FoundMask> outList; // probabilistic stack & scheduler settable new PStack pstack; // how many full mask comparisons were made int comparisons; // We all know what this is for settable bool verbose; // Has the search been ended? settable bool ended; class FoundMask { settable IG22Mask<A> mask; settable double similarity; // zero to one settable int candidateNumber; settable long stepCount; settable double foundAtProbability; Image2B image() { ret mask.image(); } A label() { ret mask.label(); } toString { ret renderVars("FoundMask", +label(), similarity := formatPercent(similarity), +candidateNumber); } } *() {} *(IG22Mask<A> mask) { queryImage(mask.image()); } *(Image2B image) { queryImage(image); } *(IImageRegion region, IG22MasksHolder *maskSet) { queryImage(maskSet.regionToMaskImage(region)); } IProbabilisticScheduler scheduler() { ret pstack.scheduler(); } void tryMask(IG22Mask<A> candidate) { if (candidate == null) ret; comparisons++; var candidateImage = candidate.image(); long diff = binaryImagePixelDifference_sameSize(queryImage, candidateImage); double p = liftProbabilityOffGround(1-doubleRatio(diff, area(candidateImage))); if (verbose) printVars("Candidate tested", +diff, +p, +candidate); foundMask(candidate, p); } void foundMask(IG22Mask<A> mask, double similarity) { long stepCount = scheduler().stepCount(); if (verbose) print("Found mask with similarity " + formatDouble3X(similarity) + " in step " + stepCount); outList.at(similarity, new FoundMask(). // actual result +mask.+similarity // stats to test effectivity of search heuristic .candidateNumber(comparisons).+stepCount .foundAtProbability(scheduler().currentProbability())); } void endSearch { ended(true); } // one-stop function ProbabilisticList<FoundMask> get(IG22MasksHolder maskSet default maskSet) { pstack.run(maskSet.findSimilarMasks(this)); ret outList; } }
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: | 269 / 458 |
Version history: | 26 change(s) |
Referenced in: | #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167) |