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; void step(IPStack stack) { if (step == 0) { ++step; stack.options(this, map(masksHolder.masks(), mask -> self -> self.currentMask = mask)); } else { long diff = binaryImagePixelDifference_sameSize( maskImage, currentMask.image()); double p = 1-doubleRatio(diff, area(currentMask.image())); outList.at(p, currentMask); stack.ret(); } } } }