skills/cv/greedy-mask-overlap-resolution/SKILL.md
Resolve overlapping instance masks by greedily assigning contested pixels to higher-confidence predictions using a running occupancy map
npx skillsauth add wenmin-wu/ds-skills cv-greedy-mask-overlap-resolutionInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Instance segmentation models often produce overlapping masks, but many evaluation metrics (and biological reality) require non-overlapping instances. This technique processes masks in descending confidence order and subtracts already-claimed pixels from each new mask. Simple, fast, and effective — commonly used in cell segmentation where dense packing makes overlap inevitable.
import numpy as np
def resolve_overlaps(masks, scores, min_pixels=75):
order = np.argsort(-scores)
used = np.zeros(masks[0].shape, dtype=np.uint8)
result = []
for idx in order:
mask = (masks[idx] > 0).astype(np.uint8)
mask = mask * (1 - used) # remove already-claimed pixels
if mask.sum() >= min_pixels:
used = np.clip(used + mask, 0, 1)
result.append(mask)
return result
# Usage with Mask R-CNN output
masks = output['masks'].cpu().numpy() # (N, H, W)
scores = output['scores'].cpu().numpy()
clean_masks = resolve_overlaps(masks, scores, min_pixels=75)
data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF