skills/cv/black-border-autocrop/SKILL.md
Crops uninformative black or dark borders from images by deriving a binary mask from the grayscale channel and trimming rows/columns.
npx skillsauth add wenmin-wu/ds-skills cv-black-border-autocropInstall 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.
Medical images (retinal scans, X-rays), scanned documents, and padded photos often have large black or dark borders that waste resolution and confuse models. This technique converts to grayscale, thresholds to find informative pixels, then crops to the bounding box of non-dark content. Works on both grayscale and multi-channel images, applying the same mask consistently across all channels.
import numpy as np
import cv2
def autocrop_black_border(img, tol=7):
"""Crop dark borders from an image.
Args:
img: (H, W) or (H, W, C) numpy array
tol: pixel intensity threshold (0-255); below this is "dark"
Returns:
cropped image
"""
if img.ndim == 2:
mask = img > tol
return img[np.ix_(mask.any(1), mask.any(0))]
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
mask = gray > tol
rows = mask.any(1)
cols = mask.any(0)
if not rows.any():
return img # entirely dark — return original
return img[np.ix_(rows, cols)]
# Usage
img = cv2.imread("scan.png")
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
cropped = autocrop_black_border(img, tol=7)
cropped = cv2.resize(cropped, (512, 512))
np.ix_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