io.read_dicom

Contents

io.read_dicom#

bartorch.io.read_dicom()#

Read a DICOM MR image series into a tensor sorted by contrast and slice.

Images are grouped into contrasts by inversion time, echo time, repetition time and flip angle, then trigger time, temporal position and b-value, and contrasts are ordered by those fields in that order; within a contrast, slices are ordered along the slice normal. Every contrast has to cover the same slices.

Parameters:
  • path (str or sequence of str) – A directory, searched recursively, or the files themselves. Files that are not DICOM are skipped.

  • series (int, str or sequence, default=None) – SeriesNumber or SeriesInstanceUID of the series to read, or several of either, read as one: a protocol that stores each echo or inversion time as a series of its own. None reads the only series the files hold.

Returns:

A named tuple of

image

float32, (contrasts, slices, rows, columns), with the rescale slope and intercept applied.

affine

float64 (4, 4), from voxel indices (column, row, slice) to RAS coordinates in millimetres.

timings

inversion_time, echo_time and repetition_time in milliseconds and flip_angle in degrees, one per contrast; NaN where the files do not state one.

header

The first dataset read, a template for write_dicom().

Return type:

Images

Raises:

ValueError – If no series matches, several do and series is not given, the files are multi-frame, two images share a contrast and a slice, or the contrasts cover different slices.