skills/cv/3d-center-crop-zero-pad/SKILL.md
Select center slices from a 3D volume and zero-pad along depth when the scan has fewer slices than the target count
npx skillsauth add wenmin-wu/ds-skills cv-3d-center-crop-zero-padInstall 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 imaging volumes vary in slice count across patients and scanners. To feed them into a fixed-depth 3D CNN, select slices centered around the midpoint and zero-pad the depth dimension if the scan has fewer slices than required. This preserves the most informative region while maintaining a consistent input shape.
import numpy as np
def load_volume_fixed_depth(files, num_slices=64, img_size=256, load_fn=None):
"""Load center slices from a sorted file list, zero-pad if too few."""
middle = len(files) // 2
half = num_slices // 2
p1 = max(0, middle - half)
p2 = min(len(files), middle + half)
slices = [load_fn(f, img_size) for f in files[p1:p2]]
vol = np.stack(slices).T # (H, W, D)
if vol.shape[-1] < num_slices:
pad = np.zeros((img_size, img_size, num_slices - vol.shape[-1]))
vol = np.concatenate([vol, pad], axis=-1)
return np.expand_dims(vol, 0) # (1, H, W, D)
volume = load_volume_fixed_depth(sorted_dcm_files, num_slices=64, load_fn=read_dcm)
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