DICOM Handling for Medical Images
DICOM files carry pixels plus patient geometry and dose tags, so handling means parsing orientation before any model runs.
Why Does This Exist?
PNGs hold pixels; scanners hold patients. DICOM wraps pixels with Study, Series, and Instance UIDs plus Image Position, Orientation, Rescale Slope and Intercept, and dose tags. Ignoring them flips left-right or shifts Hounsfield by hundreds. Input is a directory of .dcm slices; output is an oriented volume in patient coordinates ready for 3D medical segmentation.
Think of It Like This
Film canisters with lab notes taped on
Photo canisters hold film plus notes on camera angle, exposure, and order. Developing film without notes mixes rolls and mirrors shots. Reading notes first stacks frames correctly.
Tags are notes and pixels are film. The analogy stops at privacy: notes include names that must be scrubbed.
How It Actually Works
Group by Series UID into volumes; sort by Image Position along the normal. Apply with slope often and intercept . Orientation cosines map array axes to LPS patient axes. Anonymize by dropping names, dates, and UIDs while keeping geometry for organ segmentation.
Worked example
A CT slice stores pixel with slope and intercept , giving HU liver. Orientation keeps rows left-right. Sorting slices by position from to mm rebuilds mm spacing. Dropping PatientName plus shifting dates keeps geometry while passing privacy review.
Watch Out For
Left-right flips from ignored orientation
Assuming axial rows always run left to right mirrors situs cases and mislabels liver side. The symptom is perfect Dice on flipped anatomy. Apply orientation cosines explicitly and verify liver right on overviews.
The Quick Version
- DICOM pairs pixels with geometry, dose, and identity tags.
- Rescale tags make Hounsfield numbers; orientation makes left-right.
- Group by Series UID and sort by position before modeling.
- Do not feed raw pixels without rescale; numbers shift by hundreds.
- Anonymize names and dates but keep spacing for volumes.