skills/cv/dicom-orientation-detection/SKILL.md
Decodes MRI scan plane (axial, coronal, sagittal) from DICOM ImageOrientationPatient direction cosine vectors.
npx skillsauth add wenmin-wu/ds-skills cv-dicom-orientation-detectionInstall 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.
MRI studies contain multiple series acquired in different planes. The scan plane (axial, coronal, sagittal) determines what anatomical structures are visible and how they should be processed. DICOM stores this as ImageOrientationPatient — six direction cosines defining the row and column directions in patient coordinates. Rounding these cosines and pattern-matching identifies the plane, enabling automated routing of series to the correct preprocessing pipeline or model.
import pydicom
import numpy as np
def detect_orientation(dicom):
"""Detect scan plane from DICOM ImageOrientationPatient."""
iop = [round(float(v)) for v in dicom.ImageOrientationPatient]
x1, y1, z1, x2, y2, z2 = iop
# Row and column direction cosines determine the plane
row_dir = np.array([x1, y1, z1])
col_dir = np.array([x2, y2, z2])
normal = np.cross(row_dir, col_dir)
# The dominant axis of the normal vector indicates the plane
dominant = np.argmax(np.abs(normal))
planes = {0: 'sagittal', 1: 'coronal', 2: 'axial'}
return planes[dominant]
# Usage
dcm = pydicom.dcmread('path/to/slice.dcm')
plane = detect_orientation(dcm)
print(f"Scan plane: {plane}")
# Route series to correct model/preprocessing
series_planes = {}
for path in series_paths:
dcm = pydicom.dcmread(path, stop_before_pixels=True)
series_planes[dcm.SeriesInstanceUID] = detect_orientation(dcm)
ImageOrientationPatient from any DICOM slice in the seriesdata-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