Skip to content

Commit 1b7820a

Browse files
dPysarokem
authored andcommitted
[ENH] Add API to vectors for reorienting bvecs from rasb .tsv and affine list
1 parent 199a496 commit 1b7820a

File tree

7 files changed

+229
-0
lines changed

7 files changed

+229
-0
lines changed

.idea/dmriprep-1.iml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/R_User_Library.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 160 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dmriprep/utils/vectors.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,32 @@ def bvecs2ras(affine, bvecs, norm=True, bvec_norm_epsilon=0.2):
375375
rotated_bvecs[~b0s] /= norms_bvecs[~b0s, np.newaxis]
376376
rotated_bvecs[b0s] = np.zeros(3)
377377
return rotated_bvecs
378+
379+
380+
def reorient_bvecs_from_ras_b(ras_b, affines):
381+
"""
382+
Reorient the vectors from a rasb .tsv file.
383+
When correcting for motion, rotation of the diffusion-weighted volumes
384+
might cause systematic bias in rotationally invariant measures, such as FA
385+
and MD, and also cause characteristic biases in tractography, unless the
386+
gradient directions are appropriately reoriented to compensate for this
387+
effect [Leemans2009]_.
388+
389+
Parameters
390+
----------
391+
rasb_file : str or os.pathlike
392+
File path to a RAS-B gradient table. If rasb_file is provided,
393+
then bvecs and bvals will be dismissed.
394+
395+
affines : list or ndarray of shape (n, 4, 4) or (n, 3, 3)
396+
Each entry in this list or array contain either an affine
397+
transformation (4,4) or a rotation matrix (3, 3).
398+
In both cases, the transformations encode the rotation that was applied
399+
to the image corresponding to one of the non-zero gradient directions.
400+
"""
401+
from dipy.core.gradients import gradient_table_from_bvals_bvecs, reorient_bvecs
402+
403+
ras_b_mat = np.genfromtxt(ras_b, delimiter='\t')
404+
gt = gradient_table_from_bvals_bvecs(ras_b_mat[:,3], ras_b_mat[:,0:3], b0_threshold=50)
405+
406+
return reorient_bvecs(gt, affines)

0 commit comments

Comments
 (0)