interface IG22MasksHolder { replace Mask with IG22Mask. WidthAndHeight maskSize(); L maskImages(); //LPair maskImagesWithLabels(); L masks(); G22GhostImage ghost(); double certainty(); default int nMasks() { ret l(masks()); } default S renderCountAndCertainty() { ret main nMasks(nMasks()) + " with c=" + formatDouble3(certainty()); } default bool canSplit() { ret nMasks() > 1; } default L> subHolders() { null; } default void transformSubHolders(IF1> f) {} default PStackComputable findSimilarMasks( Image2B maskImage, ProbabilisticList outList) { ret new FindSimilarMasks_BruteForce(this, maskImage, outList); } srecord noeq FindSimilarMasks_BruteForce(IG22MasksHolder masksHolder, Image2B maskImage, ProbabilisticList outList) extends PStackComputableWithStep { Mask currentMask; toString { ret formatFunctionCall(shortClassName(this), masksHolder, "step=" + step); } void step(IPStack stack) { if (step == 0) { ++step; stack.optionsOrReturn(this, map(masksHolder.masks(), mask -> self -> self.currentMask = mask)); } else { long diff = binaryImagePixelDifference_sameSize( maskImage, currentMask.image()); // TODO: This formula will drop images which are // complete inverts of each other since then p is 0 // and ProbabilisticList discards this double p = 1-doubleRatio(diff, area(currentMask.image())); printVars("Found mask", +diff, +p, +currentMask); outList.at(p, currentMask); stack.ret(); } } } }