Skip to content
Snippets Groups Projects
Commit 8f9bed31 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Using nibabel version of axcodes2ornt instead of dcmstack version, as the

latter is buggy. Didn't bother to figure out the bug.
parent d4ce30ae
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,7 @@ from nibabel.nifti1 import Nifti1Extensions ...@@ -12,6 +12,7 @@ from nibabel.nifti1 import Nifti1Extensions
from nibabel.spatialimages import HeaderDataError from nibabel.spatialimages import HeaderDataError
from nibabel.orientations import (io_orientation, from nibabel.orientations import (io_orientation,
apply_orientation, apply_orientation,
axcodes2ornt,
inv_ornt_aff) inv_ornt_aff)
import numpy as np import numpy as np
from .dcmmeta import DcmMetaExtension, NiftiWrapper from .dcmmeta import DcmMetaExtension, NiftiWrapper
...@@ -132,47 +133,6 @@ def ornt_transform(start_ornt, end_ornt): ...@@ -132,47 +133,6 @@ def ornt_transform(start_ornt, end_ornt):
end_out_idx) end_out_idx)
return result return result
def axcodes2ornt(axcodes, labels=None):
""" Convert axis codes `axcodes` to an orientation
Parameters
----------
axcodes : (N,) tuple
axis codes - see ornt2axcodes docstring
labels : optional, None or sequence of (2,) sequences
(2,) sequences are labels for (beginning, end) of output axis. That
is, if the first element in `axcodes` is ``front``, and the second
(2,) sequence in `labels` is ('back', 'front') then the first
row of `ornt` will be ``[1, 1]``. If None, equivalent to
``(('L','R'),('P','A'),('I','S'))`` - that is - RAS axes.
Returns
-------
ornt : (N,2) array-like
oritation array - see io_orientation docstring
Examples
--------
>>> axcodes2ornt(('F', 'L', 'U'), (('L','R'),('B','F'),('D','U')))
[[1, 1],[0,-1],[2,1]]
"""
if labels is None:
labels = zip('LPI', 'RAS')
n_axes = len(axcodes)
ornt = np.ones((n_axes, 2), dtype=np.int8) * np.nan
for code_idx, code in enumerate(axcodes):
for label_idx, codes in enumerate(labels):
if code is None:
continue
if code in codes:
if code == codes[0]:
ornt[code_idx, :] = [label_idx, -1]
else:
ornt[code_idx, :] = [label_idx, 1]
break
return ornt
def reorder_voxels(vox_array, affine, voxel_order): def reorder_voxels(vox_array, affine, voxel_order):
'''Reorder the given voxel array and corresponding affine. '''Reorder the given voxel array and corresponding affine.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment