Package for stacking DICOM images into multi dimensional volumes, extracting the DICOM meta data, converting the result to Nifti files with the meta data stored in a header extension, and work with these extended Nifti files.
Stack DICOM datasets into volumes. The contents of this module are imported into the package namespace.
Bases: object
Object defining an ordering for a set of dicom datasets. Create a DicomOrdering with the given DICOM element keyword.
Parameters : | key : str
abs_ordering : sequence
abs_as_str : bool
|
---|
Methods
get_ordinate(ds) | Get the ordinate for the given DICOM data set. |
Get the ordinate for the given DICOM data set.
Parameters : | ds : dict like
|
---|---|
Returns : | An ordinate for the data set. If `abs_ordering` is None then this will : just be the value for the keyword `key`. Otherwise it will be an : integer. : |
Bases: object
Defines a method for stacking together DICOM data sets into a multi dimensional volume.
Tailored towards creating NiftiImage output, but can also just create numpy arrays. Can summarize all of the meta data from the input DICOM data sets into a Nifti header extension (see dcmmeta.DcmMetaExtension).
Parameters : | time_order : str or DicomOrdering
vector_order : str or DicomOrdering
allow_dummies : bool
meta_filter : callable
|
---|
Notes
If both time_order and vector_order are None, the time_order will be guessed based off the data sets.
Methods
add_dcm(dcm[, meta]) | Add a pydicom dataset to the stack. |
clear() | Remove any DICOM datasets from the stack. |
get_affine() | Get the affine transform for mapping row/column/slice indices |
get_data() | Get an array of the voxel values. |
get_shape() | Get the shape of the stack. |
to_nifti([voxel_order, embed_meta]) | Returns a NiftiImage with the data and affine from the stack. |
to_nifti_wrapper([voxel_order]) | Convienance method. |
Add a pydicom dataset to the stack.
Parameters : | dcm : dicom.dataset.Dataset
meta : dict
|
---|---|
Raises : | IncongruentImageError :
ImageCollisionError :
|
Remove any DICOM datasets from the stack.
Get the affine transform for mapping row/column/slice indices to Nifti (RAS) patient space.
Returns : | A 4x4 numpy array containing the affine transform. : |
---|---|
Raises : | InvalidStackError :
|
Get an array of the voxel values.
Returns : | A numpy array filled with values from the DICOM data sets’ pixels. : |
---|---|
Raises : | InvalidStackError :
|
Get the shape of the stack.
Returns : | A tuple of integers giving the size of the dimensions of the stack. : |
---|---|
Raises : | InvalidStackError :
|
The meta data keywords used when trying to guess the sorting order. Keys that come earlier in the list are given higher priority.
Returns a NiftiImage with the data and affine from the stack.
Parameters : | voxel_order : str
embed_meta : bool
|
---|---|
Returns : | A nibabel.nifti1.Nifti1Image created with the stack’s data and affine. : |
Convienance method. Calls to_nifti and returns a NiftiWrapper generated from the result.
Bases: exceptions.Exception
An exception denoting that a DICOM which collides with one already in the stack was passed to a DicomStack.add_dcm.
Convert axis codes axcodes to an orientation
Parameters : | axcodes : (N,) tuple
labels : optional, None or sequence of (2,) sequences
|
---|---|
Returns : | ornt : (N,2) array-like
|
Examples
>>> axcodes2ornt(('F', 'L', 'U'), (('L','R'),('B','F'),('D','U')))
[[1, 1],[0,-1],[2,1]]
Convert a DICOM time value (value representation of ‘TM’) to the number of seconds past midnight.
Parameters : | time_str : str
|
---|---|
Returns : | A floating point representing the number of seconds past midnight : |
Default keys for grouping DICOM files from the same acquisition together.
A list of regexes passed to make_key_regex_filter as exclude_res to create the default_meta_filter.
A list of regexes passed to make_key_regex_filter as force_include_res to create the default_meta_filter.
Default meta_filter for DicomStack.
Make a meta data filter using regular expressions.
Parameters : | exclude_res : sequence
force_include_res : sequence
|
---|---|
Returns : | A callable which can be passed to `DicomStack` as the `meta_filter`. : |
Return the orientation that transforms from start_ornt to end_ornt.
Parameters : | start_ornt : (n,2) orientation array
end_ornt : (n,2) orientation array
|
---|---|
Returns : | orientations : (p, 2) ndarray
|
Parse the given dicom files and group them together. Each group is stored as a (list) value in a dict where the key is a tuple of values corresponding to the keys in ‘group_by’
Parameters : | src_paths : sequence
group_by : tuple
extractor : callable
force : bool
warn_on_except : bool
|
---|---|
Returns : | groups : dict
|
Parse the given dicom files into a dictionary containing one or more DicomStack objects.
Parameters : | src_paths : sequence
group_by : tuple
extractor : callable
force : bool
warn_on_except : bool
stack_args : kwargs
|
---|
Reorder the given voxel array and corresponding affine.
Parameters : | vox_array : array
affine : array
voxel_order : str
|
---|---|
Returns : | out_vox : array
out_aff : array
reorient_transform : array
ornt_trans : tuple
|
DcmMeta header extension and NiftiWrapper for working with extended Niftis.
Bases: exceptions.Exception
Exception denoting that there is no DcmMetaExtension in the Nifti header.
Bases: object
Wraps a Nifti1Image object containing a DcmMeta header extension. Provides access to the meta data and the ability to split or merge the data array while updating the meta data.
Parameters : | nii_img : nibabel.nifti1.Nifti1Image
make_empty : bool
|
---|---|
Raises : | MissingExtensionError :
ValueError :
|
Methods
from_dicom(klass, dcm_data[, meta_dict]) | Create a NiftiWrapper from a single DICOM dataset. |
from_dicom_wrapper(klass, dcm_wrp[, meta_dict]) | Create a NiftiWrapper from a nibabel DicomWrapper. |
from_filename(klass, path) | Create a NiftiWrapper from a file. |
from_sequence(klass, seq[, dim]) | Create a NiftiWrapper by joining a sequence of NiftiWrapper objects |
get_meta(key[, index, default]) | Return the meta data value for the provided key. |
meta_valid(classification) | Return true if the meta data with the given classification appears |
remove_extension() | Remove the DcmMetaExtension from the header of nii_img. The |
replace_extension(dcmmeta_ext) | Replace the DcmMetaExtension. |
split([dim]) | Generate splits of the array and meta data along the specified dimension. |
to_filename(out_path) | Write out the wrapped Nifti to a file |
Create a NiftiWrapper from a single DICOM dataset.
Parameters : | dcm_data : dicom.dataset.Dataset
meta_dict : dict
|
---|
Create a NiftiWrapper from a nibabel DicomWrapper.
Parameters : | dcm_wrap : nicom.dicomwrappers.DicomWrapper
meta_dict : dict
|
---|
Create a NiftiWrapper from a file.
Parameters : | path : str
|
---|
Create a NiftiWrapper by joining a sequence of NiftiWrapper objects along the given dimension.
Parameters : | seq : sequence
dim : int
|
---|---|
Returns : | result : NiftiWrapper
|
Return the meta data value for the provided key.
Parameters : | key : str
index : tuple
default :
|
---|---|
Returns : | value :
|
Notes
The per-sample and per-slice meta data will only be considered if the samples_valid and slices_valid methods return True (respectively), and an index is specified.
Return true if the meta data with the given classification appears to be valid for the wrapped Nifti image. Considers the shape and orientation of the image and the meta data extension.
Remove the DcmMetaExtension from the header of nii_img. The attribute meta_ext will still point to the extension.
Replace the DcmMetaExtension.
Parameters : | dcmmeta_ext : DcmMetaExtension
|
---|
Generate splits of the array and meta data along the specified dimension.
Parameters : | dim : int
|
---|---|
Returns : | result :
|
Write out the wrapped Nifti to a file
Parameters : | out_path : str
|
---|
Notes
Will check that the DcmMetaExtension is valid before writing the file.
Returns true if all elements in (each period of) the sequence are equal.
Parameters : | sequence : sequence
period : int
|
---|
Returns true if the elements in the sequence repeat with the given period.
Parameters : | sequence : sequence
period : int
|
---|
Convert all elements in dcm with VR of ‘DS’ or ‘IS’ to floats and ints. This is a hackish work around for the backwards incompatability of pydicom 0.9.7 and should not be needed once nibabel is updated.
Extract meta data from a DICOM data set.
Bases: object
Callable object for extracting meta data from a dicom dataset. Initialize with a set of ignore rules, translators, and type conversions.
Parameters : | ignore_rules : sequence
translators : sequence
conversions : dict
warn_on_trans_except : bool
|
---|
Bases: tuple
A namedtuple for storing the four elements of a translator: a name, the dicom.tag.Tag that can be translated, the private creator string (optional), and the function which takes the DICOM element and returns a dictionary.
Methods
count(...) | |
index((value, [start, ...) | Raises ValueError if the value is not present. |
Alias for field number 0
Alias for field number 2
Alias for field number 1
Alias for field number 3
Translator for the CSA image sub header.
Function for translating the CSA image sub header.
Translator for parsing the CSA series sub header.
Function for parsing the CSA series sub header.
The default MetaExtractor.
The default tuple of ignore rules for MetaExtractor.
Default translators for MetaExtractor.
Ignore rule for MetaExtractor to skip elements with VR of ‘OW’, ‘OB’, or ‘UN’ if the byte string contains non ASCII characters.
Ignore rule for MetaExtractor to skip private DICOM elements (odd group number).
Parse the MrPheonixProtocol string.
Parameters : | prot_str : str
|
---|---|
Returns : | prot_dict : OrderedDict
|
Raises : | PhoenixParseError : A line of the ASCCONV section could not be parsed. |
Simplify the result of nibabel.nicom.csareader.
Parameters : | csa_dict : dict
|
---|---|
Returns : | result : OrderedDict
|
Convert a DICOM tag to a string representation using the group and element hex values seprated by an underscore.
Convert a DICOM time value (value representation of ‘TM’) to the number of seconds past midnight.
Parameters : | time_str : str
|
---|---|
Returns : | A floating point representing the number of seconds past midnight : |
Dictionary mapping value representations to corresponding format strings for the struct.unpack function.