io.read_series#
- bartorch.io.read_series()#
Read a DICOM or NIfTI image series, pairing magnitude with phase or real with imaginary.
Each image is assigned to a part – magnitude, phase, real or imaginary – by, in order, DICOM’s
ComplexImageComponent, GE’s private image-type tag, Philips’s private one, and the values ofImageType; a NIfTI file by its sidecar’sImageType, then a BIDSpart-entity, thenphase,realorimagin its name. An image none of these place is magnitude. The parts have to cover the same contrasts and slices, and agree on every timing both state; a timing one part does not state is taken from another.Phase is scaled to radians from the span of stored values that stands for one turn. Given
phase_range, that span is used. Otherwise it is the narrowest of radians, degrees, milliradians,[0, 4096)and[-4096, 4096)that holds every value, else the span of the stored integer type after its rescale, else the values’ own span. Wrapped phase fills its span, so a warning is issued when the values fill less than 80% of the span used, or fall outside a given one: a reconstruction of one’s own may scale phase in a way no rule can guess. A warning is also issued when the phase takes fewer than 256 distinct values: phase rounded on export (to whole radians, say) carries no field.- Parameters:
path (str or sequence of str) – A DICOM directory, searched recursively, or DICOM files; or
.niiand.nii.gzfiles, one per part and contrast or with contrasts along the fourth axis, each with an optional JSON sidecar of the same name.series (int, str or sequence, default=None) – DICOM only:
SeriesNumberorSeriesInstanceUIDof the series to read, or several, read as one.Nonereads every series the files hold, provided no two hold the same part, as a scanner that stores magnitude and phase as series of their own does.phase_range (tuple of float, default=None) – Stored phase values
(low, high)that stand for-piandpi.
- Returns:
A named tuple of
imagecomplex64when the series holds phase or real and imaginary parts,float32when it holds magnitude only;(contrasts, z, y, x). Phase without magnitude reads as unit magnitude.affinefloat64(4, 4), from voxel indices(x, y, z)to RAS millimetres.acquisitionThe
Acquisitionthe files describe.headerThe first DICOM dataset or NIfTI header read, a template for the writers.
- Return type:
- Raises:
ValueError – If two series hold the same part and
seriesis not given, the parts cover different contrasts, slices or geometry, a part is missing its counterpart (real without imaginary), orphase_rangeis empty.ImportError – If
pydicomornibabelis not installed.