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) –
SeriesNumberorSeriesInstanceUIDof 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.Nonereads the only series the files hold.
- Returns:
A named tuple of
imagefloat32,(contrasts, slices, rows, columns), with the rescale slope and intercept applied.affinefloat64(4, 4), from voxel indices(column, row, slice)to RAS coordinates in millimetres.timingsinversion_time,echo_timeandrepetition_timein milliseconds andflip_anglein degrees, one per contrast; NaN where the files do not state one.headerThe first dataset read, a template for
write_dicom().
- Return type:
Images
- Raises:
ValueError – If no series matches, several do and
seriesis not given, the files are multi-frame, two images share a contrast and a slice, or the contrasts cover different slices.