skills/cv/modality-adaptive-dicom-windowing/SKILL.md
Route each DICOM series to a per-modality window-center / window-width pair (CT/CTA/MRA/MRI) before normalization, so the same model can ingest mixed modalities without one modality's intensity range washing out the others
npx skillsauth add wenmin-wu/ds-skills cv-modality-adaptive-dicom-windowingInstall 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.
Mixed-modality medical datasets like RSNA Intracranial Aneurysm contain CT, CTA, MRA, and MRI series in the same training set. A single fixed windowing (or per-image min-max) collapses contrast on whichever modality wasn't tuned for. The fix: read Modality from the DICOM header, look it up in a {modality: (window_center, window_width)} table, and apply the matching window before scaling to uint8. The result is that vessel structure on CTA, flow signal on MRA, and parenchyma on MRI each land in a comparable normalized range — and one shared model can treat all of them as a "vessel image" rather than learning modality-specific intensity hacks.
import numpy as np
import pydicom
WINDOWS = {
'CT': (40, 80), # parenchyma
'CTA': (50, 350), # vessels
'MRA': (600, 1200), # bright-blood angio
'MRI': (40, 80), # generic MR
}
def window(img, modality):
wc, ww = WINDOWS.get(modality, (40, 80))
lo, hi = wc - ww // 2, wc + ww // 2
img = np.clip(img, lo, hi)
return ((img - lo) / (hi - lo + 1e-7) * 255).astype(np.uint8)
ds = pydicom.dcmread(fp, force=True)
px = ds.pixel_array.astype(np.float32) * float(ds.RescaleSlope) + float(ds.RescaleIntercept)
img = window(px, getattr(ds, 'Modality', 'CT'))
Modality strings in your training set (CT, CTA, MR, MRA)RescaleSlope * px + RescaleIntercept first — CT only, but harmless on MR[0, 255] uint8 (or [0, 1] float)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