dbdicom.Series.extract#
- Series.extract(slice={}, coords={}, **filters) Series [source]#
Get a slice of the series by dimension values
- Parameters:
coordinates (dict, optional) – dictionary of tag:value pairs where the value is either a single value or an array of values.
coords (dict) – Provide coordinates for the slice, either as dimension=value pairs, or as a dictionary where the keys list the dimensions, and the values are provided as scalars, 1D or meshgrid arrays of coordinates.
See also
islice
split_by
Example
Create a zero-filled array, describing 8 MRI images each measured at 3 flip angles and 2 repetition times:
>>> coords = { ... 'SliceLocation': np.arange(8), ... 'FlipAngle': [2, 15, 30], ... 'RepetitionTime': [2.5, 5.0], ... } >>> series = db.zeros((128,128,8,3,2), coords)
Slice the series at flip angle 15:
>>> fa15 = series.slice(FlipAngle=15)
Retrieve the array and check the dimensions:
>>> array = fa15.pixel_values(dims=tuple(coords)) >>> print(array.shape) (128, 128, 8, 1, 2)
Multiple possible values can be specified as a list or np.ndarray:
>>> fa15 = series.slice(SliceLocation=[0,5], FlipAngle=15) >>> array = fa15.pixel_values(dims=tuple(coords)) >>> print(array.shape) (128, 128, 2, 1, 2)
Values can also be provided as a dictionary, which is useful for instance for private tags that do not have a keyword string. So the following are equivalent:
>>> fa15 = series.slice(SliceLocation=[0,5], FlipAngle=15) >>> fa15 = series.slice({SliceLocation:[0,5], FlipAngle:15}) >>> fa15 = series.slice({(0x0020, 0x1041):[0,5], (0x0018, 0x1314):15})