skills/cv/dicom-hounsfield-normalization/SKILL.md
Convert raw DICOM pixel arrays to Hounsfield Units using per-slice RescaleSlope/RescaleIntercept, with outside-scanner clamping
npx skillsauth add wenmin-wu/ds-skills cv-dicom-hounsfield-normalizationInstall 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 CT scanners store raw pixel values that must be converted to Hounsfield Units (HU) for meaningful analysis. Apply per-slice RescaleSlope and RescaleIntercept from DICOM metadata, then clamp outside-scanner regions to air (−1000 HU). This standardizes pixel values across different scanners and protocols.
import numpy as np
import pydicom
def transform_to_hu(slices):
"""Convert DICOM slices to Hounsfield Units.
Args:
slices: list of pydicom Dataset objects (one per CT slice)
Returns:
3D numpy array in HU scale
"""
images = np.stack([s.pixel_array for s in slices]).astype(np.int16)
images[images <= -1000] = 0 # outside-scanner → air
for n in range(len(slices)):
intercept = slices[n].RescaleIntercept
slope = slices[n].RescaleSlope
if slope != 1:
images[n] = (slope * images[n].astype(np.float64)).astype(np.int16)
images[n] += np.int16(intercept)
return np.array(images, dtype=np.int16)
# Usage
slices = [pydicom.dcmread(f) for f in sorted(dicom_files)]
slices.sort(key=lambda s: float(s.ImagePositionPatient[2]))
hu_volume = transform_to_hu(slices)
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