sclass G22FindSimilarMasksTask { // 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 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 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 mask) { queryImage(mask.image()); } *(Image2B image) { queryImage(image); } *(IImageRegion region, IG22MasksHolder *maskSet) { queryImage(maskSet.regionToMaskImage(region)); } IProbabilisticScheduler scheduler() { ret pstack.scheduler(); } void tryMask(IG22Mask 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 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 get(IG22MasksHolder maskSet default maskSet) { pstack.run(maskSet.findSimilarMasks(this)); ret outList; } }