skills/cv/dicom-freq-histogram-normalization/SKILL.md
Normalize DICOM pixel values using frequency-equalized histogram bins for globally consistent non-linear intensity mapping
npx skillsauth add wenmin-wu/ds-skills cv-dicom-freq-histogram-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.
Standard HU windowing clips to a linear range, losing detail in dense regions of the intensity distribution. Frequency-equalized histogram normalization computes bin edges where each bin contains roughly equal numbers of pixels across a representative sample. This non-linear mapping spreads contrast evenly across the full [0, 1] range, making subtle density differences visible to the CNN.
import numpy as np
import torch
def freqhist_bins(px, n_bins=20):
"""Compute bin edges where each bin has equal pixel count."""
imsd = np.sort(px.flatten())
t = np.concatenate([[0.001],
np.arange(n_bins) / n_bins + (1 / (2 * n_bins)),
[0.999]])
return np.unique(np.quantile(imsd, t))
def hist_scaled(px, bins):
"""Map pixel values through frequency-equalized bins to [0, 1]."""
return np.interp(px.flatten(), bins,
np.linspace(0, 1, len(bins))).reshape(px.shape)
# Build global bins from representative sample
sample_pixels = np.concatenate([read_dcm(f).flatten() for f in sample_files])
bins = freqhist_bins(sample_pixels, n_bins=20)
# Apply to any image
normalized = hist_scaled(dcm.pixel_array * slope + intercept, bins)
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