skills/cv/tumor-volume-ratio-features/SKILL.md
Extract volumetric features from 3D segmentation masks including scan/tumor pixel ratios, tumor percentage, and tumor centroid coordinates
npx skillsauth add wenmin-wu/ds-skills cv-tumor-volume-ratio-featuresInstall 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 segmentation masks contain rich structural information beyond the mask itself. Extracting volumetric features — total scan pixels, tumor pixels, tumor-to-scan ratio, and tumor centroid coordinates — creates tabular features that complement image-based models. These features capture tumor size, location, and relative volume that CNNs may struggle to learn directly.
import numpy as np
from skimage.morphology import binary_closing
def extract_volume_features(scan, segmentation, mask_idx=1):
"""Extract volumetric features from a 3D scan and its segmentation."""
scan_filled = np.stack([binary_closing(scan[i] > 0) for i in range(scan.shape[0])])
scan_px = scan_filled.sum()
tumor_mask = (segmentation == mask_idx) | (segmentation == 4)
tumor_px = tumor_mask.sum()
total_px = np.prod(scan.shape)
z, x, y = tumor_mask.nonzero()
if len(z) > 0:
centroid = [np.median(x) / scan.shape[1],
np.median(y) / scan.shape[2],
np.median(z) / scan.shape[0]]
else:
centroid = [0.5, 0.5, 0.5]
return {
'scan_ratio': scan_px / total_px,
'tumor_ratio': tumor_px / total_px,
'tumor_to_scan': tumor_px / max(scan_px, 1),
'centroid_x': centroid[0],
'centroid_y': centroid[1],
'centroid_z': centroid[2],
}
features = extract_volume_features(volume, seg_mask, mask_idx=1)
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