skills/cv/quantile-slice-sampling/SKILL.md
Samples a fixed number of slices from variable-length CT/MRI stacks using quantile indexing to produce consistent input depth.
npx skillsauth add wenmin-wu/ds-skills cv-quantile-slice-samplingInstall 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.
3D medical imaging models require fixed-depth input, but CT/MRI scans vary widely in slice count (50-500+). Quantile slice sampling selects N evenly-spaced slices by computing quantile indices over the full stack. This preserves anatomical coverage from top to bottom regardless of scan length, unlike truncation (loses anatomy) or padding (wastes compute).
import numpy as np
from glob import glob
def sample_slices(scan_dir, n_slices=64):
paths = sorted(glob(f"{scan_dir}/*"),
key=lambda x: int(x.split('/')[-1].split('.')[0]))
n_scans = len(paths)
if n_scans <= n_slices:
indices = list(range(n_scans))
else:
indices = np.quantile(
list(range(n_scans)),
np.linspace(0., 1., n_slices)
).round().astype(int)
return [paths[i] for i in indices]
# Sample 64 slices from a scan with 300+ slices
selected = sample_slices("/data/train_images/patient_001", n_slices=64)
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