Skip to content

dicom

dicom

DICOM geometry + pixel-scaling helpers for osipy.

All series discovery and PerfusionDataset assembly live in :mod:osipy.common.io.discovery. This module retains the stateless helpers that module relies on (affine construction, Philips pixel scaling, private-tag reads, SeriesDescription time extraction).

References

DICOM Standard: https://www.dicomstandard.org/

build_affine_from_dicom

build_affine_from_dicom(dcm, slice_thickness, transpose_slices=True)

Build NIfTI affine matrix from DICOM geometry tags.

This function builds an affine matrix that maps voxel indices (i, j, k) to patient coordinates (x, y, z) in millimeters.

PARAMETER DESCRIPTION
dcm

DICOM dataset with ImageOrientationPatient and ImagePositionPatient.

TYPE: Dataset

slice_thickness

Slice thickness in mm.

TYPE: float

transpose_slices

If True, assumes slices will be transposed when loading (col, row order). This matches standard NIfTI conventions used by tools like dcm2niix. If False, assumes slices stored in DICOM native (row, col) order.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
ndarray

4x4 affine matrix mapping voxel indices to patient coordinates.

Notes

DICOM geometry conventions: - ImageOrientationPatient[0:3]: row direction cosines (direction of increasing column) - ImageOrientationPatient[3:6]: column direction cosines (direction of increasing row) - PixelSpacing[0]: row spacing (distance between rows, in column direction) - PixelSpacing[1]: column spacing (distance between columns, in row direction)

When transpose_slices=True (default): - Data is stored as array[col, row, slice] after transposing each DICOM slice - This matches the convention used by most DICOM-to-NIfTI converters - Affine column 0 maps to row direction (along increasing column index) - Affine column 1 maps to column direction (along increasing row index)