sclass G22FindSimilarMasksTask { // Image we are looking up settable Image2B queryImage; // optional - which primary mask holder is tasked with the search // settable IG22MasksHolder mainMasksHolder; // 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; settable int candidateNumber; settable long stepCount; settable double foundAtProbability; Image2B image() { ret mask.image(); } A label() { ret mask.label(); } } *() {} *(IG22Mask mask) { queryImage(mask.image()); } *(Image2B image) { queryImage(image); } 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); } }