skills/cv/isotropic-resize-with-padding/SKILL.md
Resize images preserving aspect ratio then zero-pad to a square to avoid distortion artifacts in face crops or object detection inputs
npx skillsauth add wenmin-wu/ds-skills cv-isotropic-resize-with-paddingInstall 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.
Naively resizing a rectangular image to a square distorts aspect ratio, creating artifacts that confuse classifiers (especially for faces). Isotropic resize scales the image so the longer side matches the target size, then zero-pads the shorter side. This preserves proportions while producing a fixed-size square input for CNNs.
import cv2
import numpy as np
def isotropic_resize(img, size, interpolation=cv2.INTER_AREA):
h, w = img.shape[:2]
if w > h:
new_w = size
new_h = int(h * size / w)
else:
new_h = size
new_w = int(w * size / h)
resized = cv2.resize(img, (new_w, new_h), interpolation=interpolation)
# Zero-pad to square
canvas = np.zeros((size, size, 3), dtype=np.uint8)
canvas[:new_h, :new_w] = resized
return canvas
face_crop = isotropic_resize(face_crop, 224)
INTER_AREA for downsampling (anti-aliased), INTER_LINEAR for upsamplingdata-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