sdcflows.utils.tools module¶
Image processing tools.
- sdcflows.utils.tools.brain_masker(in_file, out_file=None, padding=5)[source]¶
Use grayscale morphological operations to obtain a quick mask of EPI data.
- sdcflows.utils.tools.deoblique_and_zooms(in_reference: SpatialImage, oblique: SpatialImage, factor: int = 4, padding: int = 1, factor_tol: float = 0.0001)[source]¶
Generate a sampling reference aligned with in_reference fully covering oblique.
- Parameters:
in_reference (
SpatialImage
) – The sampling reference.oblique (
SpatialImage
) – The rotated coordinate system whose extent should be fully covered by the generated reference.factor (
int
) – A factor to increase the resolution of the generated reference.padding (
int
) – Number of additional voxels around the most extreme positions of the projection of oblique on to the reference.factor_tol (
float
) – Absolute tolerance to determine whether factor is one.
- sdcflows.utils.tools.ensure_positive_cosines(img)[source]¶
Reorient axes polarity to have all positive direction cosines.
In other words, this interface will reorient the image polarities to be all positive, respecting the axes ordering. For instance, LAS -> RAS or ALS -> ARS.
- sdcflows.utils.tools.reorient_pedir(pe_dir, source_ornt, target_ornt=None)[source]¶
Return updated PhaseEncodingDirection to account for an image data array rotation
Orientations form a natural group with identity, product and inverse. This function thus has the following properties (here
e
is the identity,*
the product and-
the inverse;a
andb
are arbitrary orientations):reorient(pe_dir, e, e) == pe_dir reorient(pe_dir, a, e) == reorient(pe_dir, a) reorient(pe_dir, e, b) == reorient(pe_dir, -b) reorient(pe_dir, a, b) == reorient(pe_dir, a * -b, e)
Therefore, this function accepts one or two orientations, and precomputed transforms from a to b can be passed as the “source” orientation.
Passing only a source orientation will rotate into RAS:
>>> from nibabel.orientations import axcodes2ornt >>> reorient_pedir("j", axcodes2ornt("RAS")) 'j' >>> reorient_pedir("i", axcodes2ornt("PSL")) 'j-'
Passing only a target_ornt will rotate from RAS:
>>> reorient_pedir("j", source_ornt=None, target_ornt=axcodes2ornt("RAS")) 'j' >>> reorient_pedir("i", source_ornt=None, target_ornt=axcodes2ornt("PSL")) 'k-'
Passing both will rotate from source to target.
>>> reorient_pedir("j", axcodes2ornt("LPS"), axcodes2ornt("AIR")) 'i-'
Passing a transform orientation as source_ornt will perform the transform, and passing it as
target_ornt
will invert the transform:>>> from nibabel.orientations import ornt_transform >>> xfm = ornt_transform(axcodes2ornt("LPS"), axcodes2ornt("AIR")) >>> reorient_pedir("j", xfm) 'i-' >>> reorient_pedir("j", source_ornt=None, target_ornt=xfm) 'k-'