skills/cv/min-area-mask-filtering/SKILL.md
Removes predicted segmentation masks below a per-class minimum pixel area threshold to eliminate small false positive regions at inference time.
npx skillsauth add wenmin-wu/ds-skills cv-min-area-mask-filteringInstall 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.
Segmentation models often produce small spurious predictions — isolated pixel clusters that score above the confidence threshold but are too small to be real objects. Min-area filtering applies a per-class pixel count threshold: after binarizing the predicted mask, any connected component (or entire class mask) with fewer pixels than the threshold is zeroed out. This simple post-processing step typically improves Dice/IoU by 0.5-2% by eliminating false positives, especially in defect detection and medical imaging where true objects have known minimum sizes.
import numpy as np
def filter_small_masks(pred_masks, min_areas, thresholds):
"""Filter masks below per-class minimum area.
Args:
pred_masks: (H, W, C) float array of predicted probabilities
min_areas: list of minimum pixel counts per class
thresholds: list of binarization thresholds per class
Returns:
Filtered binary masks (H, W, C)
"""
filtered = np.zeros_like(pred_masks, dtype=np.uint8)
for c in range(pred_masks.shape[-1]):
mask = (pred_masks[:, :, c] > thresholds[c]).astype(np.uint8)
if mask.sum() < min_areas[c]:
mask = np.zeros_like(mask)
filtered[:, :, c] = mask
return filtered
# Per-class thresholds and min areas (tune on validation)
thresholds = [0.5, 0.5, 0.5, 0.5]
min_areas = [600, 600, 1000, 2000]
clean_masks = filter_small_masks(raw_preds, min_areas, thresholds)
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